3
0
mirror of https://github.com/grafana/grafana.git synced 2025-02-25 18:55:37 -06:00

@grafana/data: Introduce new getTagKeys/getTagValues response interface ()

* @grafana/data: Introduce new getTagKeys/getTagValues response interface
This commit is contained in:
kay delaney 2024-06-10 13:48:40 +01:00 committed by GitHub
parent 80bdfbe2eb
commit 207672365a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 16 deletions
packages/grafana-data/src/types
public/app
features/variables/adhoc/picker
plugins/datasource/tempo/_importedDependencies/components/AdHocFilter

View File

@ -285,12 +285,12 @@ abstract class DataSourceApi<
/**
* Get tag keys for adhoc filters
*/
getTagKeys?(options?: DataSourceGetTagKeysOptions<TQuery>): Promise<MetricFindValue[]>;
getTagKeys?(options?: DataSourceGetTagKeysOptions<TQuery>): Promise<GetTagResponse> | Promise<MetricFindValue[]>;
/**
* Get tag values for adhoc filters
*/
getTagValues?(options: DataSourceGetTagValuesOptions<TQuery>): Promise<MetricFindValue[]>;
getTagValues?(options: DataSourceGetTagValuesOptions<TQuery>): Promise<GetTagResponse> | Promise<MetricFindValue[]>;
/**
* Set after constructor call, as the data source instance is the most common thing to pass around
@ -713,6 +713,11 @@ export interface HistoryItem<TQuery extends DataQuery = DataQuery> {
query: TQuery;
}
export interface GetTagResponse {
data: MetricFindValue[];
error?: DataQueryError;
}
abstract class LanguageProvider {
abstract datasource: DataSourceApi<any, any>;
abstract request: (url: string, params?: any) => Promise<any>;

View File

@ -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 }));
};

View File

@ -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() {

View File

@ -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 }));
};

View File

@ -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 }));
};