mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Refactor: Replaces initLock with state machine * Refactor: removes some states for now * Refactor: adds loading state in OptionsPicker * Refactor: major refactor of load state * Refactor: fixes updating graph in parallell * Refactor: moves error handling to updateOptions * Refactor: fixes the last cases * Tests: disables variable e2e again * Chore: removes nova config * Refactor: small changes when going through the code again * Refactor: fixes typings * Refactor: changes after PR comments * Refactor: split up onTimeRangeUpdated and fixed some error handling * Tests: removes unused func * Tests: fixes typing
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
import { ConstantVariableModel, initialVariableModelState, VariableHide, VariableOption } from '../types';
|
|
import { getInstanceState, VariablePayload } from '../state/types';
|
|
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
|
|
|
export const initialConstantVariableModelState: ConstantVariableModel = {
|
|
...initialVariableModelState,
|
|
type: 'constant',
|
|
hide: VariableHide.hideVariable,
|
|
query: '',
|
|
current: {} as VariableOption,
|
|
options: [],
|
|
};
|
|
|
|
export const constantVariableSlice = createSlice({
|
|
name: 'templating/constant',
|
|
initialState: initialVariablesState,
|
|
reducers: {
|
|
createConstantOptionsFromQuery: (state: VariablesState, action: PayloadAction<VariablePayload>) => {
|
|
const instanceState = getInstanceState<ConstantVariableModel>(state, action.payload.id);
|
|
instanceState.options = [
|
|
{ text: instanceState.query.trim(), value: instanceState.query.trim(), selected: false },
|
|
];
|
|
},
|
|
},
|
|
});
|
|
|
|
export const constantVariableReducer = constantVariableSlice.reducer;
|
|
|
|
export const { createConstantOptionsFromQuery } = constantVariableSlice.actions;
|