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.

fix(data-management): make virtual property definition pages load instead of 404 (#71804)

Andy Zhao32c59f375757
diff --git a/frontend/src/scenes/data-management/definition/DefinitionEdit.tsx b/frontend/src/scenes/data-management/definition/DefinitionEdit.tsx
index 4f20bef6089e..16bff57f7847 100644
--- a/frontend/src/scenes/data-management/definition/DefinitionEdit.tsx
+++ b/frontend/src/scenes/data-management/definition/DefinitionEdit.tsx
@@ -26,7 +26,11 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { getPrimaryPropertyForEvent, hasTaxonomyPrimaryProperty } from 'lib/utils/events'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { definitionEditLogic } from 'scenes/data-management/definition/definitionEditLogic'
-import { DefinitionLogicProps, definitionLogic } from 'scenes/data-management/definition/definitionLogic'
+import {
+ DefinitionLogicProps,
+ decodeDefinitionId,
+ definitionLogic,
+} from 'scenes/data-management/definition/definitionLogic'
import { PropertyAccessControl } from 'scenes/data-management/definition/PropertyAccessControl'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { SceneExport } from 'scenes/sceneTypes'
@@ -46,13 +50,15 @@ import { getEventDefinitionIcon, getPropertyDefinitionIcon } from '../events/Def
export const scene: SceneExport<DefinitionLogicProps> = {
component: DefinitionEdit,
logic: definitionLogic,
- paramsToProps: ({ params: { id } }) => ({ id }),
+ paramsToProps: ({ params: { id } }) => ({ id: decodeDefinitionId(id) }),
}
-export function DefinitionEdit(props: DefinitionLogicProps): JSX.Element {
+export function DefinitionEdit(rawProps: DefinitionLogicProps): JSX.Element {
+ // The app renders scene components with raw route params, so decode the id like paramsToProps does
+ const props = { ...rawProps, id: decodeDefinitionId(rawProps.id) }
const logic = definitionEditLogic(props)
const definitionLogicInstance = definitionLogic(props)
- const { definitionLoading, definitionMissing, isProperty } = useValues(definitionLogicInstance)
+ const { definitionLoading, definitionMissing, isProperty, singular } = useValues(definitionLogicInstance)
const { editDefinition } = useValues(logic)
const { saveDefinition } = useActions(logic)
const { tags, tagsLoading } = useValues(tagsModel)
@@ -80,7 +86,7 @@ export function DefinitionEdit(props: DefinitionLogicProps): JSX.Element {
const mediaPreviewDragTarget = createRef<HTMLDivElement>()
if (definitionMissing) {
- return <NotFound object="event" />
+ return <NotFound object={singular} />
}
return (
<Form logic={definitionEditLogic} props={props} formKey="editDefinition">
diff --git a/frontend/src/scenes/data-management/definition/DefinitionView.tsx b/frontend/src/scenes/data-management/definition/DefinitionView.tsx
index 85e7223f0104..cbeb027d718c 100644
--- a/frontend/src/scenes/data-management/definition/DefinitionView.tsx
+++ b/frontend/src/scenes/data-management/definition/DefinitionView.tsx
@@ -19,7 +19,11 @@ import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { SpinnerOverlay } from 'lib/lemon-ui/Spinner/Spinner'
import { getPrimaryPropertyForEvent } from 'lib/utils/events'
-import { DefinitionLogicProps, definitionLogic } from 'scenes/data-management/definition/definitionLogic'
+import {
+ DefinitionLogicProps,
+ decodeDefinitionId,
+ definitionLogic,
+} from 'scenes/data-management/definition/definitionLogic'
import { EventDefinitionExperiments } from 'scenes/data-management/events/EventDefinitionExperiments'
import { EventDefinitionInsights } from 'scenes/data-management/events/EventDefinitionInsights'
import { EventDefinitionProperties } from 'scenes/data-management/events/EventDefinitionProperties'
@@ -35,7 +39,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'
import { defaultDataTableColumns } from '~/queries/nodes/DataTable/utils'
import { Query } from '~/queries/Query/Query'
import { NodeKind } from '~/queries/schema/schema-general'
-import { getFilterLabel } from '~/taxonomy/helpers'
+import { getCoreFilterDefinition, getFilterLabel, getVirtualPropertyDefinition } from '~/taxonomy/helpers'
import {
EventDefinition,
FilterLogicalOperator,
@@ -48,7 +52,7 @@ import { getEventDefinitionIcon, getPropertyDefinitionIcon } from '../events/Def
export const scene: SceneExport<DefinitionLogicProps> = {
component: DefinitionView,
logic: definitionLogic,
- paramsToProps: ({ params: { id } }) => ({ id }),
+ paramsToProps: ({ params: { id } }) => ({ id: decodeDefinitionId(id) }),
}
type StatusProps = {
@@ -122,7 +126,9 @@ function PrimaryPropertyDetail({ definition }: { definition: EventDefinition }):
)
}
-export function DefinitionView(props: DefinitionLogicProps): JSX.Element {
+export function DefinitionView(rawProps: DefinitionLogicProps): JSX.Element {
+ // The app renders scene components with raw route params, so decode the id like paramsToProps does
+ const props = { ...rawProps, id: decodeDefinitionId(rawProps.id) }
const logic = definitionLogic(props)
const { definition, definitionLoading, definitionMissing, singular, isEvent, isProperty, metrics, metricsLoading } =
useValues(logic)
@@ -156,17 +162,25 @@ export function DefinitionView(props: DefinitionLogicProps): JSX.Element {
}
if (definitionMissing) {
- return <NotFound object="event" />
+ return <NotFound object={singular} />
}
const definitionStatus = definition.verified ? 'verified' : definition.hidden ? 'hidden' : 'visible'
const statusProps = getStatusProps(isProperty)
+ const isVirtual = 'virtual' in definition && !!definition.virtual
+ // Resolve label and description from the same taxonomy group the definition came from, so they can't disagree
+ const virtualProperty = isVirtual ? getVirtualPropertyDefinition(definition.id) : null
+ const propertyLabelGroup = virtualProperty?.group ?? TaxonomicFilterGroupType.EventProperties
const formattedName = getFilterLabel(
definition.name,
- isEvent ? TaxonomicFilterGroupType.Events : TaxonomicFilterGroupType.EventProperties
+ isEvent ? TaxonomicFilterGroupType.Events : propertyLabelGroup
)
+ // Taxonomy descriptions can be rich (links, code), so render them directly for virtual definitions
+ const description = virtualProperty
+ ? getCoreFilterDefinition(definition.name, virtualProperty.group)?.description
+ : definition.description
return (
<SceneContent>
@@ -210,63 +224,67 @@ export function DefinitionView(props: DefinitionLogicProps): JSX.Element {
data-attr="event-definition-view-recordings"
/>
)}
- <LemonButton
- data-attr="delete-definition"
- type="secondary"
- status="danger"
- size="small"
- onClick={() =>
- LemonDialog.open({
- title: `Delete this ${singular} definition?`,
- description: (
- <>
- <p>
- <strong>
- {getFilterLabel(
- definition.name,
- isEvent
- ? TaxonomicFilterGroupType.Events
- : TaxonomicFilterGroupType.EventProperties
- )}
- </strong>{' '}
- will no longer appear in selectors. Associated data will remain in the
- database.
- </p>
- <p>
- This definition will be recreated if the ${singular} is ever seen again
- in the event stream.
- </p>
- </>
- ),
- primaryButton: {
- status: 'danger',
- children: 'Delete definition',
- onClick: () => deleteDefinition(),
- },
- secondaryButton: {
- children: 'Cancel',
- },
- width: 448,
- })
- }
- tooltip="Delete this definition. Associated data will remain."
- >
- Delete
- </LemonButton>
- <LemonButton
- data-attr="edit-definition"
- type="secondary"
- size="small"
- onClick={() => {
- if (isProperty) {
- router.actions.push(urls.propertyDefinitionEdit(definition.id))
- } else {
- router.actions.push(urls.eventDefinitionEdit(definition.id))
- }
- }}
- >
- Edit
- </LemonButton>
+ {!isVirtual && (
+ <>
+ <LemonButton
+ data-attr="delete-definition"
+ type="secondary"
+ status="danger"
+ size="small"
+ onClick={() =>
+ LemonDialog.open({
+ title: `Delete this ${singular} definition?`,
+ description: (
+ <>
+ <p>
+ <strong>
+ {getFilterLabel(
+ definition.name,
+ isEvent
+ ? TaxonomicFilterGroupType.Events
+ : TaxonomicFilterGroupType.EventProperties
+ )}
+ </strong>{' '}
+ will no longer appear in selectors. Associated data will remain
+ in the database.
+ </p>
+ <p>
+ This definition will be recreated if the {singular} is ever seen
+ again in the event stream.
+ </p>
+ </>
+ ),
+ primaryButton: {
+ status: 'danger',
+ children: 'Delete definition',
+ onClick: () => deleteDefinition(),
+ },
+ secondaryButton: {
+ children: 'Cancel',
+ },
+ width: 448,
+ })
+ }
+ tooltip="Delete this definition. Associated data will remain."
+ >
+ Delete
+ </LemonButton>
+ <LemonButton
+ data-attr="edit-definition"
+ type="secondary"
+ size="small"
+ onClick={() => {
+ if (isProperty) {
+ router.actions.push(urls.propertyDefinitionEdit(definition.id))
+ } else {
+ router.actions.push(urls.eventDefinitionEdit(definition.id))
+ }
+ }}
+ >
+ Edit
+ </LemonButton>
+ </>
+ )}
</>
}
forceBackTo={
@@ -293,9 +311,12 @@ export function DefinitionView(props: DefinitionLogicProps): JSX.Element {
)}
<h5>Description</h5>
<div className="definition-description my-2" data-attr="definition-description-view">
- {definition.description || (
- <span className="text-muted italic">Add a description for this {singular}</span>
- )}
+ {description ||
+ (isVirtual ? (
+ <span className="text-muted italic">No description</span>
+ ) : (
+ <span className="text-muted italic">Add a description for this {singular}</span>
+ ))}
</div>
{definition.tags && definition.tags.length > 0 && (
<ObjectTags
@@ -378,6 +399,19 @@ export function DefinitionView(props: DefinitionLogicProps): JSX.Element {
</div>
)}
+ {isVirtual && (
+ <div className="flex flex-col flex-1 basis-48 min-w-48">
+ <h5>Source</h5>
+ <div>
+ <LemonTag type="highlight">Virtual</LemonTag>
+ </div>
+ <p className="italic text-secondary text-xs mt-1 mb-0">
+ This property is computed at query time rather than stored, so it can't be edited or
+ deleted.
+ </p>
+ </div>
+ )}
+
{isProperty && (
<div className="flex flex-col flex-1 basis-48 min-w-48">
<h5>Property type</h5>
diff --git a/frontend/src/scenes/data-management/definition/definitionLogic.test.ts b/frontend/src/scenes/data-management/definition/definitionLogic.test.ts
index 495a483a97af..8ff7dd636216 100644
--- a/frontend/src/scenes/data-management/definition/definitionLogic.test.ts
+++ b/frontend/src/scenes/data-management/definition/definitionLogic.test.ts
@@ -1,7 +1,11 @@
import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
-import { createNewDefinition, definitionLogic } from 'scenes/data-management/definition/definitionLogic'
+import {
+ createNewDefinition,
+ decodeDefinitionId,
+ definitionLogic,
+} from 'scenes/data-management/definition/definitionLogic'
import { urls } from 'scenes/urls'
import { useMocks } from '~/mocks/jest'
@@ -65,5 +69,27 @@ describe('definitionLogic', () => {
definition: createNewDefinition(false),
})
})
+
+ it('decodes route ids without throwing on malformed percent sequences', () => {
+ expect(decodeDefinitionId('%24builtin_%24virt_bot_name')).toBe('$builtin_$virt_bot_name')
+ expect(decodeDefinitionId('100%off')).toBe('100%off')
+ expect(decodeDefinitionId(undefined)).toBeUndefined()
+ })
+
+ it('resolves virtual property definitions from the taxonomy instead of the API', async () => {
+ router.actions.push(urls.propertyDefinition('$builtin_$virt_bot_name'))
+ logic = definitionLogic({ id: '$builtin_$virt_bot_name' })
+ logic.mount()
+ await expectLogic(logic)
+ .toDispatchActions(['loadDefinition', 'loadDefinitionSuccess'])
+ .toMatchValues({
+ definition: expect.objectContaining({
+ id: '$builtin_$virt_bot_name',
+ name: '$virt_bot_name',
+ virtual: true,
+ }),
+ definitionMissing: false,
+ })
+ })
})
})
diff --git a/frontend/src/scenes/data-management/definition/definitionLogic.ts b/frontend/src/scenes/data-management/definition/definitionLogic.ts
index 82971854aacc..c43bde83761c 100644
--- a/frontend/src/scenes/data-management/definition/definitionLogic.ts
+++ b/frontend/src/scenes/data-management/definition/definitionLogic.ts
@@ -1,24 +1,19 @@
import { MakeLogicType, actions, afterMount, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
-import { router } from 'kea-router'
+import { router, urlToAction } from 'kea-router'
import api from 'lib/api'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { tryDecodeURIComponent } from 'lib/utils/url'
import { Scene } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
import { updatePropertyDefinitions } from '~/models/propertyDefinitionsModel'
-import { getFilterLabel } from '~/taxonomy/helpers'
+import { getFilterLabel, getVirtualPropertyDefinition } from '~/taxonomy/helpers'
import { Breadcrumb, Definition, EventDefinitionMetrics, ObjectMediaPreview, PropertyDefinition } from '~/types'
-import type {
- PropertyDefinitionType,
- PropertyType,
- SchemaEnforcementMode,
- UserBasicType,
- WarehousePropertyOrigin,
-} from '../../../types'
+import type { SchemaEnforcementMode, UserBasicType } from '../../../types'
import { DataManagementTab } from '../DataManagementScene'
import { eventDefinitionsTableLogic } from '../events/eventDefinitionsTableLogic'
import { propertyDefinitionsTableLogic } from '../properties/propertyDefinitionsTableLogic'
@@ -130,6 +125,7 @@ export interface definitionLogicActions {
}
loadDefinitionSuccess: (
definition:
+ | PropertyDefinition
| {
created_at?: string | undefined
default_columns?: string[] | undefined
@@ -151,34 +147,13 @@ export interface definitionLogicActions {
verified?: boolean | undefined
verified_at?: string | undefined
verified_by?: string | undefined
- }
- | {
- created_at?: string | undefined
- description?: string | undefined
- example?: string | undefined
- hidden?: boolean | undefined
- id: string
- is_action?: boolean | undefined
- is_numerical?: boolean | undefined
- is_seen_on_filtered_events?: boolean | undefined
- last_seen_at?: string | undefined
- name: string
- property_type?: PropertyType | undefined
- tags?: string[] | undefined
- type?: PropertyDefinitionType | undefined
- updated_at?: string | undefined
- updated_by?: UserBasicType | null | undefined
- verified?: boolean | undefined
- verified_at?: string | undefined
- verified_by?: string | undefined
- virtual?: boolean | undefined
- warehouse_origin?: WarehousePropertyOrigin | null | undefined
},
payload?: {
id: string
}
) => {
definition:
+ | PropertyDefinition
| {
created_at?: string | undefined
default_columns?: string[] | undefined
@@ -201,28 +176,6 @@ export interface definitionLogicActions {
verified_at?: string | undefined
verified_by?: string | undefined
}
- | {
- created_at?: string | undefined
- description?: string | undefined
- example?: string | undefined
- hidden?: boolean | undefined
- id: string
- is_action?: boolean | undefined
- is_numerical?: boolean | undefined
- is_seen_on_filtered_events?: boolean | undefined
- last_seen_at?: string | undefined
- name: string
- property_type?: PropertyType | undefined
- tags?: string[] | undefined
- type?: PropertyDefinitionType | undefined
- updated_at?: string | undefined
- updated_by?: UserBasicType | null | undefined
- verified?: boolean | undefined
- verified_at?: string | undefined
- verified_by?: string | undefined
- virtual?: boolean | undefined
- warehouse_origin?: WarehousePropertyOrigin | null | undefined
- }
payload?: {
id: string
}
@@ -319,6 +272,13 @@ export type definitionLogicType = MakeLogicType<
definitionLogicMeta
>
+// Route params arrive percent-encoded (virtual ids contain `$`); tryDecodeURIComponent keeps malformed ids
+// from throwing, letting them fall through to the API's graceful 404. Both the scenes' paramsToProps and the
+// component bodies must use this so the two definitionLogic build paths agree on one logic key.
+export function decodeDefinitionId(id: string | undefined): string | undefined {
+ return id ? tryDecodeURIComponent(id) : id
+}
+
export const definitionLogic = kea<definitionLogicType>([
path(['scenes', 'data-management', 'definition', 'definitionViewLogic']),
props({} as DefinitionLogicProps),
@@ -351,6 +311,13 @@ export const definitionLogic = kea<definitionLogicType>([
(merge ? { ...values.definition, ...definition } : definition) as Definition,
loadDefinition: async ({ id }, breakpoint) => {
let definition = { ...values.definition }
+ if (values.isProperty) {
+ // Virtual properties have no database row to fetch, so resolve them from the taxonomy
+ const virtualProperty = getVirtualPropertyDefinition(id)
+ if (virtualProperty) {
+ return virtualProperty.definition
+ }
+ }
try {
if (values.isEvent) {
// Event Definition
@@ -439,6 +406,12 @@ export const definitionLogic = kea<definitionLogicType>([
breadcrumbs: [
(s) => [s.definition, s.isEvent],
(definition: Definition, isEvent: boolean): Breadcrumb[] => {
+ // Resolve virtual definitions' label from the same taxonomy group the definition came from
+ const propertyLabelGroup =
+ ('virtual' in definition &&
+ definition.virtual &&
+ getVirtualPropertyDefinition(definition.id)?.group) ||
+ TaxonomicFilterGroupType.EventProperties
return [
{
key: Scene.DataManagement,
@@ -458,9 +431,7 @@ export const definitionLogic = kea<definitionLogicType>([
definition?.id !== 'new'
? getFilterLabel(
definition?.name,
- isEvent
- ? TaxonomicFilterGroupType.Events
- : TaxonomicFilterGroupType.EventProperties
+ isEvent ? TaxonomicFilterGroupType.Events : propertyLabelGroup
) || 'Untitled'
: 'Untitled',
iconType: isEvent ? 'event_definition' : 'property_definition',
@@ -471,6 +442,15 @@ export const definitionLogic = kea<definitionLogicType>([
}),
listeners(({ actions, values }) => ({
loadDefinitionSuccess: () => {
+ // Virtual definitions are taxonomy-defined and read-only, so bounce off the edit page
+ if (
+ 'virtual' in values.definition &&
+ values.definition.virtual &&
+ router.values.location.pathname.endsWith('/edit')
+ ) {
+ router.actions.replace(urls.propertyDefinition(values.definition.id))
+ return
+ }
if (values.isEvent && values.definition.id && values.definition.id !== 'new') {
actions.loadPreviews()
}
@@ -488,6 +468,20 @@ export const definitionLogic = kea<definitionLogicType>([
lemonToast.error('Failed to delete image')
},
})),
+ // Covers client-side navigation to the edit URL while this logic is already mounted, where
+ // loadDefinition (and therefore the loadDefinitionSuccess bounce above) does not re-fire
+ urlToAction(({ values, props }) => ({
+ [urls.propertyDefinitionEdit(':id')]: ({ id }) => {
+ if (
+ id &&
+ decodeDefinitionId(id) === props.id &&
+ 'virtual' in values.definition &&
+ values.definition.virtual
+ ) {
+ router.actions.replace(urls.propertyDefinition(values.definition.id))
+ }
+ },
+ })),
afterMount(({ actions, values, props }) => {
if (!props.id || props.id === 'new') {
actions.setDefinition(createNewDefinition(values.isEvent))
diff --git a/frontend/src/scenes/scenes.ts b/frontend/src/scenes/scenes.ts
index cbfa0fa2c601..184557af8666 100644
--- a/frontend/src/scenes/scenes.ts
+++ b/frontend/src/scenes/scenes.ts
@@ -2,6 +2,7 @@ import { combineUrl } from 'kea-router'
import { dayjs } from 'lib/dayjs'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
+import { tryDecodeURIComponent } from 'lib/utils/url'
import { getDefaultEventsSceneQuery } from 'scenes/activity/explore/defaults'
import { Params, Scene, SceneConfig, SceneExport } from 'scenes/sceneTypes'
import { urls } from 'scenes/urls'
@@ -696,7 +697,7 @@ export const redirects: Record<
'/events/actions': urls.actions(),
'/events/properties': urls.propertyDefinitions(),
- '/events/properties/:id': ({ id }) => urls.propertyDefinition(id),
+ '/events/properties/:id': ({ id }) => urls.propertyDefinition(tryDecodeURIComponent(id)),
'/events/stats': urls.eventDefinitions(),
'/events/stats/:id': ({ id }) => urls.eventDefinition(id),
// The scene lives at /feature_flags (underscore); catch the hyphenated variant so it doesn't 404
diff --git a/frontend/src/scenes/urls.test.ts b/frontend/src/scenes/urls.test.ts
index b752a2218234..1d2d4d382920 100644
--- a/frontend/src/scenes/urls.test.ts
+++ b/frontend/src/scenes/urls.test.ts
@@ -5,6 +5,16 @@ describe('urls', () => {
expect(urls.webAnalyticsRecap()).toEqual('/web/recap')
})
+ it('percent-encodes property definition ids so virtual ($builtin_*) ids survive route matching', () => {
+ expect(urls.propertyDefinition('$builtin_$virt_bot_name')).toEqual(
+ '/data-management/properties/%24builtin_%24virt_bot_name'
+ )
+ expect(urls.propertyDefinitionEdit('$builtin_$virt_bot_name')).toEqual(
+ '/data-management/properties/%24builtin_%24virt_bot_name/edit'
+ )
+ expect(urls.propertyDefinition(':id')).toEqual('/data-management/properties/:id')
+ })
+
it.each(['Postgres', 'MySQL', 'Snowflake'] as const)(
'includes direct access method when opening the new %s source wizard in direct mode',
(sourceType) => {
diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.ts
index 497d2220b154..a77f7527b362 100644
--- a/frontend/src/scenes/urls.ts
+++ b/frontend/src/scenes/urls.ts
@@ -41,8 +41,12 @@ export const urls = {
eventDefinition: (id: string | number): string => `/data-management/events/${id}`,
eventDefinitionEdit: (id: string | number): string => `/data-management/events/${id}/edit`,
propertyDefinitions: (type?: string): string => combineUrl('/data-management/properties', type ? { type } : {}).url,
- propertyDefinition: (id: string | number): string => `/data-management/properties/${id}`,
- propertyDefinitionEdit: (id: string | number): string => `/data-management/properties/${id}/edit`,
+ // Virtual property ids contain `$`, which kea-router's segment charset rejects, so encode real ids
+ // (`:param` placeholders pass through untouched for route registration)
+ propertyDefinition: (id: string | number): string =>
+ `/data-management/properties/${typeof id === 'string' && id.startsWith(':') ? id : encodeURIComponent(id)}`,
+ propertyDefinitionEdit: (id: string | number): string =>
+ `/data-management/properties/${typeof id === 'string' && id.startsWith(':') ? id : encodeURIComponent(id)}/edit`,
schemaManagement: (): string => '/data-management/schema',
dataManagementHistory: (): string => '/data-management/history',
database: (): string => '/data-management/database',
diff --git a/frontend/src/taxonomy/helpers.ts b/frontend/src/taxonomy/helpers.ts
index f46520171a30..891772b63327 100644
--- a/frontend/src/taxonomy/helpers.ts
+++ b/frontend/src/taxonomy/helpers.ts
@@ -1,7 +1,7 @@
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { surveyQuestionLabelsLogic } from 'scenes/surveys/surveyQuestionLabelsLogic'
-import { CoreFilterDefinition } from '~/types'
+import { CoreFilterDefinition, PropertyDefinition, PropertyType } from '~/types'
import { CORE_FILTER_DEFINITIONS_BY_GROUP, CoreFilterDefinitionsGroup } from './taxonomy'
@@ -119,6 +119,49 @@ export function getCoreFilterDefinition(
return null
}
+/** Prefix of the synthetic ids the property definitions API gives virtual (query-time computed) properties. */
+export const VIRTUAL_PROPERTY_DEFINITION_ID_PREFIX = '$builtin_'
+
+const VIRTUAL_PROPERTY_DEFINITION_GROUPS = [
+ TaxonomicFilterGroupType.EventProperties,
+ TaxonomicFilterGroupType.PersonProperties,
+ TaxonomicFilterGroupType.GroupsPrefix,
+]
+
+export interface VirtualPropertyDefinitionMatch {
+ definition: PropertyDefinition
+ /** The taxonomy group the definition was resolved from; use it for label/description lookups so they can't disagree. */
+ group: TaxonomicFilterGroupType
+}
+
+/** Virtual properties have no database row, so their definition is built from the taxonomy. */
+export function getVirtualPropertyDefinition(id: string): VirtualPropertyDefinitionMatch | null {
+ if (!id.startsWith(VIRTUAL_PROPERTY_DEFINITION_ID_PREFIX)) {
+ return null
+ }
+ const name = id.slice(VIRTUAL_PROPERTY_DEFINITION_ID_PREFIX.length)
+ for (const group of VIRTUAL_PROPERTY_DEFINITION_GROUPS) {
+ const coreDefinition = getCoreFilterDefinition(name, group)
+ if (coreDefinition?.virtual) {
+ return {
+ definition: {
+ id,
+ name,
+ description:
+ typeof coreDefinition.description === 'string' ? coreDefinition.description : undefined,
+ is_numerical: coreDefinition.type === PropertyType.Numeric,
+ property_type: coreDefinition.type,
+ verified: false,
+ hidden: false,
+ virtual: true,
+ },
+ group,
+ }
+ }
+ }
+ return null
+}
+
export function getFirstFilterTypeFor(propertyKey: string): TaxonomicFilterGroupType | null {
for (const type of Object.keys(CORE_FILTER_DEFINITIONS_BY_GROUP) as CoreFilterDefinitionsGroup[]) {
if (propertyKey in CORE_FILTER_DEFINITIONS_BY_GROUP[type]) {