diff --git a/public/app/features/dashboard-scene/scene/export/exporters.test.ts b/public/app/features/dashboard-scene/scene/export/exporters.test.ts index 4f93d54cf39..9f9028e2c41 100644 --- a/public/app/features/dashboard-scene/scene/export/exporters.test.ts +++ b/public/app/features/dashboard-scene/scene/export/exporters.test.ts @@ -9,6 +9,7 @@ import { } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha1/types.spec.gen'; import config from 'app/core/config'; import { DashboardModel } from 'app/features/dashboard/state/DashboardModel'; +import { createAdHocVariableAdapter } from 'app/features/variables/adhoc/adapter'; import { LibraryElementKind } from '../../../library-panels/types'; import { DashboardJson } from '../../../manage-dashboards/types'; @@ -67,6 +68,7 @@ jest.mock('app/features/library-panels/state/api', () => ({ variableAdapters.register(createQueryVariableAdapter()); variableAdapters.register(createConstantVariableAdapter()); variableAdapters.register(createDataSourceVariableAdapter()); +variableAdapters.register(createAdHocVariableAdapter()); describe('dashboard exporter v1', () => { it('handles a default datasource in a template variable', async () => { @@ -272,6 +274,11 @@ describe('dashboard exporter v1', () => { current: { value: 'other2', text: 'other2' }, options: [], }, + { + name: 'adhoc', + type: 'adhoc', + datasource: { uid: 'gfdb', type: 'testdb' }, + }, ], }, annotations: { @@ -420,6 +427,10 @@ describe('dashboard exporter v1', () => { expect(exported.templating.list[0].current.text).toBe(undefined); }); + it('should replace datasource in adhoc query', () => { + expect(exported.templating.list[3].datasource.uid).toBe('${DS_GFDB}'); + }); + it('should replace datasource in annotation query', () => { expect(exported.annotations.list[1].datasource.uid).toBe('${DS_GFDB}'); }); diff --git a/public/app/features/dashboard-scene/scene/export/exporters.ts b/public/app/features/dashboard-scene/scene/export/exporters.ts index 5c69f8a2f3b..4ef9f5a4cbd 100644 --- a/public/app/features/dashboard-scene/scene/export/exporters.ts +++ b/public/app/features/dashboard-scene/scene/export/exporters.ts @@ -237,6 +237,8 @@ export async function makeExportableV1(dashboard: DashboardModel) { variable.refresh !== VariableRefresh.never ? variable.refresh : VariableRefresh.onDashboardLoad; } else if (variable.type === 'datasource') { variable.current = {}; + } else if (variable.type === 'adhoc') { + await templateizeDatasourceUsage(variable); } }