mirror of
https://github.com/grafana/grafana.git
synced 2025-02-09 06:56:07 -06:00
* Chore: initial commit * Tests: fixes MetricsQueryEditor.test.tsx * Tests: fixes cloudwatch/specs/datasource.test.ts * Tests: fixes stackdriver/specs/datasource.test.ts * Tests: remove refrences to CustomVariable * Refactor: moves DefaultVariableQueryEditor * Refactor: moves utils * Refactor: moves types * Refactor: removes variableSrv * Refactor: removes feature toggle newVariables * Refactor: removes valueSelectDropDown * Chore: removes GeneralTabCtrl * Chore: migrates RowOptions * Refactor: adds RowOptionsButton * Refactor: makes the interface more explicit * Refactor: small changes * Refactor: changed type as it can be any variable type * Tests: fixes broken test * Refactor: changes after PR comments * Refactor: adds loading state and call to onChange in componentDidMount
30 lines
1.3 KiB
TypeScript
30 lines
1.3 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';
|
|
|
|
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());
|
|
|
|
dispatch(changeVariableProp(toVariablePayload(variableInState, { propName: 'query', propValue: urlValue })));
|
|
|
|
await dispatch(setOptionFromUrl(toVariableIdentifier(variableInState), urlValue));
|
|
};
|