mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Variables: Do not reset description on variable type change (#31933)
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
addVariable,
|
||||
changeVariableOrder,
|
||||
changeVariableProp,
|
||||
changeVariableType,
|
||||
duplicateVariable,
|
||||
removeVariable,
|
||||
setCurrentVariableValue,
|
||||
@@ -16,7 +17,7 @@ import {
|
||||
variableStateNotStarted,
|
||||
} from './sharedReducer';
|
||||
import { ConstantVariableModel, QueryVariableModel, VariableHide, VariableOption } from '../types';
|
||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, toVariablePayload } from './types';
|
||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, toVariablePayload, VariableIdentifier } from './types';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { createQueryVariableAdapter } from '../query/adapter';
|
||||
import { initialQueryVariableModelState } from '../query/reducer';
|
||||
@@ -489,4 +490,36 @@ describe('sharedReducer', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changeVariableType is dispatched', () => {
|
||||
it('then state should be correct', () => {
|
||||
const queryAdapter = createQueryVariableAdapter();
|
||||
const { initialState: queryAdapterState } = getVariableTestContext(queryAdapter);
|
||||
const constantAdapter = createConstantVariableAdapter();
|
||||
const { initialState: constantAdapterState } = getVariableTestContext(constantAdapter);
|
||||
const newType = 'constant' as VariableType;
|
||||
const identifier: VariableIdentifier = { id: '0', type: 'query' };
|
||||
const payload = toVariablePayload(identifier, { newType });
|
||||
reducerTester<VariablesState>()
|
||||
.givenReducer(sharedReducer, cloneDeep(queryAdapterState))
|
||||
.whenActionIsDispatched(changeVariableNameSucceeded(toVariablePayload(identifier, { newName: 'test' })))
|
||||
.whenActionIsDispatched(
|
||||
changeVariableProp(toVariablePayload(identifier, { propName: 'description', propValue: 'new description' }))
|
||||
)
|
||||
.whenActionIsDispatched(
|
||||
changeVariableProp(toVariablePayload(identifier, { propName: 'label', propValue: 'new label' }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableType(payload))
|
||||
.thenStateShouldEqual({
|
||||
...constantAdapterState,
|
||||
'0': {
|
||||
...constantAdapterState[0],
|
||||
name: 'test',
|
||||
description: 'new description',
|
||||
label: 'new label',
|
||||
type: 'constant',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,7 +101,7 @@ const sharedReducerSlice = createSlice({
|
||||
},
|
||||
changeVariableType: (state: VariablesState, action: PayloadAction<VariablePayload<{ newType: VariableType }>>) => {
|
||||
const { id } = action.payload;
|
||||
const { label, name, index } = state[id];
|
||||
const { label, name, index, description } = state[id];
|
||||
|
||||
state[id] = {
|
||||
...cloneDeep(variableAdapters.get(action.payload.data.newType).initialState),
|
||||
@@ -109,6 +109,7 @@ const sharedReducerSlice = createSlice({
|
||||
label,
|
||||
name,
|
||||
index,
|
||||
description,
|
||||
};
|
||||
},
|
||||
setCurrentVariableValue: (
|
||||
|
||||
Reference in New Issue
Block a user