mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Custom variable: Initialize options from query if not present in persisted model (#76403)
* Custom variable: Initialize options from query if not oresent in persisted model * Test update
This commit is contained in:
parent
b6dff85127
commit
d00410560a
@ -12,6 +12,7 @@ import { variableAdapters } from '../adapters';
|
|||||||
import { createConstantVariableAdapter } from '../constant/adapter';
|
import { createConstantVariableAdapter } from '../constant/adapter';
|
||||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, NEW_VARIABLE_ID } from '../constants';
|
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, NEW_VARIABLE_ID } from '../constants';
|
||||||
import { createCustomVariableAdapter } from '../custom/adapter';
|
import { createCustomVariableAdapter } from '../custom/adapter';
|
||||||
|
import { createCustomOptionsFromQuery } from '../custom/reducer';
|
||||||
import { changeVariableName } from '../editor/actions';
|
import { changeVariableName } from '../editor/actions';
|
||||||
import { changeVariableNameFailed, changeVariableNameSucceeded, cleanEditorState } from '../editor/reducer';
|
import { changeVariableNameFailed, changeVariableNameSucceeded, cleanEditorState } from '../editor/reducer';
|
||||||
import { cleanPickerState } from '../pickers/OptionsPicker/reducer';
|
import { cleanPickerState } from '../pickers/OptionsPicker/reducer';
|
||||||
@ -192,7 +193,7 @@ describe('shared actions', () => {
|
|||||||
.whenAsyncActionIsDispatched(processVariables(key), true);
|
.whenAsyncActionIsDispatched(processVariables(key), true);
|
||||||
|
|
||||||
await tester.thenDispatchedActionsPredicateShouldEqual((dispatchedActions) => {
|
await tester.thenDispatchedActionsPredicateShouldEqual((dispatchedActions) => {
|
||||||
expect(dispatchedActions.length).toEqual(5);
|
expect(dispatchedActions.length).toEqual(7);
|
||||||
|
|
||||||
expect(dispatchedActions[0]).toEqual(
|
expect(dispatchedActions[0]).toEqual(
|
||||||
toKeyedAction(
|
toKeyedAction(
|
||||||
@ -213,7 +214,7 @@ describe('shared actions', () => {
|
|||||||
expect(dispatchedActions[2]).toEqual(
|
expect(dispatchedActions[2]).toEqual(
|
||||||
toKeyedAction(
|
toKeyedAction(
|
||||||
key,
|
key,
|
||||||
variableStateCompleted(toVariablePayload({ ...custom, id: dispatchedActions[2].payload.action.payload.id }))
|
variableStateFetching(toVariablePayload({ ...custom, id: dispatchedActions[2].payload.action.payload.id }))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -229,7 +230,23 @@ describe('shared actions', () => {
|
|||||||
expect(dispatchedActions[4]).toEqual(
|
expect(dispatchedActions[4]).toEqual(
|
||||||
toKeyedAction(
|
toKeyedAction(
|
||||||
key,
|
key,
|
||||||
variableStateCompleted(toVariablePayload({ ...query, id: dispatchedActions[4].payload.action.payload.id }))
|
createCustomOptionsFromQuery(
|
||||||
|
toVariablePayload({ ...custom, id: dispatchedActions[4].payload.action.payload.id })
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(dispatchedActions[5]).toEqual(
|
||||||
|
toKeyedAction(
|
||||||
|
key,
|
||||||
|
variableStateCompleted(toVariablePayload({ ...custom, id: dispatchedActions[5].payload.action.payload.id }))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(dispatchedActions[6]).toEqual(
|
||||||
|
toKeyedAction(
|
||||||
|
key,
|
||||||
|
variableStateCompleted(toVariablePayload({ ...query, id: dispatchedActions[6].payload.action.payload.id }))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -381,6 +381,11 @@ export const processVariable = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (variable.type === 'custom') {
|
||||||
|
await dispatch(updateOptions(toKeyedVariableIdentifier(variable)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// for variables that aren't updated via URL or refresh, let's simulate the same state changes
|
// for variables that aren't updated via URL or refresh, let's simulate the same state changes
|
||||||
dispatch(completeVariableLoading(identifier));
|
dispatch(completeVariableLoading(identifier));
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,7 @@ import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|||||||
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
||||||
import { variableAdapters } from '../adapters';
|
import { variableAdapters } from '../adapters';
|
||||||
import { createCustomVariableAdapter } from '../custom/adapter';
|
import { createCustomVariableAdapter } from '../custom/adapter';
|
||||||
|
import { createCustomOptionsFromQuery } from '../custom/reducer';
|
||||||
import { setVariableQueryRunner, VariableQueryRunner } from '../query/VariableQueryRunner';
|
import { setVariableQueryRunner, VariableQueryRunner } from '../query/VariableQueryRunner';
|
||||||
import { createQueryVariableAdapter } from '../query/adapter';
|
import { createQueryVariableAdapter } from '../query/adapter';
|
||||||
import { updateVariableOptions } from '../query/reducer';
|
import { updateVariableOptions } from '../query/reducer';
|
||||||
@ -125,9 +126,18 @@ describe('processVariable', () => {
|
|||||||
.whenActionIsDispatched(initDashboardTemplating(key, dashboard))
|
.whenActionIsDispatched(initDashboardTemplating(key, dashboard))
|
||||||
.whenAsyncActionIsDispatched(processVariable(toKeyedVariableIdentifier(custom), queryParams), true);
|
.whenAsyncActionIsDispatched(processVariable(toKeyedVariableIdentifier(custom), queryParams), true);
|
||||||
|
|
||||||
await tester.thenDispatchedActionsShouldEqual(
|
await tester.thenDispatchedActionsPredicateShouldEqual((dispatchedActions) => {
|
||||||
toKeyedAction(key, variableStateCompleted(toVariablePayload(custom)))
|
expect(dispatchedActions.length).toEqual(4);
|
||||||
|
|
||||||
|
expect(dispatchedActions[0]).toEqual(toKeyedAction(key, variableStateFetching(toVariablePayload(custom))));
|
||||||
|
expect(dispatchedActions[1]).toEqual(
|
||||||
|
toKeyedAction(key, createCustomOptionsFromQuery(toVariablePayload(custom)))
|
||||||
);
|
);
|
||||||
|
expect(dispatchedActions[2].type).toEqual('templating/keyed/shared/setCurrentVariableValue');
|
||||||
|
expect(dispatchedActions[3]).toEqual(toKeyedAction(key, variableStateCompleted(toVariablePayload(custom))));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user