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(taxonomic-filter): offer to show a category when its name is searched (#119089)

Paul D'Ambrabf3c3987a199
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index aafdf7b8f790..fe23ea4c316e 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3636,6 +3636,10 @@ snapshots:
hash: v1.k794b7964.56b8792ce05a2bd6639b561f1330df09e67cf01fa9307301aa91560ff69442dd.mnfSSv24JeDgvtTRf6YX_-olqjQUQIzvd7GVi6CFMNU
filters-taxonomic-filter--empty-events-with-value-hint--light:
hash: v1.k794b7964.97ddd61650806011675ac41c4ca31e0409b894993096eaa1e645e5748502be1a.NtvmxNSJzpPc-osNFNOzk85H2kVtbmQKDUClTvwYPfA
+ filters-taxonomic-filter--empty-tab-searching-a-category-name--dark:
+ hash: v1.k794b7964.fd4d6a0fa9ff79e0b7835a577e9fca1b5ebaea73cbce2e8fbe22b7f81d74a430.ygr-MRffkSBDiRqiPa3uZLZ3mKodH39bbm5jzD0dOSE
+ filters-taxonomic-filter--empty-tab-searching-a-category-name--light:
+ hash: v1.k794b7964.d34e0cd92326d56e6226e99b008b31b05131c3114c9d5f5040e20e2bae15824c.h5p3ybwNBUXc4AGbV0AOfpPs1oEMypI_rV1QBg7egbc
filters-taxonomic-filter--empty-tab-with-jumps-to-other-categories--dark:
hash: v1.k794b7964.cb129e04c8d6a9e6c4603e87a645e9bb1136bb222f0fdfcf53e25b1e32983873.43FF8fvDP9re3M194WgDHHJxMQvZsCWKfVt122ELNHg
filters-taxonomic-filter--empty-tab-with-jumps-to-other-categories--light:
diff --git a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
index 7491e33c5464..d066d00de889 100644
--- a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
@@ -45,6 +45,7 @@ import {
TaxonomicFilterGroupType,
TaxonomicFilterGroupValueMap,
} from 'lib/components/TaxonomicFilter/types'
+import { groupNamedBySearch } from 'lib/components/TaxonomicFilter/utils/groupNamedBySearch'
import { hiddenEventMatchingSearch } from 'lib/components/TaxonomicFilter/utils/hiddenEvents'
import { dayjs } from 'lib/dayjs'
import { LemonRow } from 'lib/lemon-ui/LemonRow'
@@ -726,8 +727,9 @@ function InfiniteListEmptyState(): JSX.Element {
infiniteListCounts,
infiniteListResultCounts,
eventNames,
+ ownsSearchInput,
} = useValues(taxonomicFilterLogic)
- const { setIncludeStaleEvents, setActiveTab } = useActions(taxonomicFilterLogic)
+ const { setIncludeStaleEvents, setActiveTab, setSearchQuery } = useActions(taxonomicFilterLogic)
const { reportTaxonomicFilterCategorySelected } = useActions(eventUsageLogic)
const { group, needsMoreSearchCharacters, minSearchQueryLength, isSuggestedFilters, listGroupType } =
@@ -754,6 +756,11 @@ function InfiniteListEmptyState(): JSX.Element {
taxonomicGroupTypes.includes(TaxonomicFilterGroupType.SuggestedFilters) &&
allSectionHasResults
+ // A search for a category's name offers that whole category, and replaces the named jump to it below.
+ const namedGroupType =
+ emptySearchQuery || !ownsSearchInput ? null : groupNamedBySearch(searchQuery, taxonomicGroupTypes)
+ const namedGroupName = taxonomicGroups.find((g) => g.type === namedGroupType)?.name
+
// Named jumps come first because they say where the match is. The "all" jump stays as the fallback.
// Keyed off result counts (not `infiniteListCounts`/`totalListCount`) so render-backed groups like
// the SQL expression editor, whose affordance row makes `totalListCount` non-zero for any query,
@@ -763,6 +770,7 @@ function InfiniteListEmptyState(): JSX.Element {
? taxonomicGroupTypes.filter(
(groupType) =>
groupType !== listGroupType &&
+ groupType !== namedGroupType &&
!metaGroupTypes.has(groupType) &&
(infiniteListResultCounts[groupType] ?? 0) > 0
)
@@ -834,6 +842,20 @@ function InfiniteListEmptyState(): JSX.Element {
Include stale events
</LemonButton>
)}
+ {namedGroupType && namedGroupName && (
+ <LemonButton
+ type="secondary"
+ size="xsmall"
+ data-attr={`taxonomic-show-group-${namedGroupType}`}
+ onClick={() => {
+ reportTaxonomicFilterCategorySelected(namedGroupType, eventNames?.[0])
+ setSearchQuery('')
+ setActiveTab(namedGroupType)
+ }}
+ >
+ Show all {namedGroupName.toLowerCase()}
+ </LemonButton>
+ )}
{otherGroupTypesWithResults.slice(0, MAX_OTHER_GROUP_SWITCHES).map((groupType) => {
const groupName = taxonomicGroups.find((g) => g.type === groupType)?.name ?? groupType
return (
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
index d57b72638490..98b3fc1ad1b0 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
@@ -926,6 +926,46 @@ export const EmptyTabWithJumpsToOtherCategories: Story = {
},
}
+export const EmptyTabSearchingACategoryName: Story = {
+ render: (args) => {
+ useMountedLogic(actionsModel)
+ const { setSearchQuery, setActiveTab } = useActions(
+ taxonomicFilterLogic({ ...args, taxonomicFilterLogicKey: args.taxonomicFilterLogicKey as string })
+ )
+
+ useOnMountEffect(() => {
+ setSearchQuery('person')
+ setActiveTab(TaxonomicFilterGroupType.Events)
+ })
+
+ return (
+ <div className="w-fit border rounded p-2 bg-surface-primary">
+ <TaxonomicFilter {...args} />
+ </div>
+ )
+ },
+ args: {
+ taxonomicFilterLogicKey: 'empty-tab-category-name',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.PersonProperties],
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/projects/:team_id/event_definitions': [],
+ },
+ }),
+ ],
+ parameters: {
+ // Hidden tabs stay mounted and render the same button, so wait for the one on the open tab.
+ testOptions: { waitForSelector: '[data-attr="taxonomic-show-group-person_properties"] >> visible=true' },
+ docs: {
+ description: {
+ story: 'A search for a category name, such as "person", offers to show that whole category.',
+ },
+ },
+ },
+}
+
function EventMatchStoryRender({
resetMatches = false,
...args
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
index 4233fedf034b..5a52c8d19a74 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
@@ -539,6 +539,43 @@ describe('TaxonomicFilter', () => {
expect(screen.queryByTestId('taxonomic-switch-to-all')).not.toBeInTheDocument()
})
+ it('offers to show a category whose name was searched, and opens it with the search cleared', async () => {
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.PersonProperties],
+ })
+
+ await activateGroupWithResults('taxonomic-tab-events')
+ await withoutDebounceDelay((user) =>
+ user.type(screen.getByTestId('taxonomic-filter-searchfield'), 'person')
+ )
+
+ let showButton: HTMLElement | undefined
+ await waitFor(() => {
+ showButton = inVisibleTab(screen.getAllByTestId('taxonomic-show-group-person_properties'))
+ expect(showButton).toHaveTextContent('Show all person properties')
+ })
+
+ await userEvent.click(showButton!)
+
+ await waitFor(() => {
+ expectActiveTab('taxonomic-tab-person_properties')
+ })
+ expect(screen.getByTestId('taxonomic-filter-searchfield')).toHaveValue('')
+ })
+
+ it('does not offer to show a category when the host owns the search input', async () => {
+ renderFilter({
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.PersonProperties],
+ hideSearchInput: true,
+ searchQuery: 'person',
+ })
+
+ await waitFor(() => {
+ expect(inVisibleTab(screen.getAllByText(/No results for/))).toBeTruthy()
+ })
+ expect(inVisibleTab(screen.queryAllByTestId('taxonomic-show-group-person_properties'))).toBeUndefined()
+ })
+
it('does not offer a jump to a render-backed group with no real matches', async () => {
// SQL expression is render-backed: its affordance row makes totalListCount non-zero for
// any query, but it has no actual search results. It must not produce a bogus jump button.
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx
index bbbbc332115a..eba128e42d20 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.tsx
@@ -105,6 +105,7 @@ export function TaxonomicFilter({
excludedOperators,
selectingKeyOnly,
collapseUrlsToContainsRow,
+ hideSearchInput,
}
const logic = taxonomicFilterLogic(taxonomicFilterLogicProps)
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index 17965217a54f..d867e73fe2b1 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -570,6 +570,7 @@ export interface taxonomicFilterLogicValues {
}
metadataSource: AnyDataNode
mouseInteractionsEnabled: boolean
+ ownsSearchInput: boolean
propertyAllowList: TaxonomicFilterGroupValueMap | undefined
propertyFilters: {
excludedProperties: TaxonomicFilterGroupValueMap
@@ -676,6 +677,7 @@ export interface taxonomicFilterLogicMeta {
key: string
__keaTypeGenInternalSelectorTypes: {
selectedItemMeta: (arg: any) => any
+ ownsSearchInput: (arg: any) => boolean
showNumericalPropsOnly: (arg: any) => any
taxonomicFilterLogicKey: (taxonomicFilterLogicKey: string) => string
eventNames: (arg: any) => any
@@ -1003,6 +1005,11 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
})),
selectors({
selectedItemMeta: [() => [(_, props) => props.filter], (filter) => filter],
+ // A host that renders its own search input owns the query, so the picker cannot clear it.
+ ownsSearchInput: [
+ () => [(_, props) => props.hideSearchInput],
+ (hideSearchInput: boolean | undefined): boolean => !hideSearchInput,
+ ],
showNumericalPropsOnly: [
() => [(_, props) => props.showNumericalPropsOnly],
(showNumericalPropsOnly) => showNumericalPropsOnly ?? false,
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/groupNamedBySearch.test.ts b/frontend/src/lib/components/TaxonomicFilter/utils/groupNamedBySearch.test.ts
new file mode 100644
index 000000000000..3f6cb79eb33f
--- /dev/null
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/groupNamedBySearch.test.ts
@@ -0,0 +1,48 @@
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+
+import { groupNamedBySearch } from './groupNamedBySearch'
+
+describe('groupNamedBySearch', () => {
+ const propertyPicker = [
+ TaxonomicFilterGroupType.Events,
+ TaxonomicFilterGroupType.PersonProperties,
+ TaxonomicFilterGroupType.Cohorts,
+ TaxonomicFilterGroupType.EventFeatureFlags,
+ ]
+ const personPicker = [TaxonomicFilterGroupType.Persons, TaxonomicFilterGroupType.CohortsWithAllUsers]
+
+ it.each([
+ { searchQuery: 'person', offered: propertyPicker, expected: TaxonomicFilterGroupType.PersonProperties },
+ { searchQuery: ' Users ', offered: propertyPicker, expected: TaxonomicFilterGroupType.PersonProperties },
+ { searchQuery: 'EVENTS', offered: propertyPicker, expected: TaxonomicFilterGroupType.Events },
+ { searchQuery: 'feature flags', offered: propertyPicker, expected: TaxonomicFilterGroupType.EventFeatureFlags },
+ { searchQuery: 'persons', offered: personPicker, expected: TaxonomicFilterGroupType.Persons },
+ { searchQuery: 'cohort', offered: personPicker, expected: TaxonomicFilterGroupType.CohortsWithAllUsers },
+ {
+ searchQuery: 'person',
+ offered: [TaxonomicFilterGroupType.Persons, TaxonomicFilterGroupType.PersonProperties],
+ expected: TaxonomicFilterGroupType.PersonProperties,
+ },
+ {
+ searchQuery: 'cohort',
+ offered: [TaxonomicFilterGroupType.CohortsWithAllUsers, TaxonomicFilterGroupType.Cohorts],
+ expected: TaxonomicFilterGroupType.Cohorts,
+ },
+ {
+ searchQuery: 'flags',
+ offered: [TaxonomicFilterGroupType.FeatureFlags, TaxonomicFilterGroupType.EventFeatureFlags],
+ expected: TaxonomicFilterGroupType.EventFeatureFlags,
+ },
+ {
+ searchQuery: 'flag',
+ offered: [TaxonomicFilterGroupType.FeatureFlags],
+ expected: TaxonomicFilterGroupType.FeatureFlags,
+ },
+ { searchQuery: 'session', offered: propertyPicker, expected: null },
+ { searchQuery: 'person_id', offered: propertyPicker, expected: null },
+ { searchQuery: 'email', offered: propertyPicker, expected: null },
+ { searchQuery: 'constructor', offered: propertyPicker, expected: null },
+ ])('maps "$searchQuery" to $expected', ({ searchQuery, offered, expected }) => {
+ expect(groupNamedBySearch(searchQuery, offered)).toEqual(expected)
+ })
+})
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/groupNamedBySearch.ts b/frontend/src/lib/components/TaxonomicFilter/utils/groupNamedBySearch.ts
new file mode 100644
index 000000000000..db36e504e3eb
--- /dev/null
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/groupNamedBySearch.ts
@@ -0,0 +1,39 @@
+import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+
+const PERSON_GROUPS = [TaxonomicFilterGroupType.PersonProperties, TaxonomicFilterGroupType.Persons]
+const FLAG_GROUPS = [TaxonomicFilterGroupType.EventFeatureFlags, TaxonomicFilterGroupType.FeatureFlags]
+const COHORT_GROUPS = [TaxonomicFilterGroupType.Cohorts, TaxonomicFilterGroupType.CohortsWithAllUsers]
+
+// Pickers offer the same category under different group types, so each name lists them in order of preference.
+// A Map, so a search such as "constructor" never resolves to an inherited object property.
+const GROUP_TYPES_BY_TYPED_NAME = new Map<string, TaxonomicFilterGroupType[]>([
+ ['person', PERSON_GROUPS],
+ ['persons', PERSON_GROUPS],
+ ['people', PERSON_GROUPS],
+ ['user', PERSON_GROUPS],
+ ['users', PERSON_GROUPS],
+ ['event', [TaxonomicFilterGroupType.Events]],
+ ['events', [TaxonomicFilterGroupType.Events]],
+ ['cohort', COHORT_GROUPS],
+ ['cohorts', COHORT_GROUPS],
+ ['action', [TaxonomicFilterGroupType.Actions]],
+ ['actions', [TaxonomicFilterGroupType.Actions]],
+ ['session', [TaxonomicFilterGroupType.SessionProperties]],
+ ['sessions', [TaxonomicFilterGroupType.SessionProperties]],
+ ['flag', FLAG_GROUPS],
+ ['flags', FLAG_GROUPS],
+ ['feature flag', FLAG_GROUPS],
+ ['feature flags', FLAG_GROUPS],
+])
+
+/**
+ * The category a search names, when the picker offers it. The empty state calls this only after the
+ * search found nothing, so a search for a category's name is taken as a request to browse that category.
+ */
+export function groupNamedBySearch(
+ searchQuery: string,
+ taxonomicGroupTypes: TaxonomicFilterGroupType[]
+): TaxonomicFilterGroupType | null {
+ const candidates = GROUP_TYPES_BY_TYPED_NAME.get(searchQuery.trim().toLowerCase()) ?? []
+ return candidates.find((groupType) => taxonomicGroupTypes.includes(groupType)) ?? null
+}