mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
import { UrlQueryValue } from '@grafana/data';
|
|
|
|
import { ThunkResult } from '../../../types';
|
|
import { variableAdapters } from '../adapters';
|
|
import { setOptionFromUrl } from '../state/actions';
|
|
import { toKeyedAction } from '../state/keyedVariablesReducer';
|
|
import { getVariable } from '../state/selectors';
|
|
import { changeVariableProp } from '../state/sharedReducer';
|
|
import { KeyedVariableIdentifier } from '../state/types';
|
|
import { TextBoxVariableModel } from '../types';
|
|
import { ensureStringValues, toKeyedVariableIdentifier, toVariablePayload } from '../utils';
|
|
|
|
import { createTextBoxOptions } from './reducer';
|
|
|
|
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));
|
|
};
|