mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Refactor: renames uuid to id * Refactor: misc renames * Refactor: fixes renaming of variable * Refactor: changes method accessed by templateSrv * Refactor: fixes for NEW_VARIABLE_ID * Refactor: rename flow refactor * Tests: adds missing reducer and action tests * Refactor: keeping tests consitent * Chore: reorder imports * Chore: removes uuid package * Refactor: fixes imports
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import cloneDeep from 'lodash/cloneDeep';
|
|
|
|
import { TextBoxVariableModel } from '../../templating/variable';
|
|
import { initialTextBoxVariableModelState, textBoxVariableReducer } from './reducer';
|
|
import { dispatch } from '../../../store/store';
|
|
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
|
import { VariableAdapter } from '../adapters';
|
|
import { TextBoxVariablePicker } from './TextBoxVariablePicker';
|
|
import { TextBoxVariableEditor } from './TextBoxVariableEditor';
|
|
import { updateTextBoxVariableOptions } from './actions';
|
|
import { toVariableIdentifier } from '../state/types';
|
|
|
|
export const createTextBoxVariableAdapter = (): VariableAdapter<TextBoxVariableModel> => {
|
|
return {
|
|
description: 'Define a textbox variable, where users can enter any arbitrary string',
|
|
label: 'Text box',
|
|
initialState: initialTextBoxVariableModelState,
|
|
reducer: textBoxVariableReducer,
|
|
picker: TextBoxVariablePicker,
|
|
editor: TextBoxVariableEditor,
|
|
dependsOn: (variable, variableToTest) => {
|
|
return false;
|
|
},
|
|
setValue: async (variable, option, emitChanges = false) => {
|
|
await dispatch(setOptionAsCurrent(toVariableIdentifier(variable), option, emitChanges));
|
|
},
|
|
setValueFromUrl: async (variable, urlValue) => {
|
|
await dispatch(setOptionFromUrl(toVariableIdentifier(variable), urlValue));
|
|
},
|
|
updateOptions: async variable => {
|
|
await dispatch(updateTextBoxVariableOptions(toVariableIdentifier(variable)));
|
|
},
|
|
getSaveModel: variable => {
|
|
const { index, id, initLock, global, ...rest } = cloneDeep(variable);
|
|
return rest;
|
|
},
|
|
getValueForUrl: variable => {
|
|
return variable.current.value;
|
|
},
|
|
};
|
|
};
|