diff --git a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts index 83482884b08..1b8d2eda579 100644 --- a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts +++ b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.test.ts @@ -276,6 +276,10 @@ describe('given dashboard with repeated panels', () => { }, ], }, + { + id: 5, + targets: [{ scenarioId: 'random_walk', refId: 'A' }], + }, ], }; @@ -312,6 +316,23 @@ describe('given dashboard with repeated panels', () => { expect(panel.datasource.uid).toBe('${DS_GFDB}'); }); + it('should explicitly specify default datasources', () => { + const panel = exported.panels[7]; + expect(exported.__inputs.some((ds: Record) => ds.name === 'DS_GFDB')).toBeTruthy(); + expect(panel.datasource.uid).toBe('${DS_GFDB}'); + expect(panel.targets[0].datasource).toBe('${DS_GFDB}'); + }); + + it('should not include default datasource in __inputs unnecessarily', async () => { + const testJson: any = { + panels: [{ id: 1, datasource: { uid: 'other', type: 'other' }, type: 'graph' }], + }; + const testDash = new DashboardModel(testJson); + const exporter = new DashboardExporter(); + const exportedJson: any = await exporter.makeExportable(testDash); + expect(exportedJson.__inputs.some((ds: Record) => ds.name === 'DS_GFDB')).toBeFalsy(); + }); + it('should replace datasource refs in collapsed row', () => { const panel = exported.panels[6].panels[0]; expect(panel.datasource.uid).toBe('${DS_GFDB}'); @@ -453,7 +474,7 @@ stubs['other2'] = { meta: { id: 'other2', info: { version: '1.2.1' }, name: 'OtherDB_2' }, }; -stubs['-- Mixed --'] = { +stubs['mixed'] = { name: 'mixed', meta: { id: 'mixed', @@ -463,7 +484,7 @@ stubs['-- Mixed --'] = { }, }; -stubs['-- Grafana --'] = { +stubs['grafana'] = { name: '-- Grafana --', meta: { id: 'grafana', diff --git a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts index 3e7886e4c1c..6cc3219be7b 100644 --- a/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts +++ b/public/app/features/dashboard/components/DashExportModal/DashboardExporter.ts @@ -126,15 +126,18 @@ export class DashboardExporter { }; const processPanel = (panel: PanelModel) => { - if (panel.datasource !== undefined && panel.datasource !== null) { + const isRegularPanel = + (panel.repeatPanelId === undefined || panel.repeatPanelId === null) && + !('collapsed' in panel) && + !('panels' in panel); + + if (isRegularPanel) { templateizeDatasourceUsage(panel); } if (panel.targets) { for (const target of panel.targets) { - if (target.datasource !== undefined) { - templateizeDatasourceUsage(target); - } + templateizeDatasourceUsage(target); } }