mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Export: Explicitly include default datasources in exported dashboard json (#47244)
* Export: Explicitly include default datasources in exported dashboard json
This commit is contained in:
parent
cbd2d09d70
commit
f9f4a4cbf6
@ -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<string, string>) => 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<string, string>) => 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',
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user