Templating: Fix issue where updated custom var options weren't persisted (#86804)

* Templating: Fix issue where updated custom var options weren't persisted
This commit is contained in:
kay delaney
2024-05-09 14:11:03 +01:00
committed by GitHub
parent c1a2051c1e
commit d5c781b9c5
3 changed files with 24 additions and 13 deletions

View File

@@ -3559,11 +3559,10 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
[0, 0, 0, "Do not use any type assertions.", "7"]
[0, 0, 0, "Do not use any type assertions.", "6"]
],
"public/app/features/visualization/data-hover/DataHoverRows.tsx:5381": [
[0, 0, 0, "Styles should be written using objects.", "0"]

View File

@@ -152,6 +152,21 @@ describe('processVariable', () => {
.whenAsyncActionIsDispatched(processVariable(toKeyedVariableIdentifier(custom), queryParams), true);
await tester.thenDispatchedActionsShouldEqual(
toKeyedAction(key, variableStateFetching(toVariablePayload({ type: 'custom', id: 'custom' }))),
toKeyedAction(
key,
createCustomOptionsFromQuery(toVariablePayload({ type: 'custom', id: 'custom' }, 'A,B,C'))
),
toKeyedAction(
key,
setCurrentVariableValue(
toVariablePayload(
{ type: 'custom', id: 'custom' },
{ option: { text: 'A', value: 'A', selected: false } }
)
)
),
toKeyedAction(key, variableStateCompleted(toVariablePayload(custom))),
toKeyedAction(
key,
setCurrentVariableValue(
@@ -160,8 +175,7 @@ describe('processVariable', () => {
{ option: { text: 'B', value: 'B', selected: false } }
)
)
),
toKeyedAction(key, variableStateCompleted(toVariablePayload(custom)))
)
);
});
});

View File

@@ -156,21 +156,19 @@ export function getLegacyQueryOptions(
}
export function getVariableRefresh(variable: VariableModel): VariableRefresh {
if (!variable || !variable.hasOwnProperty('refresh')) {
return VariableRefresh.never;
if (variable?.type === 'custom') {
return VariableRefresh.onDashboardLoad;
}
const queryVariable = variable as QueryVariableModel;
if (
queryVariable.refresh !== VariableRefresh.onTimeRangeChanged &&
queryVariable.refresh !== VariableRefresh.onDashboardLoad &&
queryVariable.refresh !== VariableRefresh.never
!variable ||
!('refresh' in variable) ||
(variable.refresh !== VariableRefresh.onTimeRangeChanged && variable.refresh !== VariableRefresh.onDashboardLoad)
) {
return VariableRefresh.never;
}
return queryVariable.refresh;
return variable.refresh;
}
export function getVariableTypes(): Array<{ label: string; value: VariableType }> {