From 207672365a040d9fb6fc527c2f629d228958bf6c Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:48:40 +0100 Subject: [PATCH] @grafana/data: Introduce new getTagKeys/getTagValues response interface (#88369) * @grafana/data: Introduce new getTagKeys/getTagValues response interface --- packages/grafana-data/src/types/datasource.ts | 9 +++++++-- .../variables/adhoc/picker/AdHocFilterKey.tsx | 3 ++- .../variables/adhoc/picker/AdHocFilterValue.tsx | 7 ++++--- .../components/AdHocFilter/AdHocFilterKey.tsx | 3 ++- .../components/AdHocFilter/AdHocFilterValue.tsx | 13 ++++--------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index cd22fb00b64..2990facb107 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -285,12 +285,12 @@ abstract class DataSourceApi< /** * Get tag keys for adhoc filters */ - getTagKeys?(options?: DataSourceGetTagKeysOptions): Promise; + getTagKeys?(options?: DataSourceGetTagKeysOptions): Promise | Promise; /** * Get tag values for adhoc filters */ - getTagValues?(options: DataSourceGetTagValuesOptions): Promise; + getTagValues?(options: DataSourceGetTagValuesOptions): Promise | Promise; /** * Set after constructor call, as the data source instance is the most common thing to pass around @@ -713,6 +713,11 @@ export interface HistoryItem { query: TQuery; } +export interface GetTagResponse { + data: MetricFindValue[]; + error?: DataQueryError; +} + abstract class LanguageProvider { abstract datasource: DataSourceApi; abstract request: (url: string, params?: any) => Promise; diff --git a/public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx b/public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx index ca19658b1f1..a75cc6765fa 100644 --- a/public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx +++ b/public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx @@ -69,7 +69,8 @@ const fetchFilterKeys = async ( } const otherFilters = allFilters.filter((f) => f.key !== currentKey); - const metrics = await ds.getTagKeys({ filters: otherFilters }); + const response = await ds.getTagKeys({ filters: otherFilters }); + const metrics = Array.isArray(response) ? response : response.data; return metrics.map((m) => ({ label: m.text, value: m.text })); }; diff --git a/public/app/features/variables/adhoc/picker/AdHocFilterValue.tsx b/public/app/features/variables/adhoc/picker/AdHocFilterValue.tsx index e733043c8b9..1079e892aa8 100644 --- a/public/app/features/variables/adhoc/picker/AdHocFilterValue.tsx +++ b/public/app/features/variables/adhoc/picker/AdHocFilterValue.tsx @@ -1,7 +1,7 @@ import { css } from '@emotion/css'; import React from 'react'; -import { AdHocVariableFilter, DataSourceRef, MetricFindValue, SelectableValue } from '@grafana/data'; +import { AdHocVariableFilter, DataSourceRef, SelectableValue } from '@grafana/data'; import { SegmentAsync, useStyles2 } from '@grafana/ui'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; @@ -57,8 +57,9 @@ const fetchFilterValues = async ( const timeRange = getTimeSrv().timeRange(); // Filter out the current filter key from the list of all filters const otherFilters = allFilters.filter((f) => f.key !== key); - const metrics = await ds.getTagValues({ key, filters: otherFilters, timeRange }); - return metrics.map((m: MetricFindValue) => ({ label: m.text, value: m.text })); + const response = await ds.getTagValues({ key, filters: otherFilters, timeRange }); + const metrics = Array.isArray(response) ? response : response.data; + return metrics.map((m) => ({ label: m.text, value: m.text })); }; function getStyles() { diff --git a/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterKey.tsx b/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterKey.tsx index 5c0fc5bcf4d..fb57eb9d7f8 100644 --- a/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterKey.tsx +++ b/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterKey.tsx @@ -68,7 +68,8 @@ const fetchFilterKeys = async ( } const otherFilters = allFilters.filter((f) => f.key !== currentKey); - const metrics = await ds.getTagKeys({ filters: otherFilters }); + const response = await ds.getTagKeys({ filters: otherFilters }); + const metrics = Array.isArray(response) ? response : response.data; return metrics.map((m) => ({ label: m.text, value: m.text })); }; diff --git a/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterValue.tsx b/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterValue.tsx index a8034bf1654..3c2e23dbd7c 100644 --- a/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterValue.tsx +++ b/public/app/plugins/datasource/tempo/_importedDependencies/components/AdHocFilter/AdHocFilterValue.tsx @@ -1,12 +1,6 @@ import React from 'react'; -import { - AdHocVariableFilter, - DataSourceRef, - MetricFindValue, - SelectableValue, - getDefaultTimeRange, -} from '@grafana/data'; +import { AdHocVariableFilter, DataSourceRef, SelectableValue, getDefaultTimeRange } from '@grafana/data'; // import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { getDataSourceSrv } from '@grafana/runtime'; import { SegmentAsync } from '@grafana/ui'; @@ -63,6 +57,7 @@ const fetchFilterValues = async ( // Filter out the current filter key from the list of all filters const otherFilters = allFilters.filter((f) => f.key !== key); - const metrics = await ds.getTagValues({ key, filters: otherFilters, timeRange }); - return metrics.map((m: MetricFindValue) => ({ label: m.text, value: m.text })); + const response = await ds.getTagValues({ key, filters: otherFilters, timeRange }); + const metrics = Array.isArray(response) ? response : response.data; + return metrics.map((m) => ({ label: m.text, value: m.text })); };