DashboardExport: Correctly templetatize datasource prop now that is's a ref obj (#42305) (#42345)

(cherry picked from commit 1e1403fad1)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
Grot (@grafanabot)
2021-11-26 10:29:16 +01:00
committed by GitHub
co-authored by Torkel Ödegaard
parent 2504f5f719
commit 934c446bf4
2 changed files with 13 additions and 6 deletions
@@ -75,7 +75,7 @@ describe('given dashboard with repeated panels', () => {
list: [
{
name: 'logs',
datasource: { uid: 'gfdb', type: 'testdb' },
datasource: 'gfdb',
},
],
},
@@ -167,16 +167,16 @@ describe('given dashboard with repeated panels', () => {
it('should replace datasource refs', () => {
const panel = exported.panels[0];
expect(panel.datasource).toBe('${DS_GFDB}');
expect(panel.datasource.uid).toBe('${DS_GFDB}');
});
it('should replace datasource refs in collapsed row', () => {
const panel = exported.panels[6].panels[0];
expect(panel.datasource).toBe('${DS_GFDB}');
expect(panel.datasource.uid).toBe('${DS_GFDB}');
});
it('should replace datasource in variable query', () => {
expect(exported.templating.list[0].datasource).toBe('${DS_GFDB}');
expect(exported.templating.list[0].datasource.uid).toBe('${DS_GFDB}');
expect(exported.templating.list[0].options.length).toBe(0);
expect(exported.templating.list[0].current.value).toBe(undefined);
expect(exported.templating.list[0].current.text).toBe(undefined);
@@ -280,8 +280,11 @@ describe('given dashboard with repeated panels', () => {
expect(element.kind).toBe(LibraryElementKind.Panel);
expect(element.model).toEqual({
id: 16,
datasource: '${DS_GFDB}',
type: 'graph',
datasource: {
type: 'testdb',
uid: '${DS_GFDB}',
},
});
});
});
@@ -116,7 +116,11 @@ export class DashboardExporter {
pluginName: ds.meta?.name,
};
obj.datasource = '${' + refName + '}';
if (obj.datasource === null || typeof obj.datasource === 'string') {
obj.datasource = '${' + refName + '}';
} else {
obj.datasource.uid = '${' + refName + '}';
}
})
);
};