/usr/share/grafana/public/app/features/variables/state
import { createAction } from '@reduxjs/toolkit'; import { AnyAction } from 'redux'; import { variableAdapters } from '../adapters'; import { sharedReducer } from './sharedReducer'; import { initialVariablesState, VariablesState } from './types'; export const cleanVariables = createAction<undefined>('templating/cleanVariables'); export const variablesReducer = (state: VariablesState = initialVariablesState, action: AnyAction): VariablesState => { if (cleanVariables.match(action)) { const globalVariables = Object.values(state).filter((v) => v.global); if (!globalVariables) { return initialVariablesState; } const variables = globalVariables.reduce<typeof state>((allVariables, state) => { allVariables[state.id] = state; return allVariables; }, {}); return variables; } if (action?.payload?.type && variableAdapters.getIfExists(action?.payload?.type)) { // Now that we know we are dealing with a payload that is addressed for an adapted variable let's reduce state: // Firstly call the sharedTemplatingReducer that handles all shared actions between variable types // Secondly call the specific variable type's reducer return variableAdapters.get(action.payload.type).reducer(sharedReducer(state, action), action); } return state; };
.
Edit
..
Edit
__tests__
Edit
actions.test.ts
Edit
actions.ts
Edit
helpers.ts
Edit
initVariableTransaction.test.ts
Edit
keyedVariablesReducer.test.ts
Edit
keyedVariablesReducer.ts
Edit
migrateVariablesDatasourceNameToRef.test.ts
Edit
onTimeRangeUpdated.test.ts
Edit
processVariable.test.ts
Edit
reducers.test.ts
Edit
reducers.ts
Edit
selectors.ts
Edit
setOptionFromUrl.test.ts
Edit
sharedReducer.test.ts
Edit
sharedReducer.ts
Edit
templateVarsChangedInUrl.test.ts
Edit
transactionReducer.test.ts
Edit
transactionReducer.ts
Edit
types.ts
Edit
upgradeLegacyQueries.test.ts
Edit
variablesReducer.ts
Edit