mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -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
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
import { TextBoxVariableModel, VariableHide, VariableOption } from '../types';
|
|
import { getInstanceState, NEW_VARIABLE_ID, VariablePayload } from '../state/types';
|
|
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
|
|
|
export const initialTextBoxVariableModelState: TextBoxVariableModel = {
|
|
id: NEW_VARIABLE_ID,
|
|
global: false,
|
|
index: -1,
|
|
type: 'textbox',
|
|
name: '',
|
|
label: '',
|
|
hide: VariableHide.dontHide,
|
|
query: '',
|
|
current: {} as VariableOption,
|
|
options: [],
|
|
skipUrlSync: false,
|
|
initLock: null,
|
|
};
|
|
|
|
export const textBoxVariableSlice = createSlice({
|
|
name: 'templating/textbox',
|
|
initialState: initialVariablesState,
|
|
reducers: {
|
|
createTextBoxOptions: (state: VariablesState, action: PayloadAction<VariablePayload>) => {
|
|
const instanceState = getInstanceState<TextBoxVariableModel>(state, action.payload.id);
|
|
const option = { text: instanceState.query.trim(), value: instanceState.query.trim(), selected: false };
|
|
instanceState.options = [option];
|
|
instanceState.current = option;
|
|
},
|
|
},
|
|
});
|
|
|
|
export const textBoxVariableReducer = textBoxVariableSlice.reducer;
|
|
|
|
export const { createTextBoxOptions } = textBoxVariableSlice.actions;
|