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

This commit is contained in:
Torkel Ödegaard 2021-11-26 10:06:41 +01:00 committed by GitHub
parent b164ce0c9b
commit 1e1403fad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -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}',
},
});
});
});

View File

@ -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 + '}';
}
})
);
};