DashboardScene: Re-add support for default datasource var (#94806)
re-add support for default datasource var
This commit is contained in:
@@ -251,6 +251,7 @@ describe('when creating variables objects', () => {
|
|||||||
isMulti: true,
|
isMulti: true,
|
||||||
description: null,
|
description: null,
|
||||||
hide: 0,
|
hide: 0,
|
||||||
|
defaultOptionEnabled: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -673,6 +674,49 @@ describe('when creating variables objects', () => {
|
|||||||
type: 'datasource',
|
type: 'datasource',
|
||||||
value: '',
|
value: '',
|
||||||
isMulti: true,
|
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';
|
import { getCurrentValueForOldIntervalModel, getIntervalsFromQueryString } from './utils';
|
||||||
|
|
||||||
|
const DEFAULT_DATASOURCE = 'default';
|
||||||
|
|
||||||
export function createVariablesForDashboard(oldModel: DashboardModel) {
|
export function createVariablesForDashboard(oldModel: DashboardModel) {
|
||||||
const variableObjects = oldModel.templating.list
|
const variableObjects = oldModel.templating.list
|
||||||
.map((v) => {
|
.map((v) => {
|
||||||
@@ -189,6 +191,7 @@ export function createSceneVariableFromVariableModel(variable: TypedVariableMode
|
|||||||
skipUrlSync: variable.skipUrlSync,
|
skipUrlSync: variable.skipUrlSync,
|
||||||
isMulti: variable.multi,
|
isMulti: variable.multi,
|
||||||
hide: variable.hide,
|
hide: variable.hide,
|
||||||
|
defaultOptionEnabled: variable.current?.value === DEFAULT_DATASOURCE && variable.current?.text === 'default',
|
||||||
});
|
});
|
||||||
} else if (variable.type === 'interval') {
|
} else if (variable.type === 'interval') {
|
||||||
const intervals = getIntervalsFromQueryString(variable.query);
|
const intervals = getIntervalsFromQueryString(variable.query);
|
||||||
|
|||||||
Reference in New Issue
Block a user