Skip to content

Commit

Permalink
fix: extend AllFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
alxgrant committed Dec 16, 2024
1 parent dd77833 commit f87c103
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/analytics/analytics-utilities/src/types/explore/all.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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 BasicExploreFilter, type BasicExploreFilterAll, filterableBasicExploreDimensions } from './basic'
import { type AiExploreAggregations, type AiExploreFilter, type AiExploreFilterAll, filterableAiExploreDimensions } from './ai'
import { type ExploreAggregations, type ExploreFilter, 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

Expand All @@ -23,9 +23,13 @@ export const datasourceToFilterableDimensions: Record<QueryDatasource, Set<strin

// Utility for stripping unknown filters
export const stripUnknownFilters = <K extends keyof typeof datasourceToFilterableDimensions>(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 => {
if ('dimension' in f) {
datasourceToFilterableDimensions[datasource].has(f.dimension)
} else {
datasourceToFilterableDimensions[datasource].has(f.field)
}
}) as FilterTypeMap[K][]
}

// TODO: Add utility func for marking unknown filters (but not stripping them).

0 comments on commit f87c103

Please sign in to comment.