Variables: Fixes problem with data source variable when default ds is selected (#32384)

This commit is contained in:
Torkel Ödegaard 2021-03-29 14:10:40 +02:00 committed by GitHub
parent eebcc55faa
commit f37c8c10c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -69,6 +69,9 @@ export class DatasourceSrv implements DataSourceService {
// The return name or uid needs preservet string containing the variable
const clone = cloneDeep(dsSettings);
clone.name = nameOrUid;
// A data source being looked up using a variable should not be considered default
clone.isDefault = false;
return clone;
}

View File

@ -77,6 +77,7 @@ describe('datasource_srv', () => {
name: 'BBB',
uid: 'uid-code-BBB',
meta: { metrics: true },
isDefault: true,
},
Jaeger: {
type: 'jaeger-db',
@ -127,6 +128,11 @@ describe('datasource_srv', () => {
expect(ds?.uid).toBe('uid-code-BBB');
});
it('should not set isDefault when being fetched via variable', () => {
const ds = dataSourceSrv.getInstanceSettings('${datasource}');
expect(ds?.isDefault).toBe(false);
});
it('should work with variable', () => {
const ds = dataSourceSrv.getInstanceSettings('${datasourceDefault}');
expect(ds?.name).toBe('${datasourceDefault}');
@ -182,6 +188,7 @@ describe('datasource_srv', () => {
"uid": "uid-code-aaa",
},
Object {
"isDefault": true,
"meta": Object {
"metrics": true,
},