DataSourceApi: More specific naming for getFiltersApplicability (#110407)
* rename getFiltersApplicability * typecheck * typecheck
This commit is contained in:
@@ -658,6 +658,7 @@ export {
|
||||
type DataSourceConstructor,
|
||||
type DataSourceGetTagKeysOptions,
|
||||
type DataSourceGetTagValuesOptions,
|
||||
type DataSourceGetDrilldownsApplicabilityOptions,
|
||||
type MetadataInspectorProps,
|
||||
type LegacyMetricFindQueryOptions,
|
||||
type QueryEditorProps,
|
||||
@@ -674,7 +675,7 @@ export {
|
||||
type QueryFixAction,
|
||||
type QueryHint,
|
||||
type MetricFindValue,
|
||||
type FiltersApplicability,
|
||||
type DrilldownsApplicability,
|
||||
type DataSourceJsonData,
|
||||
type DataSourceSettings,
|
||||
type DataSourceInstanceSettings,
|
||||
|
||||
@@ -307,9 +307,11 @@ abstract class DataSourceApi<
|
||||
metricFindQuery?(query: any, options?: LegacyMetricFindQueryOptions): Promise<MetricFindValue[]>;
|
||||
|
||||
/**
|
||||
* Verify adhoc filters applicability based on queries and current filters
|
||||
* Verify adhoc filters and groupBy keys applicability based on queries and current selected values
|
||||
*/
|
||||
getFiltersApplicability?(options?: DataSourceGetFiltersApplicabilityOptions<TQuery>): Promise<FiltersApplicability[]>;
|
||||
getDrilldownsApplicability?(
|
||||
options?: DataSourceGetDrilldownsApplicabilityOptions<TQuery>
|
||||
): Promise<DrilldownsApplicability[]>;
|
||||
|
||||
/**
|
||||
* Get tag keys for adhoc filters
|
||||
@@ -643,7 +645,7 @@ export interface MetricFindValue {
|
||||
expandable?: boolean;
|
||||
}
|
||||
|
||||
export interface DataSourceGetFiltersApplicabilityOptions<TQuery extends DataQuery = DataQuery> {
|
||||
export interface DataSourceGetDrilldownsApplicabilityOptions<TQuery extends DataQuery = DataQuery> {
|
||||
filters: AdHocVariableFilter[];
|
||||
groupByKeys?: string[];
|
||||
timeRange?: TimeRange;
|
||||
@@ -651,7 +653,7 @@ export interface DataSourceGetFiltersApplicabilityOptions<TQuery extends DataQue
|
||||
scopes?: Scope[] | undefined;
|
||||
}
|
||||
|
||||
export interface FiltersApplicability {
|
||||
export interface DrilldownsApplicability {
|
||||
key: string;
|
||||
applicable: boolean;
|
||||
// message explaining why the filter is not applicable
|
||||
|
||||
@@ -570,7 +570,7 @@ describe('DashboardDatasource', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFiltersApplicability', () => {
|
||||
describe('getDrilldownsApplicability', () => {
|
||||
const originalToggleValue = config.featureToggles.dashboardDsAdHocFiltering;
|
||||
const ds = new DashboardDatasource({} as DataSourceInstanceSettings);
|
||||
|
||||
@@ -585,7 +585,7 @@ describe('DashboardDatasource', () => {
|
||||
it('should return empty array when feature toggle is disabled', async () => {
|
||||
config.featureToggles.dashboardDsAdHocFiltering = false;
|
||||
|
||||
const result = await ds.getFiltersApplicability({
|
||||
const result = await ds.getDrilldownsApplicability({
|
||||
filters: [{ key: 'name', operator: '=', value: 'test' }],
|
||||
});
|
||||
|
||||
@@ -593,7 +593,7 @@ describe('DashboardDatasource', () => {
|
||||
});
|
||||
|
||||
it('should mark supported operators as applicable', async () => {
|
||||
const result = await ds.getFiltersApplicability({
|
||||
const result = await ds.getDrilldownsApplicability({
|
||||
filters: [
|
||||
{ key: 'name', operator: '=', value: 'John' },
|
||||
{ key: 'age', operator: '!=', value: '25' },
|
||||
@@ -607,7 +607,7 @@ describe('DashboardDatasource', () => {
|
||||
});
|
||||
|
||||
it('should mark unsupported operators as not applicable with reason', async () => {
|
||||
const result = await ds.getFiltersApplicability({
|
||||
const result = await ds.getDrilldownsApplicability({
|
||||
filters: [
|
||||
{ key: 'name', operator: '>', value: 'John' },
|
||||
{ key: 'age', operator: '<', value: '25' },
|
||||
@@ -635,7 +635,7 @@ describe('DashboardDatasource', () => {
|
||||
});
|
||||
|
||||
it('should handle mixed applicable and non-applicable filters', async () => {
|
||||
const result = await ds.getFiltersApplicability({
|
||||
const result = await ds.getDrilldownsApplicability({
|
||||
filters: [
|
||||
{ key: 'name', operator: '=', value: 'John' },
|
||||
{ key: 'age', operator: '>', value: '25' },
|
||||
@@ -655,12 +655,12 @@ describe('DashboardDatasource', () => {
|
||||
});
|
||||
|
||||
it('should handle empty filters array', async () => {
|
||||
const result = await ds.getFiltersApplicability({ filters: [] });
|
||||
const result = await ds.getDrilldownsApplicability({ filters: [] });
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('should handle missing options', async () => {
|
||||
const result = await ds.getFiltersApplicability();
|
||||
const result = await ds.getDrilldownsApplicability();
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,8 +17,8 @@ import {
|
||||
MetricFindValue,
|
||||
getValueMatcher,
|
||||
ValueMatcherID,
|
||||
FiltersApplicability,
|
||||
DataSourceGetTagKeysOptions,
|
||||
DataSourceGetDrilldownsApplicabilityOptions,
|
||||
DrilldownsApplicability,
|
||||
} from '@grafana/data';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { SceneDataProvider, SceneDataTransformer, SceneObject } from '@grafana/scenes';
|
||||
@@ -341,16 +341,16 @@ export class DashboardDatasource extends DataSourceApi<DashboardQuery> {
|
||||
/**
|
||||
* Check which AdHoc filters are applicable based on operator and field type support
|
||||
*/
|
||||
async getFiltersApplicability(
|
||||
options?: DataSourceGetTagKeysOptions<DashboardQuery>
|
||||
): Promise<FiltersApplicability[]> {
|
||||
async getDrilldownsApplicability(
|
||||
options?: DataSourceGetDrilldownsApplicabilityOptions<DashboardQuery>
|
||||
): Promise<DrilldownsApplicability[]> {
|
||||
if (!config.featureToggles.dashboardDsAdHocFiltering) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const filters = options?.filters || [];
|
||||
|
||||
return filters.map((filter): FiltersApplicability => {
|
||||
return filters.map((filter): DrilldownsApplicability => {
|
||||
// Check operator support
|
||||
if (filter.operator !== '=' && filter.operator !== '!=') {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user