Dashboards: Fix custom variable legacy model to return options when flag is set (#115154)

* fix custom var legacy model options property

* add test
This commit is contained in:
Victor Marin
2025-12-12 12:12:46 +00:00
committed by GitHub
parent b863acab05
commit fa62113b41
2 changed files with 34 additions and 1 deletions
@@ -380,6 +380,35 @@ describe('sceneVariablesSetToVariables', () => {
`);
});
it('should handle Custom variable when sceneVariablesSetToVariables should keep options', () => {
const variable = new CustomVariable({
name: 'test',
label: 'test-label',
description: 'test-desc',
hide: VariableHide.inControlsMenu,
value: ['test'],
text: ['test'],
query: 'test,test1,test2',
options: [
{ label: 'test', value: 'test' },
{ label: 'test1', value: 'test1' },
{ label: 'test2', value: 'test2' },
],
includeAll: true,
allValue: 'test-all',
isMulti: true,
});
const set = new SceneVariableSet({
variables: [variable],
});
const keepQueryOptions = true;
const result = sceneVariablesSetToVariables(set, keepQueryOptions);
expect(result).toHaveLength(1);
expect(result[0].options).not.toEqual([]);
expect(result[0].options?.length).toEqual(3);
});
it('should handle ConstantVariable', () => {
const variable = new ConstantVariable({
name: 'test',
@@ -102,6 +102,10 @@ export function sceneVariablesSetToVariables(set: SceneVariables, keepQueryOptio
}
variables.push(variableObj);
} else if (sceneUtils.isCustomVariable(variable)) {
let options: VariableOption[] = [];
if (keepQueryOptions) {
options = variableValueOptionsToVariableOptions(variable.state);
}
const customVariable: VariableModel = {
...commonProperties,
current: {
@@ -110,7 +114,7 @@ export function sceneVariablesSetToVariables(set: SceneVariables, keepQueryOptio
// @ts-expect-error
value: variable.state.value,
},
options: [],
options,
query: variable.state.query,
multi: variable.state.isMulti,
allValue: variable.state.allValue,