Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(insights): delete EntityFilter and the warehouse filter types (#127312)

Thomas Obermüller6470e860e8f3
diff --git a/frontend/src/lib/components/ActivityLog/activityDescriptions/tagActivityDescriber.tsx b/frontend/src/lib/components/ActivityLog/activityDescriptions/tagActivityDescriber.tsx
index af5baf1c0a7d..27b8acb34c90 100644
--- a/frontend/src/lib/components/ActivityLog/activityDescriptions/tagActivityDescriber.tsx
+++ b/frontend/src/lib/components/ActivityLog/activityDescriptions/tagActivityDescriber.tsx
@@ -11,7 +11,6 @@ import { Link } from 'lib/lemon-ui/Link'
import { urls } from 'scenes/urls'
import { getFilterLabel } from '~/taxonomy/helpers'
-import { EntityFilter } from '~/types'
const nameOrId = (name?: string | null, id?: string | null): string => {
if (name) {
@@ -32,7 +31,7 @@ const getRelatedObjectDescription = (context: any, preposition?: 'to' | 'from'):
const getDisplayName = (): string => {
if (objectType === 'event_definition') {
- return getDisplayNameFromEntityFilter({ name: objectName } as EntityFilter, false) || objectName
+ return getDisplayNameFromEntityFilter({ name: objectName }, false) || objectName
}
if (objectType === 'property_definition') {
return getFilterLabel(objectName, TaxonomicFilterGroupType.EventProperties)
diff --git a/frontend/src/lib/components/EntityFilterInfo.stories.tsx b/frontend/src/lib/components/EntityFilterInfo.stories.tsx
index 149c62a5cdd3..a0ee29db45ad 100644
--- a/frontend/src/lib/components/EntityFilterInfo.stories.tsx
+++ b/frontend/src/lib/components/EntityFilterInfo.stories.tsx
@@ -1,8 +1,8 @@
import { Meta, StoryObj } from '@storybook/react'
-import { ActionFilter, EntityFilter, EntityTypes } from '~/types'
+import { EntityTypes } from '~/types'
-import { EntityFilterInfo } from './EntityFilterInfo'
+import { DisplayableEntity, EntityFilterInfo } from './EntityFilterInfo'
const meta: Meta<typeof EntityFilterInfo> = {
title: 'Components/Entity Filter Info',
@@ -20,7 +20,7 @@ const meta: Meta<typeof EntityFilterInfo> = {
export default meta
type Story = StoryObj<typeof EntityFilterInfo>
-const VARIANTS: { label: string; filter: EntityFilter | ActionFilter }[] = [
+const VARIANTS: { label: string; filter: DisplayableEntity }[] = [
{
label: 'Unrenamed core event (single label, no tooltip)',
filter: { type: EntityTypes.EVENTS, id: '$pageview', name: '$pageview' },
diff --git a/frontend/src/lib/components/EntityFilterInfo.test.tsx b/frontend/src/lib/components/EntityFilterInfo.test.tsx
index 5e11d2b71e1f..819a71c8ac39 100644
--- a/frontend/src/lib/components/EntityFilterInfo.test.tsx
+++ b/frontend/src/lib/components/EntityFilterInfo.test.tsx
@@ -5,7 +5,7 @@ import userEvent from '@testing-library/user-event'
import { NodeKind } from '~/queries/schema/schema-general'
import { initKeaTests } from '~/test/init'
-import { ActionFilter, EntityFilter, EntityTypes } from '~/types'
+import { EntityTypes } from '~/types'
import { DisplayableEntity, EntityFilterInfo } from './EntityFilterInfo'
@@ -145,7 +145,7 @@ describe('EntityFilterInfo', () => {
it.each([
['null', null],
['undefined', undefined],
- ] as [string, EntityFilter | ActionFilter | null | undefined][])(
+ ] as [string, DisplayableEntity | null | undefined][])(
'renders nothing without throwing for a %s filter',
(_, filter) => {
const { container } = render(<EntityFilterInfo filter={filter} />)
diff --git a/frontend/src/lib/components/EntityFilterInfo.tsx b/frontend/src/lib/components/EntityFilterInfo.tsx
index 046585359867..0bba1ebb2450 100644
--- a/frontend/src/lib/components/EntityFilterInfo.tsx
+++ b/frontend/src/lib/components/EntityFilterInfo.tsx
@@ -1,6 +1,7 @@
import clsx from 'clsx'
import {
+ LegacyDisplayEntity,
formatEventName,
getDisplayNameFromEntityFilter,
isAllEventsEntityFilter,
@@ -19,16 +20,16 @@ import {
} from 'scenes/insights/filters/ActionFilter/seriesNode'
import { getCoreFilterDefinition } from '~/taxonomy/helpers'
-import { ActionFilter, EntityFilter, EntityTypes } from '~/types'
+import { ActionFilter, EntityTypes } from '~/types'
import { TaxonomicFilterGroupType } from './TaxonomicFilter/types'
/** A series reaches this component either as a query node or as the legacy entity filter that
* query responses and the legacy-persisted surfaces still carry. */
-export type DisplayableEntity = EntityFilter | ActionFilter | SeriesNode
+export type DisplayableEntity = LegacyDisplayEntity | ActionFilter | SeriesNode
/** Reads a node into the legacy display fields, so one set of display rules serves both shapes. */
-export type DisplayEntityFilter = (EntityFilter | ActionFilter) & { table_name?: string }
+export type DisplayEntityFilter = (LegacyDisplayEntity | ActionFilter) & { table_name?: string }
export function toDisplayEntityFilter(filter: DisplayableEntity): DisplayEntityFilter {
const displayFilter = nodeToDisplayEntityFilter(filter)
diff --git a/frontend/src/lib/components/TaxonomicFilter/types.ts b/frontend/src/lib/components/TaxonomicFilter/types.ts
index 103a870a73fa..79e9f257950b 100644
--- a/frontend/src/lib/components/TaxonomicFilter/types.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/types.ts
@@ -2,6 +2,7 @@ import Fuse from 'fuse.js'
import { LogicWrapper } from 'kea'
import { ReactNode } from 'react'
+import type { LegacyDisplayEntity } from 'lib/insights/entityFilterNames'
import type { SeriesNode } from 'scenes/insights/filters/ActionFilter/seriesNode'
// eslint-disable-next-line import/no-cycle
import type { MaxContextTaxonomicFilterOption } from 'scenes/max/maxTypes'
@@ -12,7 +13,6 @@ import {
ActionType,
AnyPropertyFilter,
CohortType,
- EntityFilter,
EventDefinition,
EventPropertyFilter,
PersonProperty,
@@ -128,7 +128,7 @@ export interface TaxonomicFilterProps {
onClose?: () => void
/** The series/entity filter the picker is editing — lets the list surface
* the committed selection with its rename (`custom_name`) applied. */
- filter?: EntityFilter | ActionFilter | SeriesNode
+ filter?: LegacyDisplayEntity | ActionFilter | SeriesNode
taxonomicGroupTypes: TaxonomicFilterGroupType[]
taxonomicFilterLogicKey?: string
optionsFromProp?: Partial<Record<TaxonomicFilterGroupType, SimpleOption[]>>
diff --git a/frontend/src/lib/insights/entityFilterNames.test.ts b/frontend/src/lib/insights/entityFilterNames.test.ts
index 0700722da7bd..e8dee1be3df9 100644
--- a/frontend/src/lib/insights/entityFilterNames.test.ts
+++ b/frontend/src/lib/insights/entityFilterNames.test.ts
@@ -1,8 +1,6 @@
-import { EntityFilter } from '~/types'
+import { LegacyDisplayEntity, getDisplayNameFromEntityFilter } from './entityFilterNames'
-import { getDisplayNameFromEntityFilter } from './entityFilterNames'
-
-const createFilter = (id?: EntityFilter['id'], name?: string, custom_name?: string): EntityFilter => {
+const createFilter = (id?: LegacyDisplayEntity['id'], name?: string, custom_name?: string): LegacyDisplayEntity => {
return {
custom_name,
name: name ?? null,
@@ -11,7 +9,7 @@ const createFilter = (id?: EntityFilter['id'], name?: string, custom_name?: stri
}
describe('getDisplayNameFromEntityFilter()', () => {
- const paramsToExpected: [EntityFilter, boolean, string | null][] = [
+ const paramsToExpected: [LegacyDisplayEntity, boolean, string | null][] = [
[createFilter(3, 'name', 'custom_name'), true, 'custom_name'],
[createFilter(3, 'name', ''), true, 'name'],
[createFilter(3, 'name', ' '), true, 'name'],
diff --git a/frontend/src/lib/insights/entityFilterNames.ts b/frontend/src/lib/insights/entityFilterNames.ts
index f030137b2fba..306d9604452b 100644
--- a/frontend/src/lib/insights/entityFilterNames.ts
+++ b/frontend/src/lib/insights/entityFilterNames.ts
@@ -1,9 +1,16 @@
import { ensureStringIsNotBlank } from 'lib/utils/strings'
import { CORE_FILTER_DEFINITIONS_BY_GROUP } from '~/taxonomy/taxonomy'
-import { ActionFilter, EntityFilter, EntityTypes } from '~/types'
+import { EntityType, EntityTypes } from '~/types'
-export const isAllEventsEntityFilter = (filter: EntityFilter | ActionFilter | null | undefined): boolean => {
+export interface LegacyDisplayEntity {
+ type?: EntityType
+ id?: string | number | null
+ name?: string | null
+ custom_name?: string | null
+}
+
+export const isAllEventsEntityFilter = (filter: LegacyDisplayEntity | null | undefined): boolean => {
return (
filter != null &&
filter.type === EntityTypes.EVENTS &&
@@ -32,7 +39,7 @@ export const formatEventName = (name: string | undefined | null): string | undef
}
export const getDisplayNameFromEntityFilter = (
- filter: EntityFilter | ActionFilter | null | undefined,
+ filter: LegacyDisplayEntity | null | undefined,
isCustom = true
): string | null => {
// Make sure names aren't blank strings
diff --git a/frontend/src/scenes/dashboard/dashboardTemplateEntities.ts b/frontend/src/scenes/dashboard/dashboardTemplateEntities.ts
index 2ebff1d6f1b1..a287f62bacab 100644
--- a/frontend/src/scenes/dashboard/dashboardTemplateEntities.ts
+++ b/frontend/src/scenes/dashboard/dashboardTemplateEntities.ts
@@ -30,27 +30,40 @@ import {
MathType,
NodeKind,
} from '~/queries/schema/schema-general'
-import {
- ActionFilter,
- AnyDataWarehouseFilter,
- BaseMathType,
- EntityTypes,
- FunnelDatawarehouseFilter,
- LifecycleDatawarehouseFilter,
- RetentionEntity,
- TemplateVariableStep,
- TrendsDataWarehouseFilter,
- isDataWarehouseFilter,
- isGroupFilter,
-} from '~/types'
+import { BaseMathType, EntityTypes, FilterLogicalOperator, RetentionEntity, TemplateVariableStep } from '~/types'
type DataWarehouseNodeKind =
| NodeKind.DataWarehouseNode
| NodeKind.FunnelsDataWarehouseNode
| NodeKind.LifecycleDataWarehouseNode
+/** A stored template variable default. The template editor writes series fields into it that `TemplateVariableStep` does not declare. */
+type TemplateStep = TemplateVariableStep & {
+ math_property?: string | null
+ math_property_type?: string | null
+ math_hogql?: string | null
+ math_group_type_index?: number | null
+ optionalInFunnel?: boolean
+ operator?: FilterLogicalOperator | null
+ nestedFilters?: TemplateStep[] | null
+ table_name?: string
+ id_field?: string
+ timestamp_field?: string
+ distinct_id_field?: string
+ aggregation_target_field?: string
+ created_at_field?: string
+}
+
+function isDataWarehouseStep(step: TemplateStep): boolean {
+ return step.type === EntityTypes.DATA_WAREHOUSE
+}
+
+function isGroupStep(step: TemplateStep): boolean {
+ return step.type === EntityTypes.GROUPS
+}
+
export const legacyEntityToNode = (
- entity: ActionFilter | AnyDataWarehouseFilter,
+ entity: TemplateStep,
includeProperties: boolean,
mathAvailability: MathAvailability,
dataWarehouseNodeKind: DataWarehouseNodeKind = NodeKind.DataWarehouseNode
@@ -62,40 +75,34 @@ export const legacyEntityToNode = (
custom_name: entity.custom_name || undefined,
}
- if (isDataWarehouseFilter(entity)) {
+ if (isDataWarehouseStep(entity)) {
shared = {
...shared,
timestamp_field: entity.timestamp_field || undefined,
table_name: entity.table_name || undefined,
...(dataWarehouseNodeKind === NodeKind.LifecycleDataWarehouseNode
? {
- aggregation_target_field: (entity as LifecycleDatawarehouseFilter).aggregation_target_field,
- created_at_field: (entity as LifecycleDatawarehouseFilter).created_at_field,
+ aggregation_target_field: entity.aggregation_target_field,
+ created_at_field: entity.created_at_field,
}
: dataWarehouseNodeKind === NodeKind.FunnelsDataWarehouseNode
? {
- id_field: (entity as FunnelDatawarehouseFilter).id_field || undefined,
- aggregation_target_field:
- (entity as FunnelDatawarehouseFilter).aggregation_target_field || undefined,
+ id_field: entity.id_field || undefined,
+ aggregation_target_field: entity.aggregation_target_field || undefined,
}
: {
- id_field: (entity as TrendsDataWarehouseFilter).id_field || undefined,
- distinct_id_field: (entity as TrendsDataWarehouseFilter).distinct_id_field || undefined,
+ id_field: entity.id_field || undefined,
+ distinct_id_field: entity.distinct_id_field || undefined,
}),
} as DataWarehouseNode | FunnelsDataWarehouseNode | LifecycleDataWarehouseNode
}
- if (isGroupFilter(entity)) {
+ if (isGroupStep(entity)) {
shared = {
...shared,
operator: entity.operator || undefined,
nodes: (entity.nestedFilters || []).map((v) =>
- legacyEntityToNode(
- v as ActionFilter | AnyDataWarehouseFilter,
- includeProperties,
- mathAvailability,
- dataWarehouseNodeKind
- )
+ legacyEntityToNode(v, includeProperties, mathAvailability, dataWarehouseNodeKind)
),
} as GroupNode
}
@@ -200,8 +207,6 @@ const NODE_IDENTITY_KEYS = ['kind', 'version', 'event', 'id', 'nodes']
/** When the picker holds more than one row, the first row of the earliest type here is the one stored. */
const TEMPLATE_STEP_TYPES = [EntityTypes.ACTIONS, EntityTypes.EVENTS, EntityTypes.DATA_WAREHOUSE, EntityTypes.GROUPS]
-type TemplateStep = TemplateVariableStep & { nestedFilters?: TemplateStep[] }
-
function omitKeys(source: Record<string, any>, keys: string[]): Record<string, any> {
return Object.fromEntries(Object.entries(source).filter(([key]) => !keys.includes(key)))
}
diff --git a/frontend/src/scenes/insights/summarizeInsight.ts b/frontend/src/scenes/insights/summarizeInsight.ts
index 6e8426c3ddd9..8fb1d00330ca 100644
--- a/frontend/src/scenes/insights/summarizeInsight.ts
+++ b/frontend/src/scenes/insights/summarizeInsight.ts
@@ -36,7 +36,7 @@ import {
import { isEventsQuery } from '~/queries/utils'
import { getCoreFilterDefinition } from '~/taxonomy/helpers'
import { CORE_FILTER_DEFINITIONS_BY_GROUP } from '~/taxonomy/taxonomy'
-import { BreakdownKeyType, BreakdownType, EntityFilter, FilterType, FunnelVizType, StepOrderValue } from '~/types'
+import { BreakdownKeyType, BreakdownType, FilterType, FunnelVizType, StepOrderValue } from '~/types'
import { summarizeJourneys } from 'products/product_analytics/frontend/insights/journeys/journeysSummary'
import { retentionOptions } from 'products/product_analytics/frontend/insights/retention/constants'
@@ -204,13 +204,11 @@ export function summarizeInsightQuery(query: InsightQueryNode, context: SummaryC
query.retentionFilter?.returningEntity?.type === query.retentionFilter?.targetEntity?.type
return (
`Retention of ${context.aggregationLabel(query.aggregation_group_type_index, true).plural}` +
- ` based on doing ${getDisplayNameFromEntityFilter(
- (query.retentionFilter?.targetEntity || {}) as EntityFilter
- )}` +
+ ` based on doing ${getDisplayNameFromEntityFilter(query.retentionFilter?.targetEntity)}` +
` ${retentionOptions[query.retentionFilter?.retentionType || RETENTION_FIRST_OCCURRENCE_MATCHING_FILTERS]} and returning with ` +
(areTargetAndReturningIdentical
? 'the same event'
- : getDisplayNameFromEntityFilter((query.retentionFilter?.returningEntity || {}) as EntityFilter))
+ : getDisplayNameFromEntityFilter(query.retentionFilter?.returningEntity))
)
} else if (isPathsQuery(query)) {
// Sync format with PathsSummary in InsightDetails
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 441b9bd4a126..040a8bdd7bc3 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -1694,62 +1694,37 @@ export enum EntityTypes {
GROUPS = 'groups',
}
-export type EntityFilter = {
- type?: EntityType
+export interface ActionFilter {
+ type: EntityType
id: string | number | null
name?: string | null
custom_name?: string | null
index?: number
order?: number
optionalInFunnel?: boolean
-}
-
-export interface ActionFilter extends EntityFilter {
math?: string
math_property?: string | null
math_property_type?: TaxonomicFilterGroupType | null
math_group_type_index?: integer | null
math_hogql?: string | null
properties?: AnyPropertyFilter[]
- type: EntityType
days?: string[] // TODO: why was this added here?
operator?: FilterLogicalOperator | null
- nestedFilters?: EntityFilter[] | null
+ nestedFilters?:
+ | {
+ type?: EntityType
+ id: string | number | null
+ name?: string | null
+ custom_name?: string | null
+ index?: number
+ order?: number
+ optionalInFunnel?: boolean
+ }[]
+ | null
/** Replay-only. When true, matches sessions that do NOT contain any event matching this entity */
negation?: boolean
}
-export const isGroupFilter = (filter: EntityFilter): filter is ActionFilter => filter.type === EntityTypes.GROUPS
-
-export type AnyDataWarehouseFilter =
- | TrendsDataWarehouseFilter
- | FunnelDatawarehouseFilter
- | LifecycleDatawarehouseFilter
-
-export interface TrendsDataWarehouseFilter extends ActionFilter {
- table_name: string
- id_field: string
- timestamp_field: string
- distinct_id_field: string
-}
-
-export interface FunnelDatawarehouseFilter extends ActionFilter {
- table_name: string
- id_field: string
- timestamp_field: string
- aggregation_target_field: string
-}
-
-export interface LifecycleDatawarehouseFilter extends ActionFilter {
- table_name: string
- timestamp_field: string
- aggregation_target_field: string
- created_at_field: string
-}
-
-export const isDataWarehouseFilter = (filter: EntityFilter): filter is AnyDataWarehouseFilter =>
- filter.type === EntityTypes.DATA_WAREHOUSE
-
export interface PersonType {
id?: string
uuid?: string
@@ -7388,7 +7363,7 @@ export type CyclotronJobMasking = {
bytecode?: any
}
-// subset of EntityFilter
+// subset of ActionFilter
export interface CyclotronJobFilterBase {
id: string
name?: string | null