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:
@@ -1,4 +1,4 @@
|
||||
import { DataQuery, DataSourceInstanceSettings } from '@grafana/data';
|
||||
import { DataQuery, DataSourceInstanceSettings, DataSourceRef, getDataSourceRef } from '@grafana/data';
|
||||
|
||||
export const getNextRefIdChar = (queries: DataQuery[]): string => {
|
||||
for (let num = 0; ; num++) {
|
||||
@@ -9,7 +9,7 @@ export const getNextRefIdChar = (queries: DataQuery[]): string => {
|
||||
}
|
||||
};
|
||||
|
||||
export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>, datasource?: string): DataQuery[] {
|
||||
export function addQuery(queries: DataQuery[], query?: Partial<DataQuery>, datasource?: DataSourceRef): DataQuery[] {
|
||||
const q = query || {};
|
||||
q.refId = getNextRefIdChar(queries);
|
||||
q.hide = false;
|
||||
@@ -27,16 +27,18 @@ export function updateQueries(
|
||||
extensionID: string, // pass this in because importing it creates a circular dependency
|
||||
dsSettings?: DataSourceInstanceSettings
|
||||
): DataQuery[] {
|
||||
const datasource = getDataSourceRef(newSettings);
|
||||
|
||||
if (!newSettings.meta.mixed && dsSettings?.meta.mixed) {
|
||||
return queries.map((q) => {
|
||||
if (q.datasource !== extensionID) {
|
||||
q.datasource = newSettings.name;
|
||||
q.datasource = datasource;
|
||||
}
|
||||
return q;
|
||||
});
|
||||
} else if (!newSettings.meta.mixed && dsSettings?.meta.id !== newSettings.meta.id) {
|
||||
// we are changing data source type, clear queries
|
||||
return [{ refId: 'A', datasource: newSettings.name }];
|
||||
return [{ refId: 'A', datasource }];
|
||||
}
|
||||
|
||||
return queries;
|
||||
|
||||
Reference in New Issue
Block a user