diff --git a/packages/grafana-data/src/utils/index.ts b/packages/grafana-data/src/utils/index.ts index 41909d9b64f..e56ef12c010 100644 --- a/packages/grafana-data/src/utils/index.ts +++ b/packages/grafana-data/src/utils/index.ts @@ -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'; diff --git a/packages/grafana-data/src/utils/matchPluginId.ts b/packages/grafana-data/src/utils/matchPluginId.ts new file mode 100644 index 00000000000..d21a0654215 --- /dev/null +++ b/packages/grafana-data/src/utils/matchPluginId.ts @@ -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; +} diff --git a/public/app/features/plugins/datasource_srv.ts b/public/app/features/plugins/datasource_srv.ts index e9b3b858662..df342cb746b 100644 --- a/public/app/features/plugins/datasource_srv.ts +++ b/public/app/features/plugins/datasource_srv.ts @@ -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)) { diff --git a/public/app/features/variables/datasource/reducer.ts b/public/app/features/variables/datasource/reducer.ts index 550c4c700af..b0949752273 100644 --- a/public/app/features/variables/datasource/reducer.ts +++ b/public/app/features/variables/datasource/reducer.ts @@ -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; }