: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): open rebuild taxonomic input trigger in one commit (#64795)
Paul D'Ambraae975fceb651
diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.test.ts b/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.test.tsindex c91e0fd404fa..9e76895a26c4 100644--- a/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.test.ts@@ -1,5 +1,9 @@import { TaxonomicFilterGroupType } from '../types'-import { eventSelectionWasStale } from './TaxonomicFilterMenu'+import { eventSelectionWasStale, resolveInitialMenuState, resolveSelectedOpenState } from './TaxonomicFilterMenu'+import { MenuFilterEntry, MenuFilterState } from './types'++const entryFor = (type: TaxonomicFilterGroupType): MenuFilterEntry =>+ ({ item: { id: 'a', name: 'a' }, group: { type }, name: 'a' }) as unknown as MenuFilterEntrydescribe('eventSelectionWasStale', () => {const staleEvent = { name: 'old', last_seen_at: '2000-01-01T00:00:00Z' } as any@@ -15,3 +19,37 @@ describe('eventSelectionWasStale', () => {expect(eventSelectionWasStale(groupType as TaxonomicFilterGroupType, item)).toBe(expected)})})++describe('resolveSelectedOpenState', () => {+ const hogqlEntry = entryFor(TaxonomicFilterGroupType.HogQLExpression)+ const dwhEntry = entryFor(TaxonomicFilterGroupType.DataWarehouse)+ const eventEntry = entryFor(TaxonomicFilterGroupType.Events)++ it.each<[string, MenuFilterEntry | null, MenuFilterState]>([+ ['no selection -> menu', null, { kind: 'menu' }],+ ['hogql selection -> hogql editor', hogqlEntry, { kind: 'hogql-edit' }],+ [+ 'data warehouse selection -> dwh config (origin menu)',+ dwhEntry,+ { kind: 'dwh-config', table: dwhEntry.item, group: dwhEntry.group, origin: 'menu' },+ ],+ ['other selection -> combobox all', eventEntry, { kind: 'combobox', drillTo: 'all' }],+ ])('%s', (_label, selected, expected) => {+ expect(resolveSelectedOpenState(selected)).toEqual(expected)+ })+})++describe('resolveInitialMenuState', () => {+ const hogqlEntry = entryFor(TaxonomicFilterGroupType.HogQLExpression)++ it.each<[string, boolean, 'menu' | 'combobox' | undefined, MenuFilterEntry | null, MenuFilterState]>([+ ['closed when not defaultOpen', false, undefined, null, { kind: 'closed' }],+ ['not defaultOpen ignores defaultOpenState and selection', false, 'combobox', hogqlEntry, { kind: 'closed' }],+ ['defaultOpenState combobox -> combobox all', true, 'combobox', null, { kind: 'combobox', drillTo: 'all' }],+ ['defaultOpenState menu -> menu', true, 'menu', null, { kind: 'menu' }],+ ['no defaultOpenState falls back to selection (none -> menu)', true, undefined, null, { kind: 'menu' }],+ ['no defaultOpenState falls back to selection (hogql)', true, undefined, hogqlEntry, { kind: 'hogql-edit' }],+ ])('%s', (_label, defaultOpen, defaultOpenState, selected, expected) => {+ expect(resolveInitialMenuState(defaultOpen, defaultOpenState, selected)).toEqual(expected)+ })+})diff --git a/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.tsx b/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.tsxindex c68f2d9720d7..e1a5e8e84b51 100644--- a/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/menu/TaxonomicFilterMenu.tsx@@ -176,6 +176,61 @@ export function eventSelectionWasStale(return isDefinitionStale(item as unknown as EventDefinition)}+/** The default combobox landing — the "All" scope, where recents/pinned lead and+ * the user can search across every category. The one home for this state so the+ * initial-mount and runtime open paths can't drift. */+const comboboxAllState = (): MenuFilterState => ({ kind: 'combobox', drillTo: 'all' })++/**+ * Resolve the panel a trigger open should land on from the current selection.+ * If `selected` is set, jump straight into the panel that matches its group so+ * the user lands on something editable (e.g. the HogQL editor pre-filled with+ * the existing expression) instead of having to re-traverse the dropdown menu.+ * With no selection we fall back to the menu.+ */+export function resolveSelectedOpenState(selected: MenuFilterEntry | null): MenuFilterState {+ if (!selected) {+ return { kind: 'menu' }+ }+ if (selected.group.type === TaxonomicFilterGroupType.HogQLExpression) {+ return { kind: 'hogql-edit' }+ }+ if (selected.group.type === TaxonomicFilterGroupType.DataWarehouse) {+ // origin='menu' so X / Esc / Cancel return to the dropdown menu rather+ // than dropping the user into the (unscrolled) dwh-pick list they never+ // visited.+ return { kind: 'dwh-config', table: selected.item, group: selected.group, origin: 'menu' }+ }+ // The committed selection floats to the first row (and stays highlighted) so+ // the user can verify it at a glance.+ return comboboxAllState()+}++/**+ * Initial menu state at mount. `defaultOpen` consumers lazily mount this+ * component on the user's first trigger interaction, so opening is a one-shot+ * mount concern — it belongs in the initial state, not a post-paint effect, so+ * the picker opens in the same commit it mounts (no intermediate closed frame).+ * `defaultOpenState` routes the open to the panel matching the interaction (the+ * input trigger's search box -> combobox, its filter icon -> menu).+ */+export function resolveInitialMenuState(+ defaultOpen: boolean,+ defaultOpenState: 'menu' | 'combobox' | undefined,+ selected: MenuFilterEntry | null+): MenuFilterState {+ if (!defaultOpen) {+ return { kind: 'closed' }+ }+ if (defaultOpenState === 'combobox') {+ return comboboxAllState()+ }+ if (defaultOpenState === 'menu') {+ return { kind: 'menu' }+ }+ return resolveSelectedOpenState(selected)+}+export function TaxonomicFilterMenu({triggerLabel,selected,@@ -193,7 +248,9 @@ export function TaxonomicFilterMenu({}: TaxonomicFilterMenuProps): JSX.Element {const { groups, selectItem, inputProps, searchQuery, setSearchQuery, selectingKeyOnly, excludedOperators } =useTaxonomicFilterContext()- const [state, setState] = useState<MenuFilterState>({ kind: 'closed' })+ const [state, setState] = useState<MenuFilterState>(() =>+ resolveInitialMenuState(defaultOpen, defaultOpenState, selected ?? null)+ )// Telemetry — track open dwell + commit funnel so we can compare// against legacy `taxonomic filter *` events. Stored in refs so the@@ -271,48 +328,7 @@ export function TaxonomicFilterMenu({action()}, [])- /**- * Resolve the initial state when the trigger opens. If `selected` is- * set, jump straight into the panel that matches its group so the- * user lands on something editable (e.g. the HogQL editor pre-filled- * with the existing expression) instead of having to re-traverse the- * dropdown menu. With no selection we fall back to the menu.- */- const resolveOpenState = useCallback((): MenuFilterState => {- if (!selected) {- return { kind: 'menu' }- }- if (selected.group.type === TaxonomicFilterGroupType.HogQLExpression) {- return { kind: 'hogql-edit' }- }- if (selected.group.type === TaxonomicFilterGroupType.DataWarehouse) {- // origin='menu' so X / Esc / Cancel return to the dropdown- // menu rather than dropping the user into the (unscrolled)- // dwh-pick list they never visited.- return { kind: 'dwh-config', table: selected.item, group: selected.group, origin: 'menu' }- }- // Land on the regular combobox on the "All" scope. The committed selection- // floats to the first row (and stays highlighted) so the user can verify it- // at a glance, while still seeing recents/pinned and being able to search- // across every category.- return { kind: 'combobox', drillTo: 'all' }- }, [selected])-- // Open on mount when the consumer lazily mounts this component in- // response to the user's first click (see `TaxonomicPopoverMenu`).- // Runs once — opening is a one-shot mount concern, not reactive.- useEffect(() => {- if (defaultOpen) {- setState(- defaultOpenState === 'combobox'- ? { kind: 'combobox', drillTo: 'all' }- : defaultOpenState === 'menu'- ? { kind: 'menu' }- : resolveOpenState()- )- }- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [])+ const resolveOpenState = useCallback((): MenuFilterState => resolveSelectedOpenState(selected ?? null), [selected])// -- Recent / Pinned shortcuts -- read from kea so menu items reflect// the live counts. Mapped back to entries via source group.