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

(cherry picked from commit f37c8c10c5)

Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
Grot (@grafanabot)
2021-03-29 14:43:02 +02:00
committed by GitHub
co-authored by Torkel Ödegaard
parent c33d12185d
commit 0c208a31dd
2 changed files with 10 additions and 0 deletions
@@ -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;
}
@@ -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,
},