mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardExport: Correctly templetatize datasource prop now that is's a ref obj (#42305)
This commit is contained in:
parent
b164ce0c9b
commit
1e1403fad1
@ -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 + '}';
|
||||
}
|
||||
})
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user