diff --git a/packages/analytics/analytics-metric-provider/src/components/metricsProviderUtil.ts b/packages/analytics/analytics-metric-provider/src/components/metricsProviderUtil.ts index aa63cf5cf9..9f0d7a7822 100644 --- a/packages/analytics/analytics-metric-provider/src/components/metricsProviderUtil.ts +++ b/packages/analytics/analytics-metric-provider/src/components/metricsProviderUtil.ts @@ -2,6 +2,7 @@ import { type AnalyticsBridge, type ExploreAggregations, type ExploreFilter, + type ExploreFilterAll, type FilterableExploreDimensions, type QueryDatasource, stripUnknownFilters, type Timeframe, @@ -30,7 +31,7 @@ interface FetcherOptions { datasource: Ref dimension?: FilterableExploreDimensions dimensionFilterValue?: string - additionalFilter: Ref + additionalFilter: Ref queryReady: Ref timeframe: Ref tz: Ref diff --git a/packages/analytics/analytics-utilities/src/types/explore/all.ts b/packages/analytics/analytics-utilities/src/types/explore/all.ts index 51a2fa2e9f..047201bcfd 100644 --- a/packages/analytics/analytics-utilities/src/types/explore/all.ts +++ b/packages/analytics/analytics-utilities/src/types/explore/all.ts @@ -1,18 +1,18 @@ -import { type BasicExploreAggregations, type BasicExploreFilter, filterableBasicExploreDimensions } from './basic' -import { type AiExploreAggregations, type AiExploreFilter, filterableAiExploreDimensions } from './ai' -import { type ExploreAggregations, type ExploreFilter, filterableExploreDimensions } from './advanced' +import { type BasicExploreAggregations, type BasicExploreFilterAll, filterableBasicExploreDimensions } from './basic' +import { type AiExploreAggregations, type AiExploreFilterAll, filterableAiExploreDimensions } from './ai' +import { type ExploreAggregations, type ExploreFilterAll, filterableExploreDimensions } from './advanced' export type AllAggregations = BasicExploreAggregations | AiExploreAggregations | ExploreAggregations -export type AllFilters = BasicExploreFilter | AiExploreFilter | ExploreFilter +export type AllFilters = BasicExploreFilterAll | AiExploreFilterAll | ExploreFilterAll export const queryDatasources = ['basic', 'advanced', 'ai'] as const export type QueryDatasource = typeof queryDatasources[number] export interface FilterTypeMap extends Record { - basic: BasicExploreFilter, - advanced: ExploreFilter, - ai: AiExploreFilter, + basic: BasicExploreFilterAll, + advanced: ExploreFilterAll, + ai: AiExploreFilterAll, } export const datasourceToFilterableDimensions: Record> = { @@ -25,7 +25,7 @@ export const datasourceToFilterableDimensions: Record(datasource: K, filters: AllFilters[]): FilterTypeMap[K][] => { // Note: once we extend API request filters, this may need to look at more than just dimensions. // Note the cast; we could potentially try to derive the type, but it doesn't seem worth it. - return filters.filter(f => datasourceToFilterableDimensions[datasource].has(f.dimension)) as FilterTypeMap[K][] + return filters.filter(f => 'dimension' in f ? datasourceToFilterableDimensions[datasource].has(f.dimension) : datasourceToFilterableDimensions[datasource].has(f.field)) as FilterTypeMap[K][] } // TODO: Add utility func for marking unknown filters (but not stripping them). diff --git a/packages/analytics/dashboard-renderer/src/components/QueryDataProvider.vue b/packages/analytics/dashboard-renderer/src/components/QueryDataProvider.vue index 5b6742a525..3480589b54 100644 --- a/packages/analytics/dashboard-renderer/src/components/QueryDataProvider.vue +++ b/packages/analytics/dashboard-renderer/src/components/QueryDataProvider.vue @@ -101,7 +101,7 @@ const { data: v4Data, error, isValidating } = useSWRV(queryKey, async () => { datasource = 'basic' } - const mergedFilters = deriveFilters(datasource, props.query.filters, props.context.filters) + const mergedFilters = deriveFilters(datasource, props.query.filters as FilterTypeMap[typeof datasource][], props.context.filters) // TODO: similar to other places, consider adding a type guard to ensure the query // matches the datasource. Currently, this block effectively pretends all queries diff --git a/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts b/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts index 9e7514122e..2e35addb6c 100644 --- a/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts +++ b/packages/analytics/dashboard-renderer/src/types/dashboard-renderer-types.ts @@ -15,6 +15,7 @@ import { queryableBasicExploreDimensions, queryableExploreDimensions, relativeTimeRangeValuesV4, + requestFilterTypeEmptyV2, } from '@kong-ui-public/analytics-utilities' export interface DashboardRendererContext { @@ -306,32 +307,78 @@ const dimensionsFn = (dimensions: T) => ({ const filtersFn = (filterableDimensions: T) => ({ type: 'array', - description: 'A list of filters to apply to the query.', + description: 'A list of filters to apply to the query', items: { - type: 'object', - description: 'A filter that specifies which data to include in the query', - properties: { - dimension: { - type: 'string', - enum: filterableDimensions, + oneOf: [ + { + type: 'object', + description: 'A filter that specifies which data to include in the query', + properties: { + dimension: { + type: 'string', + enum: filterableDimensions, + }, + type: { + type: 'string', + enum: exploreFilterTypesV2, + }, + values: { + type: 'array', + items: { + type: ['string', 'number', 'null'], + }, + }, + }, + required: [ + 'dimension', + 'type', + 'values', + ], + additionalProperties: false, }, - type: { - type: 'string', - enum: exploreFilterTypesV2, + { + type: 'object', + description: 'In filter', + properties: { + field: { + type: 'string', + enum: filterableDimensions, + }, + operator: { + type: 'string', + enum: exploreFilterTypesV2, + }, + value: { + type: ['string', 'number', 'null'], + }, + }, + required: [ + 'field', + 'operator', + 'value', + ], + additionalProperties: false, }, - values: { - type: 'array', - items: { - type: ['string', 'number', 'null'], + { + type: 'object', + description: 'Empty filter', + properties: { + field: { + type: 'string', + enum: filterableDimensions, + }, + operator: { + type: 'string', + enum: requestFilterTypeEmptyV2, + }, }, + required: [ + 'field', + 'operator', + ], + additionalProperties: false, }, - }, - required: [ - 'dimension', - 'type', - 'values', ], - additionalProperties: false, }, } as const satisfies JSONSchema)