Variables: Add support for aliasIDs to datasource variables (Fixes issue with Postgres datasource variables) (#78170)

* Variables: Add support for aliasIDs to datasource variables

* remove file
This commit is contained in:
Torkel Ödegaard 2023-11-15 11:18:21 +01:00 committed by GitHub
parent 1d1d42c984
commit f7e5689305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 9 deletions

View File

@ -26,3 +26,4 @@ export { withLoadingIndicator, type WithLoadingIndicatorOptions } from './withLo
export { convertOldAngularValueMappings, LegacyMappingType } from './valueMappings';
export { containsSearchFilter, type SearchFilterOptions, getSearchFilterScopedVar } from './variables';
export { renderLegendFormat } from './legend';
export { matchPluginId } from './matchPluginId';

View File

@ -0,0 +1,13 @@
import { PluginMeta } from '../types';
export function matchPluginId(idToMatch: string, pluginMeta: PluginMeta) {
if (pluginMeta.id === idToMatch) {
return true;
}
if (pluginMeta.aliasIDs) {
return pluginMeta.aliasIDs.includes(idToMatch);
}
return false;
}

View File

@ -1,5 +1,3 @@
import { some } from 'lodash';
import {
AppEvents,
DataSourceApi,
@ -7,6 +5,7 @@ import {
DataSourceRef,
DataSourceSelectItem,
ScopedVars,
matchPluginId,
} from '@grafana/data';
import {
DataSourceSrv as DataSourceService,
@ -224,10 +223,7 @@ export class DatasourceSrv implements DataSourceService {
if (filters.alerting && !x.meta.alerting) {
return false;
}
if (
filters.pluginId &&
!(x.meta.id === filters.pluginId || some(x.meta.aliasIDs, (id) => id === filters.pluginId))
) {
if (filters.pluginId && !matchPluginId(filters.pluginId, x.meta)) {
return false;
}
if (filters.filter && !filters.filter(x)) {

View File

@ -1,6 +1,6 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { DataSourceInstanceSettings } from '@grafana/data';
import { DataSourceInstanceSettings, matchPluginId } from '@grafana/data';
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../constants';
import { getInstanceState } from '../state/selectors';
@ -36,8 +36,8 @@ export const dataSourceVariableSlice = createSlice({
for (let i = 0; i < sources.length; i++) {
const source = sources[i];
// must match on type
if (source.meta.id !== instanceState.query) {
if (!matchPluginId(instanceState.query, source.meta)) {
continue;
}