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.

feat(insights): show group info card on group key and id filters (#63418)

Paul D'Ambra4a1c821ae86a
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.test.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.test.tsx
new file mode 100644
index 000000000000..dc6f2372f8c3
--- /dev/null
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.test.tsx
@@ -0,0 +1,56 @@
+import '@testing-library/jest-dom'
+
+import { render } from '@testing-library/react'
+import { Provider } from 'kea'
+
+import { initKeaTests } from '~/test/init'
+import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'
+
+import { PropertyFilterButton } from './PropertyFilterButton'
+
+describe('PropertyFilterButton', () => {
+ beforeEach(() => {
+ initKeaTests()
+ })
+
+ // The content span carries a native `title` only when the rich group card
+ // tooltip is NOT used; a group-identity filter suppresses it and wraps the
+ // chip in the formatted-card Tooltip instead.
+ const contentTitle = (): string | null =>
+ document.querySelector('.PropertyFilterButton-content')?.getAttribute('title') ?? null
+
+ it.each([
+ {
+ description: 'a $group_key group filter (the group identity)',
+ item: {
+ key: '$group_key',
+ type: PropertyFilterType.Group,
+ group_type_index: 0,
+ value: ['01953d33-82a2-0000-f577-8dcc2987f5ce'],
+ operator: PropertyOperator.Exact,
+ },
+ },
+ {
+ description: 'an id group filter (a group property that often holds the key)',
+ item: {
+ key: 'id',
+ type: PropertyFilterType.Group,
+ group_type_index: 0,
+ value: ['01953d33-82a2-0000-f577-8dcc2987f5ce'],
+ operator: PropertyOperator.Exact,
+ },
+ },
+ ])('suppresses the native title (uses the group card tooltip) for $description', ({ item }) => {
+ render(
+ <Provider>
+ <PropertyFilterButton item={item as AnyPropertyFilter} onClick={jest.fn()} />
+ </Provider>
+ )
+
+ expect(document.querySelector('.PropertyFilterButton-content')).toBeInTheDocument()
+ // Native title is suppressed; the formatted-card Tooltip is used instead.
+ // (The inverse — group *property* keys not triggering the card — is
+ // covered by the isGroupCardFilterKey() unit tests.)
+ expect(contentTitle()).toBeNull()
+ })
+})
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.tsx
index 79aa19eb41c0..7fcb3511bae3 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyFilterButton.tsx
@@ -12,9 +12,9 @@ import { midEllipsis } from 'lib/utils'
import { cohortsModel } from '~/models/cohortsModel'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
-import { AnyPropertyFilter, GroupPropertyFilter, GroupTypeIndex, PropertyFilterType } from '~/types'
+import { AnyPropertyFilter, GroupPropertyFilter, GroupTypeIndex } from '~/types'
-import { formatPropertyLabel, propertyFilterTypeToPropertyDefinitionType } from '../utils'
+import { formatPropertyLabel, isGroupCardFilterKey, propertyFilterTypeToPropertyDefinitionType } from '../utils'
import { GroupKeyFilterTooltip } from './GroupKeyFilterTooltip'
export interface PropertyFilterButtonProps {
@@ -61,14 +61,14 @@ export const PropertyFilterButton = React.forwardRef<HTMLElement, PropertyFilter
: item.value !== null && item.value !== undefined
? [String(item.value)]
: []
- // When a single-group `$group_key` filter resolves to a real group we
- // replace the bare "$group_key = <uuid>" tooltip with a formatted card so
- // the user can confirm they picked the right group (e.g. after pasting a
- // UUID). Restricted to a single value so hovering only ever looks up the
- // one group under the mouse — never a fan-out across an "is one of" list.
- const isGroupKeyFilter =
- item.type === PropertyFilterType.Group &&
- item.key === '$group_key' &&
+ // When a single-group filter's value resolves to a real group we replace
+ // the bare "<key> = <uuid>" tooltip with a formatted card so the user can
+ // confirm they picked the right group (e.g. after pasting a UUID). This is
+ // display only and falls back to the label when the value isn't a real
+ // group key. Restricted to a single value so hovering only ever looks up
+ // the one group under the mouse — never a fan-out across an "is one of" list.
+ const showGroupCard =
+ isGroupCardFilterKey(item.key, item.type) &&
groupTypeIndex !== null &&
groupTypeIndex !== undefined &&
groupKeys.length === 1
@@ -91,7 +91,7 @@ export const PropertyFilterButton = React.forwardRef<HTMLElement, PropertyFilter
type={ButtonComponent === 'button' ? 'button' : undefined}
>
<PropertyFilterIcon type={item.type} />
- <span className="PropertyFilterButton-content" title={isGroupKeyFilter ? undefined : label}>
+ <span className="PropertyFilterButton-content" title={showGroupCard ? undefined : label}>
{midEllipsis(label, 32)}
</span>
{closable && !disabledReason && (
@@ -115,7 +115,7 @@ export const PropertyFilterButton = React.forwardRef<HTMLElement, PropertyFilter
return <Tooltip title={disabledReason}>{button}</Tooltip>
}
- if (isGroupKeyFilter) {
+ if (showGroupCard) {
return (
<Tooltip
interactive
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
index 864f589b22bb..c5ea1107726e 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.test.tsx
@@ -7,7 +7,7 @@ import { Provider } from 'kea'
import { useMocks } from '~/mocks/jest'
import { propertyDefinitionsModel } from '~/models/propertyDefinitionsModel'
import { initKeaTests } from '~/test/init'
-import { PropertyFilterType, PropertyOperator, PropertyType } from '~/types'
+import { GroupTypeIndex, PropertyFilterType, PropertyOperator, PropertyType } from '~/types'
import { PropertyValue } from './PropertyValue'
@@ -221,4 +221,27 @@ describe('PropertyValue', () => {
expect(input).toHaveValue('7.8')
})
+
+ it('renders a group `id` filter with the generic value editor, not the group-name picker', () => {
+ // Reverting the editor swap for `id` is the regression fix: a group property
+ // named `id` must keep its normal value input (GroupKeySelect, used only for
+ // the true `$group_key` identity, would replace it with a group search).
+ render(
+ <Provider>
+ <PropertyValue
+ propertyKey="id"
+ type={PropertyFilterType.Group}
+ groupTypeIndex={0 as GroupTypeIndex}
+ operator={PropertyOperator.Exact}
+ onSet={jest.fn()}
+ value={['org-abc-123']}
+ />
+ </Provider>
+ )
+
+ // GroupKeySelect's distinctive placeholder is absent — the generic editor is used.
+ expect(screen.queryByPlaceholderText('Search groups by name...')).not.toBeInTheDocument()
+ // The pasted id is shown as the value.
+ expect(screen.getByText('org-abc-123')).toBeInTheDocument()
+ })
})
diff --git a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
index 46e30543c47d..45af4ac9b723 100644
--- a/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/PropertyValue.tsx
@@ -14,11 +14,12 @@ import { AssigneeSelect } from '@posthog/products-error-tracking/frontend/compon
import { DateFilter } from 'lib/components/DateFilter/DateFilter'
import { DurationPicker } from 'lib/components/DurationPicker/DurationPicker'
import { DistinctIdSelect } from 'lib/components/PropertyFilters/components/DistinctIdSelect'
+import { GroupKeyFilterTooltip } from 'lib/components/PropertyFilters/components/GroupKeyFilterTooltip'
import { GroupKeySelect } from 'lib/components/PropertyFilters/components/GroupKeySelect'
import { PropertyFilterBetween } from 'lib/components/PropertyFilters/components/PropertyFilterBetween'
import { PropertyFilterDatePicker } from 'lib/components/PropertyFilters/components/PropertyFilterDatePicker'
import { propertyValueLogic } from 'lib/components/PropertyFilters/components/propertyValueLogic'
-import { propertyFilterTypeToPropertyDefinitionType } from 'lib/components/PropertyFilters/utils'
+import { isGroupCardFilterKey, propertyFilterTypeToPropertyDefinitionType } from 'lib/components/PropertyFilters/utils'
import { dayjs } from 'lib/dayjs'
import { IconErrorOutline } from 'lib/lemon-ui/icons'
import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'
@@ -108,6 +109,20 @@ export function PropertyValue({
const isGroupKeyProperty = propertyKey === '$group_key' && groupTypeIndex != null
const isDistinctIdProperty = propertyKey === 'distinct_id' && type === PropertyFilterType.Person
+ // A group property like `id` often holds the group key. We don't swap the
+ // value editor (that would break filtering the property by an arbitrary
+ // value), but we do decorate the value with a read-only group-info card so
+ // the user can confirm a pasted id resolves to the right group. Display only
+ // — it falls back to the plain value when the lookup isn't a real group key.
+ const showGroupCardOnValue = isGroupCardFilterKey(propertyKey, type) && groupTypeIndex != null
+ const groupCardTooltip = (groupKey: string): JSX.Element => (
+ <GroupKeyFilterTooltip
+ groupTypeIndex={groupTypeIndex as GroupTypeIndex}
+ groupKey={groupKey}
+ fallbackLabel={groupKey}
+ />
+ )
+
// TODO: Add semver input validation when a semver operator is selected.
// This will require detecting isOperatorSemver(operator) and validating the input
// matches semver format (e.g., "1.2.3", "1.2.3-alpha", etc.)
@@ -473,24 +488,34 @@ export function PropertyValue({
status={validationError ? 'danger' : 'default'}
title={titleNode}
popoverClassName="max-w-200"
- options={displayOptions.map(({ name: _name }, index) => {
- const name = toString(_name)
- return {
- key: name,
- label: name,
- value: isFlagDependencyProperty ? _name : undefined, // Preserve original type for flags
- labelComponent: (
- <span
- key={name}
- data-attr={'prop-val-' + index}
- className="ph-no-capture flex items-center gap-1.5"
- title={name}
- >
- {formatLabelContent(isFlagDependencyProperty ? _name : name)}
- </span>
- ),
- }
- })}
+ options={[
+ ...displayOptions.map(({ name: _name }, index) => {
+ const name = toString(_name)
+ return {
+ key: name,
+ label: name,
+ value: isFlagDependencyProperty ? _name : undefined, // Preserve original type for flags
+ tooltip: showGroupCardOnValue ? groupCardTooltip(name) : undefined,
+ labelComponent: (
+ <span
+ key={name}
+ data-attr={'prop-val-' + index}
+ className="ph-no-capture flex items-center gap-1.5"
+ title={name}
+ >
+ {formatLabelContent(isFlagDependencyProperty ? _name : name)}
+ </span>
+ ),
+ }
+ }),
+ // A pasted group id is a custom value absent from the suggestions, so add
+ // an option for each selected value to carry the group-card tooltip on its snack.
+ ...(showGroupCardOnValue
+ ? formattedValues
+ .filter((v) => !displayOptions.some((o) => toString(o.name) === v))
+ .map((v) => ({ key: v, label: v, tooltip: groupCardTooltip(v) }))
+ : []),
+ ]}
/>
{showInlineValidationErrors && validationError && (
<div className="text-danger flex items-center gap-1 text-sm mt-1">
diff --git a/frontend/src/lib/components/PropertyFilters/utils.test.ts b/frontend/src/lib/components/PropertyFilters/utils.test.ts
index 9dcca1ebb7bc..346510b36844 100644
--- a/frontend/src/lib/components/PropertyFilters/utils.test.ts
+++ b/frontend/src/lib/components/PropertyFilters/utils.test.ts
@@ -3,6 +3,7 @@ import {
convertPropertiesToPropertyGroup,
convertPropertyGroupToProperties,
createDefaultPropertyFilter,
+ isGroupCardFilterKey,
isValidPropertyFilter,
normalizePropertyFilterValue,
propertyFilterTypeToTaxonomicFilterType,
@@ -24,6 +25,23 @@ import {
} from '../../../types'
import { TaxonomicFilterGroup, TaxonomicFilterGroupType } from '../TaxonomicFilter/types'
+describe('isGroupCardFilterKey()', () => {
+ it.each([
+ { key: '$group_key', type: PropertyFilterType.Group, expected: true },
+ { key: 'id', type: PropertyFilterType.Group, expected: true },
+ // 'id' is also the Cohort key — must not match there.
+ { key: 'id', type: PropertyFilterType.Cohort, expected: false },
+ // Group *property* filters use other keys.
+ { key: 'industry', type: PropertyFilterType.Group, expected: false },
+ // '$group_key' only makes sense for a Group-type filter.
+ { key: '$group_key', type: PropertyFilterType.Event, expected: false },
+ { key: '$group_key', type: undefined, expected: false },
+ { key: undefined, type: PropertyFilterType.Group, expected: false },
+ ])('returns $expected for key=$key type=$type', ({ key, type, expected }) => {
+ expect(isGroupCardFilterKey(key, type)).toBe(expected)
+ })
+})
+
describe('isValidPropertyFilter()', () => {
it('returns values correctly', () => {
const emptyProperty: AnyPropertyFilter = {} as EmptyPropertyFilter
diff --git a/frontend/src/lib/components/PropertyFilters/utils.ts b/frontend/src/lib/components/PropertyFilters/utils.ts
index d0589f64ce54..80e34fd3c560 100644
--- a/frontend/src/lib/components/PropertyFilters/utils.ts
+++ b/frontend/src/lib/components/PropertyFilters/utils.ts
@@ -227,6 +227,18 @@ export function isValidPropertyFilter(
export function isCohortPropertyFilter(filter?: AnyFilterLike | null): filter is CohortPropertyFilter {
return filter?.type === PropertyFilterType.Cohort
}
+
+// Filter keys whose value we offer a read-only group-info card for on hover.
+// '$group_key' is the group's true identity (always a group key). 'id' is a
+// group *property* that conventionally holds the group key (e.g. CRM-imported
+// groups), so a card is a useful confirmation there too — but it is display
+// only: the lookup falls back to the plain label when the value isn't a real
+// group key, and we deliberately do NOT swap the value editor for these (only
+// the true '$group_key' identity gets the group picker). 'id' is also the
+// Cohort key, so the Group type gate matters.
+export function isGroupCardFilterKey(key: string | number | undefined, type: PropertyFilterType | undefined): boolean {
+ return type === PropertyFilterType.Group && (key === '$group_key' || key === 'id')
+}
export function isEventMetadataPropertyFilter(filter?: AnyFilterLike | null): filter is EventMetadataPropertyFilter {
return filter?.type === PropertyFilterType.EventMetadata
}