mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard: replace datasource name with a reference object (#33817)
Co-authored-by: Torkel Ödegaard <torkel@grafana.com> Co-authored-by: Elfo404 <me@giordanoricci.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import {
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
DataSourcePluginMeta,
|
||||
DataSourceRef,
|
||||
getDataSourceUID,
|
||||
} from '@grafana/data';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@@ -12,15 +14,16 @@ export class DatasourceSrvMock {
|
||||
//
|
||||
}
|
||||
|
||||
get(name?: string): Promise<DataSourceApi> {
|
||||
if (!name) {
|
||||
get(ref?: DataSourceRef | string): Promise<DataSourceApi> {
|
||||
if (!ref) {
|
||||
return Promise.resolve(this.defaultDS);
|
||||
}
|
||||
const ds = this.datasources[name];
|
||||
const uid = getDataSourceUID(ref) ?? '';
|
||||
const ds = this.datasources[uid];
|
||||
if (ds) {
|
||||
return Promise.resolve(ds);
|
||||
}
|
||||
return Promise.reject('Unknown Datasource: ' + name);
|
||||
return Promise.reject(`Unknown Datasource: ${JSON.stringify(ref)}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user