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 switch to "All" from empty tab (#63026)

Paul D'Ambraefd6fc59a3d9
diff --git a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
index 15e5c4e5ca05..7772259eec4d 100644
--- a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
@@ -38,6 +38,7 @@ import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { pluralize } from 'lib/utils'
import { cn } from 'lib/utils/css-classes'
import { isDefinitionStale } from 'lib/utils/definitions'
+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { getCoreFilterDefinition } from '~/taxonomy/helpers'
import { EventDefinition, PropertyDefinition } from '~/types'
@@ -650,8 +651,10 @@ export const InfiniteListRow = ({
}
function InfiniteListEmptyState(): JSX.Element {
- const { searchQuery, taxonomicGroupTypes, includeStaleEvents } = useValues(taxonomicFilterLogic)
- const { setIncludeStaleEvents } = useActions(taxonomicFilterLogic)
+ const { searchQuery, taxonomicGroupTypes, includeStaleEvents, infiniteListCounts, eventNames } =
+ useValues(taxonomicFilterLogic)
+ const { setIncludeStaleEvents, setActiveTab } = useActions(taxonomicFilterLogic)
+ const { reportTaxonomicFilterCategorySelected } = useActions(eventUsageLogic)
const { group, needsMoreSearchCharacters, minSearchQueryLength, isSuggestedFilters, listGroupType } =
useValues(infiniteListLogic)
@@ -662,6 +665,15 @@ function InfiniteListEmptyState(): JSX.Element {
!emptySearchQuery &&
!includeStaleEvents &&
(listGroupType === TaxonomicFilterGroupType.Events || listGroupType === TaxonomicFilterGroupType.CustomEvents)
+
+ // When this tab has no results but the aggregated "all" (suggested filters) section does, offer a
+ // jump there so the user doesn't have to guess which tab their match lives in.
+ const allSectionHasResults = (infiniteListCounts[TaxonomicFilterGroupType.SuggestedFilters] ?? 0) > 0
+ const canOfferAllSwitch =
+ !emptySearchQuery &&
+ !isSuggestedFilters &&
+ taxonomicGroupTypes.includes(TaxonomicFilterGroupType.SuggestedFilters) &&
+ allSectionHasResults
return (
<div className="no-infinite-results flex flex-col gap-y-1 items-center">
{suggestedFiltersBeforeSearching ? (
@@ -703,6 +715,22 @@ function InfiniteListEmptyState(): JSX.Element {
Include stale events
</LemonButton>
)}
+ {canOfferAllSwitch && (
+ <LemonButton
+ type="secondary"
+ size="xsmall"
+ data-attr="taxonomic-switch-to-all"
+ onClick={() => {
+ reportTaxonomicFilterCategorySelected(
+ TaxonomicFilterGroupType.SuggestedFilters,
+ eventNames?.[0]
+ )
+ setActiveTab(TaxonomicFilterGroupType.SuggestedFilters)
+ }}
+ >
+ See results from other categories
+ </LemonButton>
+ )}
</>
)}
</div>
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
index 2863dc34ab81..043c93c86f94 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
@@ -275,6 +275,68 @@ describe('TaxonomicFilter', () => {
})
})
+ describe('no results - switch to all', () => {
+ // Every group type renders its list (active one visible, the rest hidden via CSS), so the
+ // empty-state button can appear in several hidden tabs at once. Scope queries to the visible tab.
+ const inVisibleTab = (elements: HTMLElement[]): HTMLElement | undefined =>
+ elements.find((el) => !el.closest('.hidden'))
+
+ // Land on a non-"all" group while it still has results, so a later empty search leaves us there
+ // (empty tabs aren't clickable, mirroring how a user starts on a group then searches it dry).
+ async function activateGroupWithResults(testId: string): Promise<void> {
+ await waitFor(() => {
+ expect(screen.getByTestId(testId)).not.toHaveAttribute('aria-disabled', 'true')
+ })
+ await userEvent.click(screen.getByTestId(testId))
+ }
+
+ it('offers a button to jump to the all section when another group has matches', async () => {
+ renderFilter({
+ taxonomicGroupTypes: [
+ TaxonomicFilterGroupType.SuggestedFilters,
+ TaxonomicFilterGroupType.Events,
+ TaxonomicFilterGroupType.PersonProperties,
+ ],
+ })
+
+ await activateGroupWithResults('taxonomic-tab-person_properties')
+ // Search for something that only matches events, leaving person properties empty
+ await userEvent.type(screen.getByTestId('taxonomic-filter-searchfield'), 'test event')
+
+ // The empty state offers a shortcut to the aggregated all/suggested-filters section
+ let switchButton: HTMLElement | undefined
+ await waitFor(() => {
+ switchButton = inVisibleTab(screen.getAllByTestId('taxonomic-switch-to-all'))
+ expect(switchButton).toBeTruthy()
+ })
+ expect(switchButton).toHaveTextContent(/See results from other categories/i)
+
+ await userEvent.click(switchButton!)
+
+ await waitFor(() => {
+ expectActiveTab('taxonomic-tab-suggested_filters')
+ })
+ })
+
+ it('does not offer the button when no other group has matches', async () => {
+ renderFilter({
+ taxonomicGroupTypes: [
+ TaxonomicFilterGroupType.SuggestedFilters,
+ TaxonomicFilterGroupType.Events,
+ TaxonomicFilterGroupType.PersonProperties,
+ ],
+ })
+
+ await activateGroupWithResults('taxonomic-tab-person_properties')
+ await userEvent.type(screen.getByTestId('taxonomic-filter-searchfield'), 'xyznonexistent')
+
+ await waitFor(() => {
+ expect(inVisibleTab(screen.getAllByText(/No results for/))).toBeTruthy()
+ })
+ expect(screen.queryByTestId('taxonomic-switch-to-all')).not.toBeInTheDocument()
+ })
+ })
+
describe('tab switching', () => {
it('clicking a category tab switches the visible results', async () => {
renderFilter({
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
index 65e07b6619af..c900d2eac890 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.test.tsx
@@ -732,6 +732,47 @@ describe('MenuFilterCombobox', () => {
})
})
+ it('offers a jump to All when a single category comes up empty, and clicking it switches scope', async () => {
+ const user = userEvent.setup()
+ apiGet.mockResolvedValue({ results: [], count: 0 })
+
+ renderAll({
+ groupTypes: [TaxonomicFilterGroupType.Cohorts, TaxonomicFilterGroupType.Events],
+ searchQuery: 'zzz_no_match',
+ })
+
+ // Narrow to a single category so the cross-category jump becomes relevant
+ await user.click(screen.getByRole('combobox', { name: 'Filter category' }))
+ await user.click(await screen.findByRole('option', { name: 'Cohorts' }))
+
+ const jumpButton = await screen.findByRole('button', { name: 'Check for results in other categories' })
+ await user.click(jumpButton)
+
+ expect(captureMock).toHaveBeenCalledWith(
+ 'taxonomic filter menu category changed',
+ expect.objectContaining({ toChip: 'all', via: 'empty-state' })
+ )
+ // Back on the All scope, the jump no longer applies
+ await waitFor(() => {
+ expect(screen.getByRole('combobox', { name: 'Filter category' })).toHaveTextContent('All')
+ expect(
+ screen.queryByRole('button', { name: 'Check for results in other categories' })
+ ).not.toBeInTheDocument()
+ })
+ })
+
+ it('does not offer the jump on the All scope', async () => {
+ apiGet.mockResolvedValue({ results: [], count: 0 })
+
+ renderAll({
+ groupTypes: [TaxonomicFilterGroupType.Cohorts, TaxonomicFilterGroupType.Events],
+ searchQuery: 'zzz_no_match',
+ })
+
+ await waitFor(() => expect(screen.getByTestId('menu-filter-empty')).toBeInTheDocument())
+ expect(screen.queryByRole('button', { name: 'Check for results in other categories' })).not.toBeInTheDocument()
+ })
+
describe('reveal barrier', () => {
it('hides stale results during a refetch and reveals once it settles', async () => {
const user = userEvent.setup()
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
index f9c0f5a68dda..854193da50ec 100644
--- a/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/menu/Combobox.tsx
@@ -714,6 +714,27 @@ export function MenuFilterCombobox({
})
}, [telemetryGroupType, searchQuery])
+ // Only the active scope's groups are fetched, so a narrowed-to-one-category search
+ // that comes up empty can't know whether other categories have matches. Offer a jump
+ // to "All" (which fetches every group) so the user can check without re-typing. This is a
+ // deliberate divergence from the legacy `InfiniteList` empty state, which can read the
+ // aggregated count (`allSectionHasResults`) and only offers the jump when All has matches.
+ const canOfferAllSwitch =
+ showChips &&
+ !!searchQuery.trim() &&
+ activeScope !== 'all' &&
+ activeScope !== 'recent' &&
+ activeScope !== 'pinned'
+ const handleCheckOtherCategories = useCallback((): void => {
+ posthog.capture('taxonomic filter menu category changed', {
+ fromChip: activeChip,
+ toChip: 'all',
+ via: 'empty-state',
+ })
+ setActiveChip('all')
+ inputRef.current?.focus()
+ }, [activeChip])
+
const selectionContextFor = useCallback(
(entry: MenuFilterEntry): CommitSelectionContext => {
const key = entryKey(entry)
@@ -915,6 +936,16 @@ export function MenuFilterCombobox({
Include stale events
</Button>
)}
+ {canOfferAllSwitch && !emptyState.body && (
+ <Button
+ variant="outline"
+ size="sm"
+ data-attr="menu-filter-check-other-categories"
+ onClick={handleCheckOtherCategories}
+ >
+ Check for results in other categories
+ </Button>
+ )}
</div>
)
)}