mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 07:32:13 +08:00

* Variables: move state tree into a keyed state * Update public/app/features/variables/state/transactionReducer.ts Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> * Chore: fix prettier error * Chore: renamed slices and lastUid * Chore: rename toUidAction * Chore: rename dashboardVariableReducer * Chore: rename state prop back to templating * Chore renames variable.dashboardUid * Chore: rename toDashboardVariableIdentifier * Chore: rename getDashboardVariable * Chore: rename getDashboardVariablesState * Chore: rename getDashboardVariables * Chore: some more renames * Chore: small clean up * Chore: small rename * Chore: removes unused function * Chore: rename VariableModel.stateKey * Chore: rename KeyedVariableIdentifier.stateKey * user essentials mob! 🔱 * user essentials mob! 🔱 * user essentials mob! 🔱 * user essentials mob! 🔱 Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> Co-authored-by: kay delaney <kay@grafana.com> Co-authored-by: Alexandra Vargas <alexa1866@gmail.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import { TextBoxVariableModel } from '../types';
|
|
import { ThunkResult } from '../../../types';
|
|
import { getVariable } from '../state/selectors';
|
|
import { variableAdapters } from '../adapters';
|
|
import { createTextBoxOptions } from './reducer';
|
|
import { KeyedVariableIdentifier } from '../state/types';
|
|
import { setOptionFromUrl } from '../state/actions';
|
|
import { UrlQueryValue } from '@grafana/data';
|
|
import { changeVariableProp } from '../state/sharedReducer';
|
|
import { ensureStringValues, toKeyedVariableIdentifier, toVariablePayload } from '../utils';
|
|
import { toKeyedAction } from '../state/keyedVariablesReducer';
|
|
|
|
export const updateTextBoxVariableOptions = (identifier: KeyedVariableIdentifier): ThunkResult<void> => {
|
|
return async (dispatch, getState) => {
|
|
const { rootStateKey, type } = identifier;
|
|
dispatch(toKeyedAction(rootStateKey, createTextBoxOptions(toVariablePayload(identifier))));
|
|
|
|
const variableInState = getVariable<TextBoxVariableModel>(identifier, getState());
|
|
await variableAdapters.get(type).setValue(variableInState, variableInState.options[0], true);
|
|
};
|
|
};
|
|
|
|
export const setTextBoxVariableOptionsFromUrl =
|
|
(identifier: KeyedVariableIdentifier, urlValue: UrlQueryValue): ThunkResult<void> =>
|
|
async (dispatch, getState) => {
|
|
const { rootStateKey } = identifier;
|
|
const variableInState = getVariable<TextBoxVariableModel>(identifier, getState());
|
|
|
|
const stringUrlValue = ensureStringValues(urlValue);
|
|
dispatch(
|
|
toKeyedAction(
|
|
rootStateKey,
|
|
changeVariableProp(toVariablePayload(variableInState, { propName: 'query', propValue: stringUrlValue }))
|
|
)
|
|
);
|
|
|
|
await dispatch(setOptionFromUrl(toKeyedVariableIdentifier(variableInState), stringUrlValue));
|
|
};
|