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): suggest events on the All tab and show a loading state (#107437)

Paul D'Ambra4f3e954978ed
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6551f03d0d49..c74188556143 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -3176,10 +3176,18 @@ snapshots:
hash: v1.k794b7964.08dd6b6ff90babc94016f15cece4f87ac9c733101503ab4d206bef311938de6b.11OskmuMksbFPIaDtmt8ptXswFKCZQsgje5sHpyWAXw
filters-taxonomic-filter--dashboard-property-search--light:
hash: v1.k794b7964.a31bf51a80fdca614f2f36470aa051fd7faaf638ab84f332e7de43c944763c27.CznVxf4UBAP6trCkcSE7LgkjTJ3IazUfzMIhS8XBUMM
+ filters-taxonomic-filter--empty-all-tab-with-event-match--dark:
+ hash: v1.k794b7964.58e7c99b2c92f0300216c4047c2d5ea1745dfa1a606a00270b0ebc779bed3cd5.1h_7F-InpV4zcCU2i8sGo8D9GpR-M9SK0ykFwUh1DDc
+ filters-taxonomic-filter--empty-all-tab-with-event-match--light:
+ hash: v1.k794b7964.d6233206def8eefa24c433869ed21a94e9aecb397191a29c9e61295e161c594e.Ov1Fg1yGqOdhCRLXbyljE-x8teQSz_x7DBTcCiPAfXw
filters-taxonomic-filter--empty-events-with-event-match--dark:
hash: v1.k794b7964.30d20341622aff37c27fca8216269d839cc72aafd5a9cfb3a195cdde5ba414ed.ioGVHMVBgkAMr11FVdKj-pgx05LSlkwl-vuXRF-t6sw
filters-taxonomic-filter--empty-events-with-event-match--light:
hash: v1.k794b7964.d07e5394b85d6064eb2e0e92a43e138b71b4248a015af59d6a901874a6c0acca.ViBqvpCMYJ44bOijsqT7TfxMKsAFBtBUnHmRT17SQG4
+ filters-taxonomic-filter--empty-events-with-event-match-loading--dark:
+ hash: v1.k794b7964.24731467b4e99a1205df0640091c2f333b1d276df97c510a3929bf9cf342c0ee.Nd_kUIeGDDTduX8hJoZx_QCHBEqzBTKHvWdTCVQvv3g
+ filters-taxonomic-filter--empty-events-with-event-match-loading--light:
+ hash: v1.k794b7964.b3739c41d624c8631591ea6d5c9b0e1035031597bc57c0cf0cc3d90271a9afa7.TAZSeJKZZHZ8UxY3u9yNqOWKF0uYgjX74V6AnP6zqTE
filters-taxonomic-filter--empty-events-with-stale-toggle--dark:
hash: v1.k794b7964.c9c8b86f1f196faf8bb7ff2fa3a8b662b5da749e9d740979253eefd3caef6d83.Vi2aZn3Sv-3nBjiCPo9tkuX4Dj5bZSq-4KMFkSMAKps
filters-taxonomic-filter--empty-events-with-stale-toggle--light:
diff --git a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
index fcbd8dfa54a7..90c4b1cec810 100644
--- a/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/InfiniteList.tsx
@@ -702,6 +702,7 @@ const MAX_OTHER_GROUP_SWITCHES = 3
function InfiniteListEmptyState(): JSX.Element {
const {
searchQuery,
+ activeTab,
taxonomicGroups,
taxonomicGroupTypes,
metaGroupTypes,
@@ -722,6 +723,11 @@ function InfiniteListEmptyState(): JSX.Element {
!emptySearchQuery &&
!includeStaleEvents &&
(listGroupType === TaxonomicFilterGroupType.Events || listGroupType === TaxonomicFilterGroupType.CustomEvents)
+ // Inactive tabs stay mounted but hidden, so only the open tab's empty state may ask for suggestions.
+ const canOfferEventMatch =
+ !emptySearchQuery &&
+ listGroupType === activeTab &&
+ (listGroupType === TaxonomicFilterGroupType.Events || isSuggestedFilters)
// 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.
@@ -800,9 +806,7 @@ function InfiniteListEmptyState(): JSX.Element {
</>
)}
</span>
- {!emptySearchQuery && listGroupType === TaxonomicFilterGroupType.Events && (
- <TaxonomicEventMatchSuggestions />
- )}
+ {canOfferEventMatch && <TaxonomicEventMatchSuggestions />}
{canOfferStaleToggle && (
<LemonButton
type="secondary"
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx
index 63d46bf9ba0a..f9e13e9b112b 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicEventMatchSuggestions.tsx
@@ -2,15 +2,26 @@ import { useActions, useMountedLogic, useValues } from 'kea'
import { LemonButton } from '@posthog/lemon-ui'
+import { Spinner } from 'lib/lemon-ui/Spinner'
+
import { infiniteListLogic } from './infiniteListLogic'
import { taxonomicEventMatchLogic } from './taxonomicEventMatchLogic'
export function TaxonomicEventMatchSuggestions(): JSX.Element | null {
const { props } = useMountedLogic(infiniteListLogic)
const logic = taxonomicEventMatchLogic(props)
- const { suggestedEvents } = useValues(logic)
+ const { suggestedEvents, isMatching } = useValues(logic)
const { selectEventMatch } = useActions(logic)
+ if (isMatching) {
+ return (
+ <div className="flex items-center gap-1 text-secondary" data-attr="taxonomic-event-match-loading">
+ <Spinner className="text-sm" />
+ <span>Looking for events you might mean</span>
+ </div>
+ )
+ }
+
if (suggestedEvents.length === 0) {
return null
}
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
index f3e860966646..c5de435dcc75 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.stories.tsx
@@ -18,6 +18,7 @@ import { type AnyPropertyFilter, AvailableFeature, EntityTypes, PropertyFilterTy
import { infiniteListLogic } from './infiniteListLogic'
import { recentTaxonomicFiltersLogic } from './recentTaxonomicFiltersLogic'
+import { resetEventMatchMemoryForTests } from './taxonomicEventMatchLogic'
import { TaxonomicFilter } from './TaxonomicFilter'
import { taxonomicFilterCategoryLayoutLogic } from './taxonomicFilterCategoryLayoutLogic'
import { taxonomicFilterLogic } from './taxonomicFilterLogic'
@@ -846,47 +847,102 @@ export const EmptyEventsWithStaleToggle: Story = {
},
}
-/** A search that matches no event name gets core events the decision model thinks it describes. */
-export const EmptyEventsWithEventMatch: Story = {
- render: (args) => {
- useMountedLogic(actionsModel)
- const { setSearchQuery } = useActions(
- taxonomicFilterLogic({ ...args, taxonomicFilterLogicKey: args.taxonomicFilterLogicKey as string })
- )
+function EventMatchStoryRender({
+ resetMatches = false,
+ ...args
+}: TaxonomicFilterProps & { resetMatches?: boolean }): JSX.Element {
+ useMountedLogic(actionsModel)
+ const { setSearchQuery } = useActions(
+ taxonomicFilterLogic({ ...args, taxonomicFilterLogicKey: args.taxonomicFilterLogicKey as string })
+ )
- useOnMountEffect(() => setSearchQuery('browser capture'))
+ useOnMountEffect(() => {
+ if (resetMatches) {
+ resetEventMatchMemoryForTests()
+ }
+ setSearchQuery('browser capture')
+ })
- return (
- <div className="w-fit border rounded p-2 bg-surface-primary">
- <TaxonomicFilter {...args} />
- </div>
- )
+ return (
+ <div className="w-fit border rounded p-2 bg-surface-primary">
+ <TaxonomicFilter {...args} />
+ </div>
+ )
+}
+
+// No event name matches "browser capture", and the decision model answers with two core events.
+const eventMatchAutocaptureMock = mswDecorator({
+ get: {
+ '/api/projects/:team_id/event_definitions': [],
+ },
+ post: {
+ '/api/projects/:team_id/taxonomic_search_intent/match_events/': () => [
+ 200,
+ {
+ matches: [
+ { name: '$autocapture', display_name: 'Autocapture', probability: 0.95 },
+ { name: '$rageclick', display_name: 'Rageclick', probability: 0.74 },
+ ],
+ },
+ ],
},
+})
+
+/** A search that matches no event name gets core events the decision model thinks it describes. */
+export const EmptyEventsWithEventMatch: Story = {
+ render: EventMatchStoryRender,
args: {
taxonomicFilterLogicKey: 'events-event-match',
taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
},
+ decorators: [eventMatchAutocaptureMock],
+ parameters: {
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: true },
+ testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-suggestion"]' },
+ },
+}
+
+/** The "All" tab gets the same suggestions when no group has a result. */
+export const EmptyAllTabWithEventMatch: Story = {
+ render: EventMatchStoryRender,
+ args: {
+ taxonomicFilterLogicKey: 'all-event-match',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions],
+ },
+ decorators: [eventMatchAutocaptureMock],
+ parameters: {
+ featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: true },
+ testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-suggestion"]' },
+ },
+}
+
+/** While the decision model is still answering, the empty state says so. */
+export const EmptyEventsWithEventMatchLoading: Story = {
+ render: (args) => <EventMatchStoryRender {...args} resetMatches />,
+ args: {
+ taxonomicFilterLogicKey: 'events-event-match-loading',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
+ },
decorators: [
mswDecorator({
get: {
'/api/projects/:team_id/event_definitions': [],
},
post: {
- '/api/projects/:team_id/taxonomic_search_intent/match_events/': () => [
- 200,
- {
- matches: [
- { name: '$autocapture', display_name: 'Autocapture', probability: 0.95 },
- { name: '$rageclick', display_name: 'Rageclick', probability: 0.74 },
- ],
- },
- ],
+ '/api/projects/:team_id/taxonomic_search_intent/match_events/': async () => {
+ await delay('infinite')
+ return [200, { matches: [] }]
+ },
},
}),
],
parameters: {
featureFlags: { [FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]: true },
- testOptions: { waitForSelector: '[data-attr="taxonomic-event-match-suggestion"]' },
+ // The spinner is the point of this story, so the runner must not wait for it to disappear.
+ testOptions: {
+ waitForSelector: '[data-attr="taxonomic-event-match-loading"]',
+ waitForLoadersToDisappear: false,
+ },
},
}
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts
index 4c6474629f4c..3a87e7204839 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.test.ts
@@ -1,5 +1,6 @@
import { MOCK_TEAM_ID } from 'lib/api.mock'
+import { waitFor } from '@testing-library/react'
import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
@@ -10,7 +11,7 @@ import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { AppContext } from '~/types'
-import { resetEventMatchAvailabilityForTests, taxonomicEventMatchLogic } from './taxonomicEventMatchLogic'
+import { resetEventMatchMemoryForTests, taxonomicEventMatchLogic } from './taxonomicEventMatchLogic'
import { taxonomicFilterLogic } from './taxonomicFilterLogic'
import { TaxonomicFilterGroupType, TaxonomicFilterLogicProps } from './types'
@@ -24,6 +25,12 @@ const PROPS: TaxonomicFilterLogicProps = {
taxonomicGroupTypes: [TaxonomicFilterGroupType.Events],
}
+// Two groups, so the picker also offers the "All" tab and opens on it.
+const ALL_TAB_PROPS: TaxonomicFilterLogicProps = {
+ taxonomicFilterLogicKey: 'event-match-all-tab-test',
+ taxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions],
+}
+
const AUTOCAPTURE = { name: '$autocapture', display_name: 'Autocapture', probability: 0.95 }
describe('taxonomicEventMatchLogic', () => {
@@ -32,12 +39,14 @@ describe('taxonomicEventMatchLogic', () => {
let matchRequests: Record<string, any>[]
let status: number
let matches: Record<string, any>[]
+ let answerGate: Promise<void> | null
beforeEach(() => {
matchRequests = []
status = 200
matches = [AUTOCAPTURE]
- resetEventMatchAvailabilityForTests()
+ answerGate = null
+ resetEventMatchMemoryForTests()
useMocks({
get: {
'/api/projects/:team/event_definitions': () => [200, { results: [], count: 0 }],
@@ -45,6 +54,9 @@ describe('taxonomicEventMatchLogic', () => {
post: {
'/api/projects/:team/taxonomic_search_intent/match_events/': async ({ request }) => {
matchRequests.push((await request.json()) as Record<string, any>)
+ if (answerGate) {
+ await answerGate
+ }
return status === 200 ? [200, { matches }] : [status, {}]
},
},
@@ -71,13 +83,101 @@ describe('taxonomicEventMatchLogic', () => {
})
}
- it('does not ask the model for a person outside the flag', async () => {
- enroll(false)
+ const mountAllTabPicker = (): {
+ allTabFilterLogic: ReturnType<typeof taxonomicFilterLogic.build>
+ allTabLogic: ReturnType<typeof taxonomicEventMatchLogic.build>
+ } => {
+ const allTabFilterLogic = taxonomicFilterLogic(ALL_TAB_PROPS)
+ allTabFilterLogic.mount()
+ const allTabLogic = taxonomicEventMatchLogic(ALL_TAB_PROPS)
+ allTabLogic.mount()
+ return { allTabFilterLogic, allTabLogic }
+ }
- await search('browser capture')
+ const holdAnswer = (): (() => void) => {
+ let answer: () => void = () => {}
+ answerGate = new Promise<void>((resolve) => {
+ answer = resolve
+ })
+ return answer
+ }
+
+ it.each([
+ ['for a person outside the flag', (): typeof logic => (enroll(false), logic)],
+ [
+ 'from a tab that never shows suggestions',
+ (): typeof logic => {
+ enroll(true)
+ const { allTabFilterLogic, allTabLogic } = mountAllTabPicker()
+ allTabFilterLogic.actions.setActiveTab(TaxonomicFilterGroupType.Actions)
+ allTabFilterLogic.actions.setSearchQuery('browser capture')
+ return allTabLogic
+ },
+ ],
+ ])('does not ask the model %s', async (_, arrange) => {
+ const askedLogic = arrange()
+ if (askedLogic === logic) {
+ filterLogic.actions.setSearchQuery('browser capture')
+ }
+ expect(askedLogic.values.isMatching).toBe(false)
+
+ await expectLogic(askedLogic).toFinishAllListeners()
expect(matchRequests).toHaveLength(0)
- expect(logic.values.suggestedEvents).toEqual([])
+ expect(askedLogic.values.isMatching).toBe(false)
+ expect(askedLogic.values.suggestedEvents).toEqual([])
+ })
+
+ it.each([
+ ['during the pause', async (): Promise<void> => {}, 0],
+ [
+ 'while the model answers',
+ async (): Promise<void> => {
+ await waitFor(() => expect(matchRequests).toHaveLength(1))
+ },
+ 1,
+ ],
+ ])('drops the ask when another tab opens %s', async (_, waitBeforeSwitch, expectedRequests) => {
+ enroll(true)
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ const answer = holdAnswer()
+ const { allTabFilterLogic, allTabLogic } = mountAllTabPicker()
+
+ allTabFilterLogic.actions.setSearchQuery('browser capture')
+ await waitBeforeSwitch()
+ allTabFilterLogic.actions.setActiveTab(TaxonomicFilterGroupType.Actions)
+ answer()
+ await expectLogic(allTabLogic).toFinishAllListeners()
+
+ expect(matchRequests).toHaveLength(expectedRequests)
+ expect(allTabLogic.values.isMatching).toBe(false)
+ expect(allTabLogic.values.suggestedEvents).toEqual([])
+ expect(captureSpy).not.toHaveBeenCalledWith('taxonomic filter event match suggested', expect.anything())
+ })
+
+ it('shows a loading state from the All tab until the answer arrives, and records the tab', async () => {
+ enroll(true)
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ const answer = holdAnswer()
+ const { allTabFilterLogic, allTabLogic } = mountAllTabPicker()
+ expect(allTabFilterLogic.values.activeTab).toEqual(TaxonomicFilterGroupType.SuggestedFilters)
+
+ allTabFilterLogic.actions.setSearchQuery('browser capture')
+ await expectLogic(allTabLogic).toDispatchActions(['startEventMatch'])
+
+ expect(allTabLogic.values.isMatching).toBe(true)
+ expect(allTabLogic.values.suggestedEvents).toEqual([])
+
+ answer()
+ await expectLogic(allTabLogic).toFinishAllListeners()
+
+ expect(allTabLogic.values.isMatching).toBe(false)
+ expect(allTabLogic.values.suggestedEvents).toEqual([AUTOCAPTURE])
+ expect(captureSpy).toHaveBeenCalledWith('taxonomic filter event match suggested', {
+ surface: 'legacy-pill',
+ tab: 'suggested_filters',
+ suggestedEvents: ['$autocapture'],
+ })
})
it('suggests the matched events for the current search only, and selects one on click', async () => {
@@ -98,6 +198,7 @@ describe('taxonomicEventMatchLogic', () => {
])
expect(captureSpy).toHaveBeenCalledWith('taxonomic filter event match selected', {
surface: 'legacy-pill',
+ tab: 'events',
eventName: '$autocapture',
position: 0,
})
@@ -106,6 +207,25 @@ describe('taxonomicEventMatchLogic', () => {
expect(logic.values.suggestedEvents).toEqual([])
})
+ it('shows the remembered answer again when the empty state remounts for the same search', async () => {
+ enroll(true)
+ const captureSpy = jest.spyOn(posthog, 'capture')
+ await search('browser capture')
+ expect(matchRequests).toHaveLength(1)
+
+ logic.unmount()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(matchRequests).toHaveLength(1)
+ expect(logic.values.isMatching).toBe(false)
+ expect(logic.values.suggestedEvents).toEqual([AUTOCAPTURE])
+ const suggestedCaptures = captureSpy.mock.calls.filter(
+ ([event]) => event === 'taxonomic filter event match suggested'
+ )
+ expect(suggestedCaptures).toHaveLength(2)
+ })
+
it('does not suggest an event the picker excludes', async () => {
const excludingProps: TaxonomicFilterLogicProps = {
...PROPS,
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts
index edfb05644fe3..844715630d60 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicEventMatchLogic.ts
@@ -28,6 +28,8 @@ const EVENT_MATCH_DEBOUNCE_MS = 350
// A throttle returns 429 by design, and the backend reports its own model failures as 503.
// Other failures are visible only in the browser, so the logic reports them without the search text.
const UNREPORTED_FAILURE_STATUSES = [429, 503]
+// The picker keeps every tab's list mounted and hides the inactive ones, so only the open tab may ask the model.
+const TABS_WITH_SUGGESTIONS = [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.SuggestedFilters]
export interface EventMatches {
projectId: number
@@ -37,19 +39,43 @@ export interface EventMatches {
// A 404 means the person is not in the flag for this project, so the rest of the page load does not ask again.
const unavailableProjectIds = new Set<number>()
+// Switching between the All and Events tabs remounts the empty state and this logic with it, so each answer is
+// kept for the page load and shown again without another model call. The backend caches the same key.
+const answeredMatches = new Map<string, EventMatchApi[]>()
-export function resetEventMatchAvailabilityForTests(): void {
+const matchKey = (projectId: number, query: string): string => `${projectId}:${query}`
+
+export function resetEventMatchMemoryForTests(): void {
unavailableProjectIds.clear()
+ answeredMatches.clear()
+}
+
+function reportSuggested(shown: EventMatchApi[], tab: TaxonomicFilterGroupType): void {
+ // Only the suggestions the picker shows, after its exclusions, count for the flag's metric.
+ if (shown.length === 0) {
+ return
+ }
+ // pinned: analytics event name and properties, the flag's success metric reads them
+ posthog.capture('taxonomic filter event match suggested', {
+ surface: legacyTaxonomicSurface(),
+ tab,
+ suggestedEvents: shown.map((match) => match.name),
+ })
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface taxonomicEventMatchLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
currentProjectId: number | null // projectLogic
+ activeTab: TaxonomicFilterGroupType // taxonomicFilterLogic
searchQuery: string // taxonomicFilterLogic
+ taxonomicGroupTypes: TaxonomicFilterGroupType[] // taxonomicFilterLogic
taxonomicGroups: TaxonomicFilterGroup[] // taxonomicFilterLogic
eventMatches: EventMatches | null
+ isMatching: boolean
+ pendingQuery: string | null
suggestedEvents: EventMatchApi[]
+ tabShowsSuggestions: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -77,6 +103,9 @@ export interface taxonomicEventMatchLogicActions {
setEventMatches: (eventMatches: EventMatches | null) => {
eventMatches: EventMatches | null
}
+ startEventMatch: (query: string) => {
+ query: string
+ }
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -89,6 +118,8 @@ export interface taxonomicEventMatchLogicMeta {
taxonomicGroups: TaxonomicFilterGroup[],
currentProjectId: number | null
) => EventMatchApi[]
+ isMatching: (pendingQuery: string | null, searchQuery: string) => boolean
+ tabShowsSuggestions: (activeTab: TaxonomicFilterGroupType) => boolean
}
}
@@ -101,7 +132,8 @@ export type taxonomicEventMatchLogicType = MakeLogicType<
/**
* Asks the decision model which PostHog core events a search that matched no event name describes, for the
- * `taxonomic-filter-event-match` flag. Mounted only by the events list's empty state. Legacy surface only.
+ * `taxonomic-filter-event-match` flag. Mounted by the empty state of the events list and of the "All" list.
+ * Legacy surface only.
*/
export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
props({} as TaxonomicFilterLogicProps),
@@ -114,12 +146,13 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
projectLogic,
['currentProjectId'],
taxonomicFilterLogic(props),
- ['searchQuery', 'taxonomicGroups'],
+ ['activeTab', 'searchQuery', 'taxonomicGroupTypes', 'taxonomicGroups'],
],
actions: [taxonomicFilterLogic(props), ['selectItem', 'setSearchQuery']],
})),
actions({
findEventMatches: (searchQuery: string) => ({ searchQuery }),
+ startEventMatch: (query: string) => ({ query }),
setEventMatches: (eventMatches: EventMatches | null) => ({ eventMatches }),
selectEventMatch: (match: EventMatchApi) => ({ match }),
}),
@@ -130,6 +163,13 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
setEventMatches: (_, { eventMatches }) => eventMatches,
},
],
+ pendingQuery: [
+ null as string | null,
+ {
+ startEventMatch: (_, { query }) => query,
+ setEventMatches: () => null,
+ },
+ ],
}),
selectors({
suggestedEvents: [
@@ -151,6 +191,15 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
return eventMatches.matches.filter((match) => !excluded.includes(match.name)).slice(0, MAX_SUGGESTIONS)
},
],
+ isMatching: [
+ (s) => [s.pendingQuery, s.searchQuery],
+ (pendingQuery: string | null, searchQuery: string): boolean =>
+ pendingQuery !== null && pendingQuery === searchQuery.trim(),
+ ],
+ tabShowsSuggestions: [
+ (s) => [s.activeTab],
+ (activeTab: TaxonomicFilterGroupType): boolean => TABS_WITH_SUGGESTIONS.includes(activeTab),
+ ],
}),
listeners(({ actions, values }) => ({
setSearchQuery: ({ searchQuery }) => {
@@ -163,13 +212,24 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
query.length < MIN_QUERY_LENGTH ||
query.length > MAX_QUERY_LENGTH ||
projectId === null ||
- unavailableProjectIds.has(projectId)
+ unavailableProjectIds.has(projectId) ||
+ !values.featureFlags[FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH] ||
+ !values.tabShowsSuggestions ||
+ !values.taxonomicGroupTypes.includes(TaxonomicFilterGroupType.Events)
) {
return
}
+ const remembered = answeredMatches.get(matchKey(projectId, query))
+ if (remembered) {
+ actions.setEventMatches({ projectId, query, matches: remembered })
+ reportSuggested(values.suggestedEvents, values.activeTab)
+ return
+ }
+ actions.startEventMatch(query)
await breakpoint(EVENT_MATCH_DEBOUNCE_MS)
- // Read after the pause, so flags that load while the person types still count.
- if (!values.featureFlags[FEATURE_FLAGS.TAXONOMIC_FILTER_EVENT_MATCH]) {
+ // A tab opened during the pause hides this list, so the ask is dropped before it costs a model call.
+ if (!values.tabShowsSuggestions) {
+ actions.setEventMatches(null)
return
}
@@ -191,16 +251,14 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
return
}
breakpoint()
- actions.setEventMatches({ projectId, query, matches })
- // Only the suggestions the picker shows, after its exclusions, count for the flag's metric.
- const shown = values.suggestedEvents
- if (shown.length > 0) {
- // pinned: analytics event name and properties, the flag's success metric reads them
- posthog.capture('taxonomic filter event match suggested', {
- surface: legacyTaxonomicSurface(),
- suggestedEvents: shown.map((match) => match.name),
- })
+ // A tab opened while the model answered hides this list, so the answer is dropped and never counted as shown.
+ if (!values.tabShowsSuggestions) {
+ actions.setEventMatches(null)
+ return
}
+ answeredMatches.set(matchKey(projectId, query), matches)
+ actions.setEventMatches({ projectId, query, matches })
+ reportSuggested(values.suggestedEvents, values.activeTab)
},
selectEventMatch: ({ match }) => {
const eventsGroup = values.taxonomicGroups.find((group) => group.type === TaxonomicFilterGroupType.Events)
@@ -214,6 +272,7 @@ export const taxonomicEventMatchLogic = kea<taxonomicEventMatchLogicType>([
// pinned: analytics event name and properties, the flag's success metric reads them
posthog.capture('taxonomic filter event match selected', {
surface: legacyTaxonomicSurface(),
+ tab: values.activeTab,
eventName: match.name,
position,
})