mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* wip * make diff easier to read * Update template_srv getVariables to return new TypedVariableModel * update VariableType to use the type from TypedVariableModel * tidy things up * Chore: Use type-accurate mock variables in tests * Chore: Type VariableState to use TypedVariableModel * fix typo * remove type assertion from template_srv.getVariables * use typescript/no-redeclare for compatibility with ts overloads * remove generics from getVariable() and overload it to only return undefined based on arguments * update usages of getVariable() * Remove generic from getInstanceState * update usages of getInstanceState * fix lint
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
import { getInstanceState } from '../state/selectors';
|
|
import { initialVariablesState, VariablePayload, VariablesState } from '../state/types';
|
|
import { initialVariableModelState, TextBoxVariableModel, VariableOption } from '../types';
|
|
|
|
export const initialTextBoxVariableModelState: TextBoxVariableModel = {
|
|
...initialVariableModelState,
|
|
type: 'textbox',
|
|
query: '',
|
|
current: {} as VariableOption,
|
|
options: [],
|
|
originalQuery: null,
|
|
};
|
|
|
|
export const textBoxVariableSlice = createSlice({
|
|
name: 'templating/textbox',
|
|
initialState: initialVariablesState,
|
|
reducers: {
|
|
createTextBoxOptions: (state: VariablesState, action: PayloadAction<VariablePayload>) => {
|
|
const instanceState = getInstanceState(state, action.payload.id);
|
|
if (instanceState.type !== 'textbox') {
|
|
return;
|
|
}
|
|
|
|
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;
|