mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DataSourceVariables: Fix storing uninterpolated datasource in ds ref uid prop (#41248)
* DataSourceVariables: Fix storing uninterpolated datasource in ds ref uid prop * better variable name * Fix issue changing from data source variable to specific data source of the same type * revert name change * Update public/app/features/plugins/datasource_srv.ts Co-authored-by: Ryan McKinley <ryantxu@gmail.com> * Simply logic and remove deep clone * updated comment Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
parent
1b5b747885
commit
59c97bb1b2
@ -27,7 +27,6 @@ import {
|
||||
instanceSettings as expressionInstanceSettings,
|
||||
} from 'app/features/expressions/ExpressionDatasource';
|
||||
import { DataSourceVariableModel } from '../variables/types';
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
export class DatasourceSrv implements DataSourceService {
|
||||
private datasources: Record<string, DataSourceApi> = {}; // UID
|
||||
@ -101,13 +100,14 @@ export class DatasourceSrv implements DataSourceService {
|
||||
if (!dsSettings) {
|
||||
return undefined;
|
||||
}
|
||||
// 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;
|
||||
// Return an instance with un-interpolated values for name and uid
|
||||
return {
|
||||
...dsSettings,
|
||||
isDefault: false,
|
||||
name: nameOrUid,
|
||||
uid: nameOrUid,
|
||||
};
|
||||
}
|
||||
|
||||
return this.settingsMapByUid[nameOrUid] ?? this.settingsMapByName[nameOrUid];
|
||||
@ -243,6 +243,7 @@ export class DatasourceSrv implements DataSourceService {
|
||||
base.push({
|
||||
...dsSettings,
|
||||
name: key,
|
||||
uid: key,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ describe('datasource_srv', () => {
|
||||
it('should work with variable', () => {
|
||||
const ds = dataSourceSrv.getInstanceSettings('${datasource}');
|
||||
expect(ds?.name).toBe('${datasource}');
|
||||
expect(ds?.uid).toBe('uid-code-BBB');
|
||||
expect(ds?.uid).toBe('${datasource}');
|
||||
});
|
||||
|
||||
it('should not set isDefault when being fetched via variable', () => {
|
||||
@ -136,7 +136,7 @@ describe('datasource_srv', () => {
|
||||
it('should work with variable', () => {
|
||||
const ds = dataSourceSrv.getInstanceSettings('${datasourceDefault}');
|
||||
expect(ds?.name).toBe('${datasourceDefault}');
|
||||
expect(ds?.uid).toBe('uid-code-BBB');
|
||||
expect(ds?.uid).toBe('${datasourceDefault}');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user