mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
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:
parent
1d1d42c984
commit
f7e5689305
@ -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';
|
||||
|
13
packages/grafana-data/src/utils/matchPluginId.ts
Normal file
13
packages/grafana-data/src/utils/matchPluginId.ts
Normal 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;
|
||||
}
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user