mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Fixes issue with variables without current property (#78481)
This commit is contained in:
parent
5a19813771
commit
393d103782
@ -679,6 +679,7 @@ describe('transformSaveModelToScene', () => {
|
||||
error: null,
|
||||
description: null,
|
||||
};
|
||||
|
||||
const migrated = createSceneVariableFromVariableModel(variable);
|
||||
const { key, ...rest } = migrated.state;
|
||||
expect(rest).toEqual({
|
||||
@ -696,6 +697,7 @@ describe('transformSaveModelToScene', () => {
|
||||
value: '1m',
|
||||
});
|
||||
});
|
||||
|
||||
it.each(['textbox', 'system'])('should throw for unsupported (yet) variables', (type) => {
|
||||
const variable = {
|
||||
name: 'query0',
|
||||
@ -704,6 +706,42 @@ describe('transformSaveModelToScene', () => {
|
||||
|
||||
expect(() => createSceneVariableFromVariableModel(variable as TypedVariableModel)).toThrow();
|
||||
});
|
||||
|
||||
it('should handle variable without current', () => {
|
||||
// @ts-expect-error
|
||||
const variable: TypedVariableModel = {
|
||||
id: 'query1',
|
||||
name: 'query1',
|
||||
type: 'datasource',
|
||||
global: false,
|
||||
regex: '/^gdev/',
|
||||
options: [],
|
||||
query: 'prometheus',
|
||||
multi: true,
|
||||
includeAll: true,
|
||||
refresh: 1,
|
||||
allValue: 'Custom all',
|
||||
};
|
||||
|
||||
const migrated = createSceneVariableFromVariableModel(variable);
|
||||
const { key, ...rest } = migrated.state;
|
||||
|
||||
expect(migrated).toBeInstanceOf(DataSourceVariable);
|
||||
expect(rest).toEqual({
|
||||
allValue: 'Custom all',
|
||||
defaultToAll: true,
|
||||
includeAll: true,
|
||||
label: undefined,
|
||||
name: 'query1',
|
||||
options: [],
|
||||
pluginId: 'prometheus',
|
||||
regex: '/^gdev/',
|
||||
text: '',
|
||||
type: 'datasource',
|
||||
value: '',
|
||||
isMulti: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Repeating rows', () => {
|
||||
|
@ -274,8 +274,8 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
||||
if (variable.type === 'custom') {
|
||||
return new CustomVariable({
|
||||
...commonProperties,
|
||||
value: variable.current.value,
|
||||
text: variable.current.text,
|
||||
value: variable.current?.value ?? '',
|
||||
text: variable.current?.text ?? '',
|
||||
description: variable.description,
|
||||
query: variable.query,
|
||||
isMulti: variable.multi,
|
||||
@ -288,8 +288,8 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
||||
} else if (variable.type === 'query') {
|
||||
return new QueryVariable({
|
||||
...commonProperties,
|
||||
value: variable.current.value,
|
||||
text: variable.current.text,
|
||||
value: variable.current?.value ?? '',
|
||||
text: variable.current?.text ?? '',
|
||||
description: variable.description,
|
||||
query: variable.query,
|
||||
datasource: variable.datasource,
|
||||
@ -306,8 +306,8 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
||||
} else if (variable.type === 'datasource') {
|
||||
return new DataSourceVariable({
|
||||
...commonProperties,
|
||||
value: variable.current.value,
|
||||
text: variable.current.text,
|
||||
value: variable.current?.value ?? '',
|
||||
text: variable.current?.text ?? '',
|
||||
description: variable.description,
|
||||
regex: variable.regex,
|
||||
pluginId: variable.query,
|
||||
|
Loading…
Reference in New Issue
Block a user