mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 04:12:09 +08:00

* Refactor: moves all the newVariables part to features/variables directory * Feature: adds datasource type * Tests: adds reducer tests * Tests: covers data source actions with tests * Chore: reduces strict null errors
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
import { TextBoxVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
|
import { EMPTY_UUID, getInstanceState, VariablePayload } from '../state/types';
|
|
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
|
|
|
export const initialTextBoxVariableModelState: TextBoxVariableModel = {
|
|
uuid: EMPTY_UUID,
|
|
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.uuid!);
|
|
instanceState.options = [
|
|
{ text: instanceState.query.trim(), value: instanceState.query.trim(), selected: false },
|
|
];
|
|
instanceState.current = instanceState.options[0];
|
|
},
|
|
},
|
|
});
|
|
|
|
export const textBoxVariableReducer = textBoxVariableSlice.reducer;
|
|
|
|
export const { createTextBoxOptions } = textBoxVariableSlice.actions;
|