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(taxonomic-filter): show failed searches without old results (#105940)

Paul D'Ambra75a9cb6ff928
diff --git a/docs/internal/taxonomic-filter-search.md b/docs/internal/taxonomic-filter-search.md
index e27cd2623238..4e01e80fc866 100644
--- a/docs/internal/taxonomic-filter-search.md
+++ b/docs/internal/taxonomic-filter-search.md
@@ -7,6 +7,8 @@ The classic picker shows its active category in the search input. A person can d
The rail starts undocked. `taxonomic filter category rail toggled` records whether it is docked. `taxonomic filter closed` records the final `categoryRailDocked` state so reports can show which people keep the rail docked.
A category shows results for the current query only. It clears its earlier rows when the current query cannot fetch, such as a query below the category minimum length or a request that failed.
+In the classic picker, a failed search with no usable matches shows an error and a retry action.
+A failed search does not offer an uncaptured event name, and it does not change the selected form value.
Scoped property searches return properties associated with the selected events. A separate unscoped request counts matches across the project so the picker can offer an expansion to other properties.
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
index a561419b3134..b6af6dc89366 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
@@ -1,7 +1,7 @@
import { MOCK_TEAM_ID } from 'lib/api.mock'
import { Meta, StoryObj } from '@storybook/react'
-import { useActions, useMountedLogic } from 'kea'
+import { useActions, useMountedLogic, useValues } from 'kea'
import { delay } from 'msw'
import { useEffect } from 'react'
@@ -684,7 +684,18 @@ export const FailedFetchOffersRetry: Story = {
taxonomicFilterLogic({ ...args, taxonomicFilterLogicKey: args.taxonomicFilterLogicKey as string })
)
- useOnMountEffect(() => setSearchQuery('user_signed_up'))
+ const { remoteItems } = useValues(
+ infiniteListLogic({
+ ...args,
+ taxonomicFilterLogicKey: args.taxonomicFilterLogicKey as string,
+ listGroupType: TaxonomicFilterGroupType.Events,
+ })
+ )
+ useEffect(() => {
+ if (remoteItems.searchQuery === '' && remoteItems.results.length > 0) {
+ setSearchQuery('user_signed_up')
+ }
+ }, [remoteItems, setSearchQuery])
return (
<div className="w-fit border rounded p-2 bg-surface-primary">
@@ -695,11 +706,17 @@ export const FailedFetchOffersRetry: Story = {
args: {
taxonomicFilterLogicKey: 'events-failed-fetch',
taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
+ groupType: TaxonomicFilterGroupType.Events,
+ value: 'page_opened',
+ allowNonCapturedEvents: true,
},
decorators: [
mswDecorator({
get: {
- '/api/projects/:team_id/event_definitions': () => [500, { detail: 'server error' }],
+ '/api/projects/:team_id/event_definitions': ({ request }) =>
+ new URL(request.url).searchParams.get('search')
+ ? [500, { detail: 'server error' }]
+ : [200, { results: [{ name: 'page_opened', id: 'uuid-2' }], count: 1 }],
},
}),
],
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
index ea196da37ef2..23fa9283c289 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.test.ts
@@ -886,11 +886,14 @@ describe('infiniteListLogic', () => {
}
})
- it('clears the error state when a retry succeeds', async () => {
+ it.each([null, 'page_opened'])('clears the error state on retry after selecting %p', async (selectedEvent) => {
let attempts = 0
useMocks({
get: {
- '/api/projects/:team/event_definitions': () => {
+ '/api/projects/:team/event_definitions': ({ request }) => {
+ if (!new URL(request.url).searchParams.get('search')) {
+ return [200, { results: [{ name: 'page_opened', id: 'uuid-2' }], count: 1 }]
+ }
attempts += 1
return attempts === 1
? [500, { detail: 'server error' }]
@@ -904,23 +907,41 @@ describe('infiniteListLogic', () => {
listGroupType: TaxonomicFilterGroupType.Events,
taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
showNumericalPropsOnly: false,
+ allowNonCapturedEvents: true,
+ groupType: TaxonomicFilterGroupType.Events,
+ value: selectedEvent,
})
retryingLogic.mount()
+ if (selectedEvent) {
+ await expectLogic(retryingLogic).toDispatchActions(['loadRemoteItemsSuccess']).toFinishAllListeners()
+ expect(retryingLogic.values.results).toEqual(
+ expect.arrayContaining([expect.objectContaining({ name: selectedEvent })])
+ )
+ }
await expectLogic(retryingLogic, () => {
retryingLogic.actions.setSearchQuery('user_signed_up')
})
.toDispatchActions(['loadRemoteItemsFailure'])
.toFinishAllListeners()
- .toMatchValues({ showErrorState: true })
+ .toMatchValues({
+ showErrorState: true,
+ showEmptyState: false,
+ showNonCapturedEventOption: false,
+ results: [],
+ value: selectedEvent,
+ })
await expectLogic(retryingLogic, () => {
retryingLogic.actions.retryRemoteItems()
+ expect(retryingLogic.values.results).toEqual([])
+ expect(retryingLogic.values.showNonCapturedEventOption).toBe(false)
})
.toDispatchActions(['retryRemoteItems', 'loadRemoteItems', 'loadRemoteItemsSuccess'])
.toFinishAllListeners()
.toMatchValues({
showErrorState: false,
showEmptyState: false,
+ value: selectedEvent,
})
expect(retryingLogic.values.totalResultCount).toBeGreaterThan(0)
})
@@ -1374,6 +1395,38 @@ describe('infiniteListLogic', () => {
logic.mount()
})
+ it('shows a scoped search failure even when the full count succeeds', async () => {
+ useMocks({
+ get: {
+ '/api/projects/:team/property_definitions': ({ request }) => {
+ const url = new URL(request.url)
+ if (url.searchParams.get('search') === 'device') {
+ return url.searchParams.has('filter_by_event_names')
+ ? [500, { detail: 'server error' }]
+ : [200, { results: [{ name: '$device_type' }], count: 9 }]
+ }
+ return [200, { results: [{ name: '$browser' }], count: 1 }]
+ },
+ },
+ })
+ await expectLogic(logic).toDispatchActions(['loadRemoteItemsSuccess']).toFinishAllListeners()
+ silenceKeaLoadersErrors()
+ try {
+ await expectLogic(logic, () => logic.actions.setSearchQuery('device'))
+ .toDispatchActions(['loadRemoteItemsFailure'])
+ .toFinishAllListeners()
+ .toMatchValues({
+ expandedCount: 9,
+ isExpandable: false,
+ results: [],
+ showErrorState: true,
+ showEmptyState: false,
+ })
+ } finally {
+ resumeKeaLoadersErrors()
+ }
+ })
+
it.each([200, 500])('reveals scoped results before the full count returns %s', async (status) => {
let resolveCount!: (response: [number, { count: number; results: { name: string }[] }]) => void
useMocks({
diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
index 7958e4dd6a04..ae4a436d45ad 100644
--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts
@@ -352,6 +352,7 @@ export interface infiniteListLogicValues {
totalListCount: number
totalResultCount: number
trimmedSearchQuery: string
+ usableRemoteItems: ListStorage
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -606,10 +607,13 @@ export interface infiniteListLogicMeta {
remoteEndpoint: string | null,
scopedRemoteEndpoint: string | null,
remoteItems: ListStorage,
- expandedCount: number
+ expandedCount: number,
+ searchQuery: string,
+ remoteFetchFailed: string | null
) => boolean
isExpandableButtonSelected: (isExpandable: boolean, index: number, totalListCount: number) => boolean
hasRemoteDataSource: (remoteEndpoint: string | null) => boolean
+ usableRemoteItems: (remoteItems: ListStorage, searchQuery: string) => ListStorage
remoteResultsAreFresh: (
hasRemoteDataSource: boolean,
remoteItems: ListStorage,
@@ -622,7 +626,8 @@ export interface infiniteListLogicMeta {
searchQuery: string,
isLoading: boolean,
results: QuickFilterItem[] | (SkeletonItem | TaxonomicDefinitionTypes)[],
- excludedProperties: string[] | undefined
+ excludedProperties: string[] | undefined,
+ remoteFetchFailed: string | null
) => boolean
suggestedFiltersSettling: (
isSuggestedFilters: boolean,
@@ -717,7 +722,7 @@ export interface infiniteListLogicMeta {
value: TaxonomicFilterValue | undefined
}
items: (
- remoteItems: ListStorage,
+ usableRemoteItems: ListStorage,
localItems: ListStorage,
listGroupType: TaxonomicFilterGroupType,
dedupedTopMatches: (SkeletonItem | TaxonomicDefinitionTypes)[],
@@ -1295,13 +1300,29 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
],
hasRenderFunction: [(s) => [s.group], (group: TaxonomicFilterGroup | undefined) => !!group?.render],
isExpandable: [
- (s) => [s.remoteEndpoint, s.scopedRemoteEndpoint, s.remoteItems, s.expandedCount],
+ (s) => [
+ s.remoteEndpoint,
+ s.scopedRemoteEndpoint,
+ s.remoteItems,
+ s.expandedCount,
+ s.searchQuery,
+ s.remoteFetchFailed,
+ ],
(
remoteEndpoint: string | null,
scopedRemoteEndpoint: string | null,
remoteItems: ListStorage,
- expandedCount: number
- ) => !!(remoteEndpoint && scopedRemoteEndpoint && expandedCount > remoteItems.count),
+ expandedCount: number,
+ searchQuery: string,
+ remoteFetchFailed: string | null
+ ): boolean =>
+ !!(
+ remoteEndpoint &&
+ scopedRemoteEndpoint &&
+ remoteItems.searchQuery === searchQuery &&
+ remoteFetchFailed !== searchQuery &&
+ expandedCount > remoteItems.count
+ ),
],
isExpandableButtonSelected: [
(s) => [s.isExpandable, s.index, s.totalListCount],
@@ -1309,6 +1330,11 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
isExpandable && index === totalListCount - 1,
],
hasRemoteDataSource: [(s) => [s.remoteEndpoint], (remoteEndpoint: string | null) => !!remoteEndpoint],
+ usableRemoteItems: [
+ (s) => [s.remoteItems, s.searchQuery],
+ (remoteItems: ListStorage, searchQuery: string): ListStorage =>
+ remoteItems.searchQuery === searchQuery ? remoteItems : createEmptyListStorage(searchQuery),
+ ],
remoteResultsAreFresh: [
(s) => [s.hasRemoteDataSource, s.remoteItems, s.searchQuery, s.remoteFetchFailed],
(
@@ -1335,6 +1361,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
s.isLoading,
s.results,
s.excludedProperties,
+ s.remoteFetchFailed,
],
(
allowNonCapturedEvents: boolean,
@@ -1342,7 +1369,8 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
searchQuery: string,
isLoading: boolean,
results: TaxonomicDefinitionTypes[],
- excludedProperties: string[] | undefined
+ excludedProperties: string[] | undefined,
+ remoteFetchFailed: string | null
): boolean => {
if (!allowNonCapturedEvents) {
return false
@@ -1354,7 +1382,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
return false
}
const trimmedSearch = searchQuery.trim()
- if (trimmedSearch.length === 0 || isLoading) {
+ if (trimmedSearch.length === 0 || isLoading || remoteFetchFailed === searchQuery) {
return false
}
// Offering an excluded name would let it be selected as a non-captured event,
@@ -1764,7 +1792,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([
],
items: [
(s) => [
- s.remoteItems,
+ s.usableRemoteItems,
s.localItems,
s.listGroupType,
s.dedupedTopMatches,