: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(taxonomic-filter): commit SQL expression in headless menu (#61444)
Paul D'Ambra41e31ef17a42
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.tsindex 5595dbd312d8..5d09f0ad3596 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts@@ -1079,6 +1079,50 @@ describe('taxonomicFilterLogic', () => {expect(personsGroup?.getValue?.(person as any)).toBe(expected)})})++ describe('SQL expression (HogQLExpression) group commits its value', () => {+ let hogqlLogic: ReturnType<typeof taxonomicFilterLogic.build>+ const onChange = jest.fn()++ beforeEach(() => {+ onChange.mockClear()+ hogqlLogic = taxonomicFilterLogic({+ taxonomicFilterLogicKey: 'hogqlExpressionTest',+ taxonomicGroupTypes: [TaxonomicFilterGroupType.HogQLExpression],+ onChange,+ })+ hogqlLogic.mount()+ })++ afterEach(() => {+ hogqlLogic.unmount()+ })++ it('getValue returns the expression so the headless menu can commit it', () => {+ const group = hogqlLogic.values.taxonomicGroups.find(+ (g) => g.type === TaxonomicFilterGroupType.HogQLExpression+ )+ expect(group?.getValue).toBeDefined() // oxlint-disable-line jest/no-restricted-matchers+ // The headless menu synthesizes an item carrying the expression in `value`.+ const item = { name: 'properties.$current_url', value: 'properties.$current_url' }+ expect(group?.getValue?.(item as any)).toBe('properties.$current_url')+ })++ it('selectItem with the derived value fires onChange with the expression, not null', async () => {+ const group = hogqlLogic.values.taxonomicGroups.find(+ (g) => g.type === TaxonomicFilterGroupType.HogQLExpression+ )!+ const item = { name: 'properties.$current_url', value: 'properties.$current_url' }+ // Mirror TaxonomicFilterMenu's handleCommit: the value is derived via group.getValue.+ const value = group.getValue?.(item as any) ?? null++ await expectLogic(hogqlLogic, () => {+ hogqlLogic.actions.selectItem(group, value, item as any)+ }).toDispatchActions(['selectItem'])++ expect(onChange).toHaveBeenCalledWith(group, 'properties.$current_url', item)+ })+ })})describe('redistributeTopMatches', () => {diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsxindex 9d03913bc8b4..f8413be96995 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx@@ -1348,6 +1348,12 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([categoryLabel: () => 'SQL expression',type: TaxonomicFilterGroupType.HogQLExpression,render: InlineHogQLEditor,+ // The headless menu derives the committed value via+ // group.getValue(item); without this the SQL expression+ // resolves to null and the selection is silently dropped.+ // The legacy InlineHogQLEditor passes its value straight+ // to selectItem, so it never relied on getValue.+ getValue: (option) => (option as { value?: TaxonomicFilterValue }).value ?? option.name,getPopoverHeader: () => 'SQL expression',componentProps: { metadataSource, ...hogQLExpressionComponentProps },},