Dashboards: Query variable editor sets default ds on variable on init (#113843)
* Query variable editor sets default ds on var instead of undefined * fix old arch tests
This commit is contained in:
+8
@@ -89,6 +89,14 @@ export function QueryVariableEditorForm({
|
||||
onQueryChange(query);
|
||||
}
|
||||
|
||||
if (!datasourceRef) {
|
||||
const instanceSettings = getDataSourceSrv().getInstanceSettings({ type: datasource.type, uid: datasource.uid });
|
||||
|
||||
if (instanceSettings) {
|
||||
onDataSourceChange(instanceSettings);
|
||||
}
|
||||
}
|
||||
|
||||
return { datasource, VariableQueryEditor };
|
||||
}, [datasourceRef]);
|
||||
|
||||
|
||||
+14
@@ -148,6 +148,20 @@ describe('QueryVariableEditor', () => {
|
||||
expect(staticOptionsToggle).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should update the variable with default datasource when opening editor', async () => {
|
||||
const onRunQueryMock = jest.fn();
|
||||
const variable = new QueryVariable({ datasource: undefined, query: '' });
|
||||
|
||||
await setup({
|
||||
variable,
|
||||
onRunQuery: onRunQueryMock,
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(variable.state.datasource).not.toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
it('should update the variable with default query for the selected DS', async () => {
|
||||
const onRunQueryMock = jest.fn();
|
||||
const variable = new QueryVariable({ datasource: { uid: 'mock-ds-2', type: 'test' }, query: '' });
|
||||
|
||||
@@ -29,7 +29,12 @@ ds.variables = {
|
||||
};
|
||||
|
||||
const setupTestContext = async (options: Partial<Props>) => {
|
||||
const variableDefaults: Partial<QueryVariableModel> = { rootStateKey: 'key' };
|
||||
const variableDefaults: Partial<QueryVariableModel> = {
|
||||
rootStateKey: 'key',
|
||||
// adds a default datasource in old arch tests so they continue passing
|
||||
// in new scenes arch the datasource will be calculated if not provided
|
||||
datasource: { uid: 'uid', type: 'type' },
|
||||
};
|
||||
const extended = {
|
||||
VariableQueryEditor: LegacyVariableQueryEditor,
|
||||
dataSource: ds,
|
||||
|
||||
Reference in New Issue
Block a user