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 (#88369)
* @grafana/data: Introduce new getTagKeys/getTagValues response interface
This commit is contained in:
parent
80bdfbe2eb
commit
207672365a
packages/grafana-data/src/types
public/app
features/variables/adhoc/picker
plugins/datasource/tempo/_importedDependencies/components/AdHocFilter
@ -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>;
|
||||
|
@ -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 }));
|
||||
};
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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 }));
|
||||
};
|
||||
|
||||
|
@ -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 }));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user