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,
|
error: null,
|
||||||
description: null,
|
description: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const migrated = createSceneVariableFromVariableModel(variable);
|
const migrated = createSceneVariableFromVariableModel(variable);
|
||||||
const { key, ...rest } = migrated.state;
|
const { key, ...rest } = migrated.state;
|
||||||
expect(rest).toEqual({
|
expect(rest).toEqual({
|
||||||
@ -696,6 +697,7 @@ describe('transformSaveModelToScene', () => {
|
|||||||
value: '1m',
|
value: '1m',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['textbox', 'system'])('should throw for unsupported (yet) variables', (type) => {
|
it.each(['textbox', 'system'])('should throw for unsupported (yet) variables', (type) => {
|
||||||
const variable = {
|
const variable = {
|
||||||
name: 'query0',
|
name: 'query0',
|
||||||
@ -704,6 +706,42 @@ describe('transformSaveModelToScene', () => {
|
|||||||
|
|
||||||
expect(() => createSceneVariableFromVariableModel(variable as TypedVariableModel)).toThrow();
|
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', () => {
|
describe('Repeating rows', () => {
|
||||||
|
@ -274,8 +274,8 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
|||||||
if (variable.type === 'custom') {
|
if (variable.type === 'custom') {
|
||||||
return new CustomVariable({
|
return new CustomVariable({
|
||||||
...commonProperties,
|
...commonProperties,
|
||||||
value: variable.current.value,
|
value: variable.current?.value ?? '',
|
||||||
text: variable.current.text,
|
text: variable.current?.text ?? '',
|
||||||
description: variable.description,
|
description: variable.description,
|
||||||
query: variable.query,
|
query: variable.query,
|
||||||
isMulti: variable.multi,
|
isMulti: variable.multi,
|
||||||
@ -288,8 +288,8 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
|||||||
} else if (variable.type === 'query') {
|
} else if (variable.type === 'query') {
|
||||||
return new QueryVariable({
|
return new QueryVariable({
|
||||||
...commonProperties,
|
...commonProperties,
|
||||||
value: variable.current.value,
|
value: variable.current?.value ?? '',
|
||||||
text: variable.current.text,
|
text: variable.current?.text ?? '',
|
||||||
description: variable.description,
|
description: variable.description,
|
||||||
query: variable.query,
|
query: variable.query,
|
||||||
datasource: variable.datasource,
|
datasource: variable.datasource,
|
||||||
@ -306,8 +306,8 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
|||||||
} else if (variable.type === 'datasource') {
|
} else if (variable.type === 'datasource') {
|
||||||
return new DataSourceVariable({
|
return new DataSourceVariable({
|
||||||
...commonProperties,
|
...commonProperties,
|
||||||
value: variable.current.value,
|
value: variable.current?.value ?? '',
|
||||||
text: variable.current.text,
|
text: variable.current?.text ?? '',
|
||||||
description: variable.description,
|
description: variable.description,
|
||||||
regex: variable.regex,
|
regex: variable.regex,
|
||||||
pluginId: variable.query,
|
pluginId: variable.query,
|
||||||
|
Loading…
Reference in New Issue
Block a user