mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 23:53:10 +08:00
![renovate[bot]](/assets/img/avatar_default.png)
* Update dependency prettier to v2.5.1 * prettier fixes * chore(toolkit): bump prettier to 2.5.1 * style(eslint): bump grafana config to 2.5.2 in core and toolkit * style(mssql-datasource): fix no-inferrable-types eslint errors Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
31 lines
1.5 KiB
TypeScript
31 lines
1.5 KiB
TypeScript
import { TextBoxVariableModel } from '../types';
|
|
import { ThunkResult } from '../../../types';
|
|
import { getVariable } from '../state/selectors';
|
|
import { variableAdapters } from '../adapters';
|
|
import { createTextBoxOptions } from './reducer';
|
|
import { toVariableIdentifier, toVariablePayload, VariableIdentifier } from '../state/types';
|
|
import { setOptionFromUrl } from '../state/actions';
|
|
import { UrlQueryValue } from '@grafana/data';
|
|
import { changeVariableProp } from '../state/sharedReducer';
|
|
import { ensureStringValues } from '../utils';
|
|
|
|
export const updateTextBoxVariableOptions = (identifier: VariableIdentifier): ThunkResult<void> => {
|
|
return async (dispatch, getState) => {
|
|
await dispatch(createTextBoxOptions(toVariablePayload(identifier)));
|
|
|
|
const variableInState = getVariable<TextBoxVariableModel>(identifier.id, getState());
|
|
await variableAdapters.get(identifier.type).setValue(variableInState, variableInState.options[0], true);
|
|
};
|
|
};
|
|
|
|
export const setTextBoxVariableOptionsFromUrl =
|
|
(identifier: VariableIdentifier, urlValue: UrlQueryValue): ThunkResult<void> =>
|
|
async (dispatch, getState) => {
|
|
const variableInState = getVariable<TextBoxVariableModel>(identifier.id, getState());
|
|
|
|
const stringUrlValue = ensureStringValues(urlValue);
|
|
dispatch(changeVariableProp(toVariablePayload(variableInState, { propName: 'query', propValue: stringUrlValue })));
|
|
|
|
await dispatch(setOptionFromUrl(toVariableIdentifier(variableInState), stringUrlValue));
|
|
};
|