mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardScene: Re-add support for default datasource var (#94806)
re-add support for default datasource var
This commit is contained in:
parent
e462974359
commit
96893aef2a
@ -251,6 +251,7 @@ describe('when creating variables objects', () => {
|
||||
isMulti: true,
|
||||
description: null,
|
||||
hide: 0,
|
||||
defaultOptionEnabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
@ -673,6 +674,49 @@ describe('when creating variables objects', () => {
|
||||
type: 'datasource',
|
||||
value: '',
|
||||
isMulti: true,
|
||||
defaultOptionEnabled: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle datasource variable with default selected', () => {
|
||||
// @ts-expect-error
|
||||
const variable: TypedVariableModel = {
|
||||
id: 'query1',
|
||||
current: {
|
||||
text: 'default',
|
||||
value: 'default',
|
||||
selected: true,
|
||||
},
|
||||
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: 'default',
|
||||
type: 'datasource',
|
||||
value: 'default',
|
||||
isMulti: true,
|
||||
defaultOptionEnabled: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -18,6 +18,8 @@ import { SnapshotVariable } from '../serialization/custom-variables/SnapshotVari
|
||||
|
||||
import { getCurrentValueForOldIntervalModel, getIntervalsFromQueryString } from './utils';
|
||||
|
||||
const DEFAULT_DATASOURCE = 'default';
|
||||
|
||||
export function createVariablesForDashboard(oldModel: DashboardModel) {
|
||||
const variableObjects = oldModel.templating.list
|
||||
.map((v) => {
|
||||
@ -189,6 +191,7 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
||||
skipUrlSync: variable.skipUrlSync,
|
||||
isMulti: variable.multi,
|
||||
hide: variable.hide,
|
||||
defaultOptionEnabled: variable.current?.value === DEFAULT_DATASOURCE && variable.current?.text === 'default',
|
||||
});
|
||||
} else if (variable.type === 'interval') {
|
||||
const intervals = getIntervalsFromQueryString(variable.query);
|
||||
|
Loading…
Reference in New Issue
Block a user