[v10.4.x] Templating: Fix issue where updated custom var options weren't persisted (#87557)

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

* Templating: Fix issue where updated custom var options weren't persisted

(cherry picked from commit d5c781b9c5)

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
This commit is contained in:
grafana-delivery-bot[bot]
2024-05-09 16:28:34 +03:00
committed by GitHub
co-authored by kay delaney
parent 654db2500a
commit cbbd6b1f7f
3 changed files with 24 additions and 13 deletions
+2 -3
View File
@@ -4570,11 +4570,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"]
@@ -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)))
)
);
});
});
+6 -8
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 }> {