: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): single-group filters lead with the group, not an empty All (#68425)
Paul D'Ambra8e7e22455e49
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 40230a69bb6d..7d43fa656f48 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2405,9 +2405,9 @@ snapshots:filters-propertygroupfilters-data-exploration-andorfilterselect--default--light:hash: v1.k794b7964.878d5718b31de7391125577d89e8f5a2aff382328cc2ecbb92ccf7a11153a477.HrJBJwrpwOBffqHfDG_XUostPZKCiuts0wUpu35Ikjgfilters-taxonomic-filter--actions--dark:- hash: v1.k794b7964.2ac4a86fe6dbe69d6b82c5938492106a73e88f6b3c683ebb92a54086e7eef4e5.0J-Xp6zLeVTgkWQ4FQ96y7h0LTLJ_d4bkE6BMLy0oKU+ hash: v1.k794b7964.b7c757ee23be748f5575fd797100909237d9f8a51380c238e28f8be92dfe9675.sQGQQY7si0_EphicqOD-3pvgEuWhah3SZA4e6TVTnIwfilters-taxonomic-filter--actions--light:- hash: v1.k794b7964.8f42dd6fc580b0589aca7b26db8354698c8c4701bf7e632f9cc244ba84f7bf00.GwPkYpCSqvO0ou63G7Phx_Hg0NRPUcSaZ9dJZtGGPlc+ hash: v1.k794b7964.4913bcfd390eb413407696520affbe647ae1bec1a33036b6d17ba7ea844f1cf0.Hf-hM-HkNe5FLsYIb8g4D6dmJSNPz7SdXdv-lMUBfWUfilters-taxonomic-filter--autocapture-context-promotes-elements--dark:hash: v1.k794b7964.592d38eef9bc6ecd4b4685685fd8e945d15dea3b81a93022ae76153aaa7f140f.93gRKyd7YLpXrDQoydHnOu7qbJbfIUYrfjgYlncZsfIfilters-taxonomic-filter--autocapture-context-promotes-elements--light:@@ -5625,9 +5625,9 @@ snapshots:scenes-app-heatmap--generating--light:hash: v1.k794b7964.9e9c863c6e06c7e6e610353fbd826ee85406c86419eeba160ad2e525b66021bc.pQ8mxSWr4ScfBLrbe8Ppc_tyJdr0mNjKY5q71eurkBMscenes-app-heatmap--iframe-example--dark:- hash: v1.k794b7964.f85cb7ceb1ef6cd47c37a7408d2206432546a0509eae3aa957316dca54219fbf.NUQH6bQ3c0L52-B8eFHyvoPuGECuS2P3jOG_zPM1q1M+ hash: v1.k794b7964.739b8f5ac461aff690d35b4622c683f5758d1a2f16d203cb315aaa449a954cb7.QT8KobMmRxytbOoCQFHYofq2yAHXDezRBTnyfgk91Tsscenes-app-heatmap--iframe-example--light:- hash: v1.k794b7964.99a49b92212947be5153f7f445fa411097ada9f02a03ce866069b1d9bd34a7ab.rx8z4wHw_ZSqa8jn4rAGQwVj_f6frnxQ5mpYIHZmc6w+ hash: v1.k794b7964.1f8c1978a875ca2e7467d8f8fb5109f6a2d706d75535edb8a478be4365fcd613.RxyMDJcjQNBieIUkMwxqriiNth6u5_-VsGKAgyFWnoQscenes-app-heatmap--new--dark:hash: v1.k794b7964.cfd075c10189496c867372e36391cf5985948fe5a8137c434545f5825b15ac7e.IUvQTi7vHNPSGeWj-q6upJsHMLU3UpumxHwGBndOhYEscenes-app-heatmap--new--light:@@ -5636,6 +5636,10 @@ snapshots:hash: v1.k794b7964.cfd075c10189496c867372e36391cf5985948fe5a8137c434545f5825b15ac7e.CBhNqr7PbQNz8qkKG2U9CTIyRe5lDAYRM83-AJ8_zVwscenes-app-heatmap-new--new-form--light:hash: v1.k794b7964.efcfe6e747715ec98507ddc9a223cc52e821d9c44cde876551edc9e5813c2930.GJ6WxbvpypQJHEukgIxvQmhzq0GFcmtyTNZtdfA959A+ scenes-app-heatmap-recording--recording-mode-with-clickmap--dark:+ hash: v1.k794b7964.3499aad6c2502ef406a4482b07fc63e130419f017d378e67f368d037bcfe60cd.bq5I6_BkW5qM66IZeNnjtJhQ6b2_3ch-I0qGo_yKKT0+ scenes-app-heatmap-recording--recording-mode-with-clickmap--light:+ hash: v1.k794b7964.22f3a94ca40cb149e4304284f5a3ed613728ed22a1d4554fa94754aca6dc38e8.RL9cCxn6_8zy2HgMxnfhUCDvQk_-tWwn_vmZNIZjF4Iscenes-app-heatmaps-saved--list--dark:hash: v1.k794b7964.8368377e136c567c3c500c97924486837234c230858baf0eb14678b6900d68c6.qpjMZIE3Ii8vpyLrfaKjCdym7waJtp38DGez1iugMMoscenes-app-heatmaps-saved--list--light:diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsxindex dabc1615cde4..2ef3e39b7613 100644--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx@@ -61,6 +61,9 @@ describe('TaxonomicFilter', () => {'/api/environments/:team/query': { results: [] },},})+ // Recents/pinned persist to localStorage; clear so an earlier test's selection+ // (which records a recent) can't leak in and reorder a later single-group list.+ localStorage.clear()initKeaTests()actionsModel.mount()groupsModel.mount()@@ -132,7 +135,12 @@ describe('TaxonomicFilter', () => {])('allows overriding the Suggested filters label with "$label" in $description', async ({ label }) => {renderFilter({suggestedFiltersLabel: label,- taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ // Two substantive groups so "All" survives (a single substantive group drops it)+ taxonomicGroupTypes: [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.Actions,+ ],})await waitFor(() => {@@ -890,7 +898,7 @@ describe('TaxonomicFilter', () => {await waitFor(() => {expect(screen.queryAllByTestId(/^prop-filter-events-/)).toHaveLength(0)})- })+ }, 10000)})it.each([@@ -1162,7 +1170,14 @@ describe('TaxonomicFilter', () => {const user = userEvent.setup()useMockPageviewUrls(['https://example.com/pricing', 'https://example.com/pricing/teams'])renderFilter({- taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.PageviewUrls],+ // Two substantive groups so the aggregated "All" tab survives (a single+ // substantive group drops it); Events has no 'pricing' match so the URL+ // shortcut is still the only aggregated row.+ taxonomicGroupTypes: [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.PageviewUrls,+ TaxonomicFilterGroupType.Events,+ ],collapseUrlsToContainsRow: true,})@@ -1379,7 +1394,12 @@ describe('TaxonomicFilter', () => {it('control variant: default suggested-filters label is "Suggestions"', async () => {setVariant('control')renderFilter({- taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ // Two substantive groups so "All" survives (a single substantive group drops it)+ taxonomicGroupTypes: [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.Actions,+ ],})await waitFor(() => {@@ -1390,7 +1410,12 @@ describe('TaxonomicFilter', () => {it('pill variant: default suggested-filters label is "All" (seen in the dropdown items)', async () => {setVariant('pill')renderFilter({- taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ // Two substantive groups so "All" survives (a single substantive group drops it)+ taxonomicGroupTypes: [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.Actions,+ ],})await waitFor(() => {diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.tsindex 593d0e7eaa36..362d793435f6 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useGroupList.ts@@ -34,6 +34,7 @@ import {TaxonomicFilterGroup,TaxonomicFilterGroupType,} from 'lib/components/TaxonomicFilter/types'+import { floatRecentAndPinnedToTop, groupItemKey } from 'lib/components/TaxonomicFilter/utils/floatRecentPinned'import { createFuse } from 'lib/utils/fuseSearch'import { getCoreFilterDefinition } from '~/taxonomy/helpers'@@ -73,6 +74,12 @@ export interface UseGroupListInput {autoSelectItem?: boolean/** When true, the list initialises with index=0; otherwise index=NO_ITEM_SELECTED. */selectFirstItem?: boolean+ /** Set only when this is the filter's sole substantive group (no separate Recent/Pinned+ * tabs lead the filter). Floats these recent (most-recent first) then pinned items to+ * the top of the un-searched list. Mirrors legacy infiniteListLogic's `soleGroupValueKeyer`+ * path. */+ promoteRecentItemsToTop?: TaxonomicDefinitionTypes[]+ promotePinnedItemsToTop?: TaxonomicDefinitionTypes[]}export interface UseGroupListResult {@@ -122,6 +129,8 @@ export function useGroupList(input: UseGroupListInput): UseGroupListResult {enableKeywordShortcuts = false,autoSelectItem = true,selectFirstItem = true,+ promoteRecentItemsToTop,+ promotePinnedItemsToTop,} = inputconst [isExpanded, setIsExpanded] = useState(false)@@ -354,8 +363,29 @@ export function useGroupList(input: UseGroupListInput): UseGroupListResult {if (remoteItems.results.length > 0) {merged.push(...remoteItems.results)}+ // Sole substantive group: float its own recent/pinned items to the top of the+ // un-searched list (keyword shortcuts only appear while searching, so they're+ // never displaced). Mirrors legacy infiniteListLogic's `soleGroupValueKeyer` path.+ if (!trimmedSearch && (promoteRecentItemsToTop?.length || promotePinnedItemsToTop?.length)) {+ const keyOf = (item: TaxonomicDefinitionTypes): string | null =>+ groupItemKey(group.type, group.getValue?.(item) ?? null)+ return floatRecentAndPinnedToTop(+ merged,+ keyOf,+ promoteRecentItemsToTop || [],+ promotePinnedItemsToTop || []+ ) as TaxonomicDefinitionTypes[]+ }return merged- }, [keywordShortcuts, localItems, remoteItems])+ }, [+ keywordShortcuts,+ localItems,+ remoteItems,+ trimmedSearch,+ promoteRecentItemsToTop,+ promotePinnedItemsToTop,+ group,+ ])const isExpandable = !!(group.endpoint &&diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.test.tsxindex d4ac52f5bcd7..fb60151ce09b 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.test.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.test.tsx@@ -81,6 +81,26 @@ describe('useTaxonomicFilter', () => {expect(result.current.groupTypes).not.toContain(TaxonomicFilterGroupType.SuggestedFilters)})+ // Mirrors the legacy `taxonomicGroupTypes` selector cases in taxonomicFilterLogic.test.ts —+ // both surfaces must lead with the sole group, then Recent/Pinned, and drop any prepended All.+ it.each([+ {+ name: 'single substantive group leads, Recent/Pinned follow (no All)',+ requested: [TaxonomicFilterGroupType.Events],+ },+ {+ name: 'single substantive group drops an explicitly-prepended All and still leads',+ requested: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ },+ ])('$name', ({ requested }) => {+ const { result } = renderHook(() => useTaxonomicFilter({ taxonomicGroupTypes: requested }), { wrapper })+ expect(result.current.groupTypes).toEqual([+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.RecentFilters,+ TaxonomicFilterGroupType.PinnedFilters,+ ])+ })+it('auto-injects SuggestedFilters as the default for a multi-content picker', () => {const { result } = renderHook(() =>@@ -164,7 +184,12 @@ describe('useTaxonomicFilter', () => {const { result } = renderHook(() =>useTaxonomicFilter({- taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ // Two substantive groups so "All" is retained — a single substantive group drops it+ taxonomicGroupTypes: [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.Actions,+ ],}),{ wrapper })diff --git a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.ts b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.tsindex 52bebfe742ec..71f881b70926 100644--- a/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.ts+++ b/frontend/src/lib/components/TaxonomicFilter/hooks/useTaxonomicFilter.ts@@ -210,9 +210,18 @@ function resolveTaxonomicGroupTypes(// 2a. The rebuilt menu always surfaces the SuggestedFilters ("All") tab as the// default cross-group landing spot when there's more than one substantive group- // to aggregate.+ // to aggregate. With a single substantive group there's nothing for "All" to+ // aggregate, so drop it (a call site may have prepended SuggestedFilters); Recent/Pinned+ // then follow the group instead of leading, and the group's own list floats recent/pinned+ // items to the top.const substantiveGroupCount = filtered.filter((t) => !META_GROUP_TYPES.has(t)).length- if (+ const singleSubstantiveGroup = substantiveGroupCount === 1+ if (singleSubstantiveGroup) {+ const suggestedIdx = filtered.indexOf(TaxonomicFilterGroupType.SuggestedFilters)+ if (suggestedIdx !== -1) {+ filtered.splice(suggestedIdx, 1)+ }+ } else if (available.has(TaxonomicFilterGroupType.SuggestedFilters) &&!filtered.includes(TaxonomicFilterGroupType.SuggestedFilters) &&substantiveGroupCount >= 2@@ -220,28 +229,33 @@ function resolveTaxonomicGroupTypes(filtered.unshift(TaxonomicFilterGroupType.SuggestedFilters)}- // 2b. Auto-inject Recent/Pinned meta tabs when available and not already present.+ // 2b. Auto-inject Recent/Pinned meta tabs when available and not already present. For a+ // single substantive group they follow the group; otherwise they lead, after the meta block.for (const metaType of AUTO_INJECT_META_GROUPS) {if (available.has(metaType) && !filtered.includes(metaType)) {- filtered.splice(indexAfterLastMetaGroup(filtered), 0, metaType)+ const insertAt = singleSubstantiveGroup ? filtered.length : indexAfterLastMetaGroup(filtered)+ filtered.splice(insertAt, 0, metaType)}}- // 3. Promote shortcut groups to right after the meta block- const shortcutGroups: TaxonomicFilterGroupType[] = [- ...SHORTCUT_GROUPS_BASE,- ...(eventNames.includes('$autocapture') ? [TaxonomicFilterGroupType.Elements] : []),- ]- const toInsert: TaxonomicFilterGroupType[] = []- for (const groupType of shortcutGroups) {- const idx = filtered.indexOf(groupType)- if (idx !== -1) {- filtered.splice(idx, 1)- toInsert.push(groupType)+ // 3. Promote shortcut groups to right after the meta block. Skipped for a single group,+ // where there's nothing to reorder above and it would push the group below its meta tabs.+ if (!singleSubstantiveGroup) {+ const shortcutGroups: TaxonomicFilterGroupType[] = [+ ...SHORTCUT_GROUPS_BASE,+ ...(eventNames.includes('$autocapture') ? [TaxonomicFilterGroupType.Elements] : []),+ ]+ const toInsert: TaxonomicFilterGroupType[] = []+ for (const groupType of shortcutGroups) {+ const idx = filtered.indexOf(groupType)+ if (idx !== -1) {+ filtered.splice(idx, 1)+ toInsert.push(groupType)+ }+ }+ if (toInsert.length > 0) {+ filtered.splice(indexAfterLastMetaGroup(filtered), 0, ...toInsert)}- }- if (toInsert.length > 0) {- filtered.splice(indexAfterLastMetaGroup(filtered), 0, ...toInsert)}return filtered@@ -321,6 +335,14 @@ export function useTaxonomicFilter(opts: UseTaxonomicFilterOptions): TaxonomicFi[groups])+ // The filter's only substantive (non-meta) group, if there is exactly one. That group's+ // list floats its own recent/pinned items to the top, since there are no leading+ // Recent/Pinned tabs (see resolveTaxonomicGroupTypes and useGroupList).+ const soleSubstantiveGroupType = useMemo<TaxonomicFilterGroupType | null>(() => {+ const substantive = groupTypes.filter((t) => !META_GROUP_TYPES.has(t))+ return substantive.length === 1 ? substantive[0] : null+ }, [groupTypes])+// ---- search query (controlled / uncontrolled) ---------------------------const [internalSearchQuery, setInternalSearchQuery] = useState(initialSearchQuery ?? '')const isSearchControlled = controlledSearchQuery !== undefined@@ -486,6 +508,13 @@ export function useTaxonomicFilter(opts: UseTaxonomicFilterOptions): TaxonomicFi// undefined for groups whose data is `group.options` / endpoint /// optionsFromProp — useGroupList handles those internally.localOverride: getLocalOverride(group.type),+ // The sole substantive group carries recents/pinned inline (no leading tabs).+ ...(group.type === soleSubstantiveGroupType+ ? {+ promoteRecentItemsToTop: getLocalOverride(TaxonomicFilterGroupType.RecentFilters),+ promotePinnedItemsToTop: getLocalOverride(TaxonomicFilterGroupType.PinnedFilters),+ }+ : {}),}),[searchQuery,@@ -498,6 +527,7 @@ export function useTaxonomicFilter(opts: UseTaxonomicFilterOptions): TaxonomicFiselectFirstItem,autoSelectItem,getLocalOverride,+ soleSubstantiveGroupType,])diff --git a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.tsindex 49a0e9fd037a..8c09fd1a43aa 100644--- a/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts+++ b/frontend/src/lib/components/TaxonomicFilter/infiniteListLogic.ts@@ -19,6 +19,7 @@ import { legacyTaxonomicSurface } from 'lib/components/TaxonomicFilter/taxonomicimport {ExcludedOperators,InfiniteListLogicProps,+ META_GROUP_TYPES,QuickFilterItem,SkeletonItem,isQuickFilterItem,@@ -35,6 +36,12 @@ import {COLLAPSED_TO_CONTAINS_ROW,partitionContainsShortcuts,} from 'lib/components/TaxonomicFilter/utils/collapsedContainsRow'+import {+ floatRecentAndPinnedToTop,+ groupItemKey,+ pinnedSourceKey,+ recentSourceKey,+} from 'lib/components/TaxonomicFilter/utils/floatRecentPinned'import { promoteMatchingProperties } from 'lib/components/TaxonomicFilter/utils/promoteProperties'import { FEATURE_FLAGS } from 'lib/constants'import { createFuse } from 'lib/utils/fuseSearch'@@ -87,20 +94,6 @@ function recentItemMatchesSearch(return false}-// The two key builders must stay format-aligned: recent and pinned rows dedupe-// against each other only because both produce `sourceGroupType::value`.-function recentSourceKey(item: TaxonomicDefinitionTypes): string | null {- return hasRecentContext(item) && item._recentContext.sourceValue != null- ? `${item._recentContext.sourceGroupType}::${item._recentContext.sourceValue}`- : null-}--function pinnedSourceKey(item: TaxonomicDefinitionTypes): string | null {- return hasPinnedContext(item) && item._pinnedContext.value != null- ? `${item._pinnedContext.sourceGroupType}::${item._pinnedContext.value}`- : null-}-function withoutPinnedDuplicatesOfRecents(pinnedItems: TaxonomicDefinitionTypes[],recentItems: TaxonomicDefinitionTypes[]@@ -533,6 +526,36 @@ export const infiniteListLogic = kea<infiniteListLogicType>([)},],+ // This list is the filter's only substantive (non-meta) group. There are no separate+ // Recent/Pinned tabs leading the filter, so this list floats recent/pinned items to+ // the top of its own results instead (see `items`).+ isSoleSubstantiveGroup: [+ (s) => [s.listGroupType, s.taxonomicGroupTypes],+ (listGroupType, taxonomicGroupTypes: TaxonomicFilterGroupType[]): boolean => {+ const substantive = taxonomicGroupTypes.filter((t) => !META_GROUP_TYPES.has(t))+ return substantive.length === 1 && substantive[0] === listGroupType+ },+ ],+ // Keys a group result the same way recent/pinned entries are keyed+ // (`sourceGroupType::value`), so `floatRecentAndPinnedToTop` can line the tiers up.+ // Null unless this is the sole substantive group — kept off `items` as a small input.+ soleGroupValueKeyer: [+ (s) => [s.isSoleSubstantiveGroup, s.listGroupType, s.taxonomicGroups],+ (+ isSoleSubstantiveGroup,+ listGroupType,+ taxonomicGroups: TaxonomicFilterGroup[]+ ): ((item: TaxonomicDefinitionTypes) => string | null) | null => {+ if (!isSoleSubstantiveGroup) {+ return null+ }+ const getValue = taxonomicGroups.find((g) => g.type === listGroupType)?.getValue+ if (!getValue) {+ return null+ }+ return (item: TaxonomicDefinitionTypes): string | null => groupItemKey(listGroupType, getValue(item))+ },+ ],allowNonCapturedEvents: [() => [(_, props) => props.allowNonCapturedEvents],(allowNonCapturedEvents: boolean | undefined) => allowNonCapturedEvents ?? false,@@ -979,6 +1002,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([s.suggestedPinnedMatches,s.suggestedRecentMatches,s.keywordShortcutItems,+ s.soleGroupValueKeyer,(_, props: InfiniteListLogicProps) => props.collapseUrlsToContainsRow,],(@@ -992,6 +1016,7 @@ export const infiniteListLogic = kea<infiniteListLogicType>([suggestedPinnedMatches,suggestedRecentMatches,keywordShortcutItems,+ soleGroupValueKeyer,collapseUrlsToContainsRow) => {// Collapse URL groups to a single "URL contains <query>" shortcut row@@ -1041,9 +1066,22 @@ export const infiniteListLogic = kea<infiniteListLogicType>([...remoteItems.results,...topMatches,]+ // Reordering a windowed list would break onRowsRendered's display-index ->+ // remote-offset mapping (and sparse holes would crash the keyer), so only float+ // the sole group's recents/pinned once its list is fully loaded and dense.+ // Local-only groups (count 0, no remote) are always fully loaded.+ const soleGroupFullyLoaded =+ remoteItems.results.length >= remoteItems.count && !combinedResults.includes(undefined as any)const orderedBase = searchQuery? promoteMatchingProperties(combinedResults, searchQuery)- : combinedResults+ : soleGroupValueKeyer && soleGroupFullyLoaded+ ? floatRecentAndPinnedToTop(+ combinedResults,+ soleGroupValueKeyer,+ contextFilteredRecentItems || [],+ contextFilteredPinnedItems || []+ )+ : combinedResults// The "URL contains <query>" shortcut leads the aggregated SuggestedFilters list —// ahead of recents/pinned/top-matches — so a URL search surfaces the contains// suggestion first. Everything else keeps its existing order.diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.tsindex 100b1710315d..4614bda7756b 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts@@ -371,6 +371,9 @@ describe('taxonomicFilterLogic', () => {taxonomicGroupTypes: [TaxonomicFilterGroupType.SuggestedFilters,TaxonomicFilterGroupType.InternalEventProperties,+ // Second substantive group so "All" is retained (a single substantive group+ // drops it); Events has no 'activity' match so top matches stay unchanged+ TaxonomicFilterGroupType.Events,],}const noGetValueLogic = taxonomicFilterLogic(logicProps)@@ -766,9 +769,13 @@ describe('taxonomicFilterLogic', () => {it.each([{- description: 'control: includes SuggestedFilters when explicitly listed',+ description: 'control: includes SuggestedFilters when explicitly listed in a multi-group picker',variant: 'control',- groupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ groupTypes: [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.Actions,+ ],expectPresent: true,expectDefault: true,},@@ -793,6 +800,20 @@ describe('taxonomicFilterLogic', () => {expectPresent: false,expectDefault: false,},+ {+ description: 'control: strips explicitly-listed SuggestedFilters for a single substantive group',+ variant: 'control',+ groupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ expectPresent: false,+ expectDefault: false,+ },+ {+ description: 'pill: strips explicitly-listed SuggestedFilters for a single substantive group',+ variant: 'pill',+ groupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ expectPresent: false,+ expectDefault: false,+ },])('$description', ({ variant, groupTypes, expectPresent, expectDefault }) => {featureFlagLogic.actions.setFeatureFlags([], {[FEATURE_FLAGS.TAXONOMIC_FILTER_CATEGORY_DROPDOWN]: variant,@@ -915,6 +936,24 @@ describe('taxonomicFilterLogic', () => {TaxonomicFilterGroupType.EventProperties,],},+ {+ description: 'single substantive group leads, with Recent/Pinned after it (no All)',+ groupTypes: [TaxonomicFilterGroupType.Events],+ expected: [+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.RecentFilters,+ TaxonomicFilterGroupType.PinnedFilters,+ ],+ },+ {+ description: 'single substantive group drops an explicitly-prepended All and still leads',+ groupTypes: [TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events],+ expected: [+ TaxonomicFilterGroupType.Events,+ TaxonomicFilterGroupType.RecentFilters,+ TaxonomicFilterGroupType.PinnedFilters,+ ],+ },])('$description', ({ groupTypes, expected }) => {const testLogicProps: TaxonomicFilterLogicProps = {taxonomicFilterLogicKey: `testReorder-${groupTypes.join('-')}`,diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsxindex 3eda0ebcfc27..f820353e8c72 100644--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx@@ -1574,7 +1574,24 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([// because it has no per-variant arm to protect.const pillVariant = featureFlags[FEATURE_FLAGS.TAXONOMIC_FILTER_CATEGORY_DROPDOWN] === 'pill'const substantiveGroupCount = filtered.filter((t) => !META_GROUP_TYPES.has(t)).length- if (+ const singleSubstantiveGroup = substantiveGroupCount === 1++ const metaGroupOrder = [+ TaxonomicFilterGroupType.SuggestedFilters,+ TaxonomicFilterGroupType.RecentFilters,+ TaxonomicFilterGroupType.PinnedFilters,+ ]++ if (singleSubstantiveGroup) {+ // With one real group there's nothing for "All" to aggregate, so drop it+ // (a call site may have prepended SuggestedFilters — see TaxonomicPropertyFilter).+ // Recent/Pinned then follow the group instead of leading, and the group's own+ // list floats recent/pinned items to the top (see infiniteListLogic `items`).+ const suggestedIdx = filtered.indexOf(TaxonomicFilterGroupType.SuggestedFilters)+ if (suggestedIdx !== -1) {+ filtered.splice(suggestedIdx, 1)+ }+ } else if (pillVariant &&availableGroupTypes.has(TaxonomicFilterGroupType.SuggestedFilters) &&!filtered.includes(TaxonomicFilterGroupType.SuggestedFilters) &&@@ -1583,42 +1600,45 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([filtered.unshift(TaxonomicFilterGroupType.SuggestedFilters)}- // RecentFilters and PinnedFilters are auto-injected after existing- // meta groups (including SuggestedFilters when present).- const metaGroupOrder = [- TaxonomicFilterGroupType.SuggestedFilters,- TaxonomicFilterGroupType.RecentFilters,- TaxonomicFilterGroupType.PinnedFilters,- ]+ // RecentFilters and PinnedFilters are auto-injected after existing meta groups+ // (including SuggestedFilters when present) for multi-group filters, but after the+ // sole group when there's only one — so the group itself leads.const autoInjectGroups = [TaxonomicFilterGroupType.RecentFilters,TaxonomicFilterGroupType.PinnedFilters,]for (const metaType of autoInjectGroups) {if (availableGroupTypes.has(metaType) && !filtered.includes(metaType)) {- filtered.splice(indexAfterLastMetaGroup(filtered, metaGroupOrder), 0, metaType)+ const insertAt = singleSubstantiveGroup+ ? filtered.length+ : indexAfterLastMetaGroup(filtered, metaGroupOrder)+ filtered.splice(insertAt, 0, metaType)}}- // Promote shortcut groups to top positions (after meta groups)- const shortcutGroups: TaxonomicFilterGroupType[] = [- TaxonomicFilterGroupType.PageviewUrls,- TaxonomicFilterGroupType.Screens,- TaxonomicFilterGroupType.EmailAddresses,- ...(eventNames.includes('$autocapture') ? [TaxonomicFilterGroupType.Elements] : []),- ]-- const toInsert: TaxonomicFilterGroupType[] = []- for (const groupType of shortcutGroups) {- const idx = filtered.indexOf(groupType)- if (idx !== -1) {- filtered.splice(idx, 1)- toInsert.push(groupType)+ // Promote shortcut groups to top positions (after meta groups). With a single+ // substantive group there's nothing to reorder above it, and doing so would push+ // the group below its own Recent/Pinned tabs, so skip it.+ if (!singleSubstantiveGroup) {+ const shortcutGroups: TaxonomicFilterGroupType[] = [+ TaxonomicFilterGroupType.PageviewUrls,+ TaxonomicFilterGroupType.Screens,+ TaxonomicFilterGroupType.EmailAddresses,+ ...(eventNames.includes('$autocapture') ? [TaxonomicFilterGroupType.Elements] : []),+ ]++ const toInsert: TaxonomicFilterGroupType[] = []+ for (const groupType of shortcutGroups) {+ const idx = filtered.indexOf(groupType)+ if (idx !== -1) {+ filtered.splice(idx, 1)+ toInsert.push(groupType)+ }}- }- if (toInsert.length > 0) {- filtered.splice(indexAfterLastMetaGroup(filtered, metaGroupOrder), 0, ...toInsert)+ if (toInsert.length > 0) {+ filtered.splice(indexAfterLastMetaGroup(filtered, metaGroupOrder), 0, ...toInsert)+ }}return filtereddiff --git a/frontend/src/lib/components/TaxonomicFilter/utils/floatRecentPinned.test.ts b/frontend/src/lib/components/TaxonomicFilter/utils/floatRecentPinned.test.tsnew file mode 100644index 000000000000..655eb37720f9--- /dev/null+++ b/frontend/src/lib/components/TaxonomicFilter/utils/floatRecentPinned.test.ts@@ -0,0 +1,85 @@+import { SkeletonItem, TaxonomicDefinitionTypes, TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'++import { floatRecentAndPinnedToTop } from './floatRecentPinned'++describe('floatRecentAndPinnedToTop', () => {+ const G = TaxonomicFilterGroupType.Cohorts+ const keyOf = (item: TaxonomicDefinitionTypes): string | null => {+ const value = (item as { value?: string }).value+ return value == null ? null : `${G}::${value}`+ }+ const groupItem = (value: string | null): TaxonomicDefinitionTypes =>+ ({ value }) as unknown as TaxonomicDefinitionTypes+ const recent = (value: string): TaxonomicDefinitionTypes =>+ ({ _recentContext: { sourceGroupType: G, sourceValue: value } }) as unknown as TaxonomicDefinitionTypes+ const pinned = (value: string): TaxonomicDefinitionTypes =>+ ({ _pinnedContext: { sourceGroupType: G, value } }) as unknown as TaxonomicDefinitionTypes++ const valuesOf = (items: (TaxonomicDefinitionTypes | SkeletonItem)[]): (string | undefined)[] =>+ items.map((i) => (i as { value?: string }).value)++ it.each([+ {+ description: 'recents float to the top, most-recent (earliest in list) first',+ items: ['a', 'b', 'c', 'd'],+ recents: ['c', 'a'],+ pins: [] as string[],+ expected: ['c', 'a', 'b', 'd'],+ },+ {+ description: 'pinned float below recents, above the rest',+ items: ['a', 'b', 'c', 'd'],+ recents: ['c'],+ pins: ['b'],+ expected: ['c', 'b', 'a', 'd'],+ },+ {+ description: 'an item that is both recent and pinned appears once, in the recent tier',+ items: ['a', 'b', 'c'],+ recents: ['b'],+ pins: ['b'],+ expected: ['b', 'a', 'c'],+ },+ {+ description: 'non-matching items keep their original relative order',+ items: ['a', 'b', 'c', 'd'],+ recents: ['d'],+ pins: [] as string[],+ expected: ['d', 'a', 'b', 'c'],+ },+ {+ description: 'recent/pinned entries with no matching group item promote nothing',+ items: ['a', 'b'],+ recents: ['zzz'],+ pins: ['yyy'],+ expected: ['a', 'b'],+ },+ ])('$description', ({ items, recents, pins, expected }) => {+ const result = floatRecentAndPinnedToTop(items.map(groupItem), keyOf, recents.map(recent), pins.map(pinned))+ expect(valuesOf(result)).toEqual(expected)+ })++ it('keeps a synthetic null-value leading row (e.g. "All events") on top when a real item is pinned', () => {+ const items = [groupItem(null), groupItem('a'), groupItem('b')]+ const result = floatRecentAndPinnedToTop(items, keyOf, [], [pinned('b')])+ expect(valuesOf(result)).toEqual([null, 'b', 'a'])+ })++ it('leaves sparse-array holes in place and never keys them (a partially loaded legacy list must not crash or reorder holes)', () => {+ const throwingKeyOf = (item: TaxonomicDefinitionTypes): string | null => {+ // Mirrors a real group getValue that assumes a present item, e.g. `'id' in item`.+ const value = (item as { value?: string }).value+ return value == null ? null : `${G}::${value}`+ }+ const items: (TaxonomicDefinitionTypes | undefined)[] = [groupItem('a'), undefined, groupItem('c')]+ const result = floatRecentAndPinnedToTop(items as TaxonomicDefinitionTypes[], throwingKeyOf, [recent('c')], [])+ // 'c' floats to the top; 'a' and the hole stay in the rest tier by original index+ // (the hole is never floated and never keyed — throwingKeyOf is never called on it).+ expect(result.map((i) => (i == null ? 'HOLE' : (i as { value?: string }).value))).toEqual(['c', 'a', 'HOLE'])+ })++ it('returns the input array unchanged when there is nothing to promote', () => {+ const items = ['a', 'b'].map(groupItem)+ expect(floatRecentAndPinnedToTop(items, keyOf, [], [])).toBe(items)+ })+})diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/floatRecentPinned.ts b/frontend/src/lib/components/TaxonomicFilter/utils/floatRecentPinned.tsnew file mode 100644index 000000000000..d08142bc7f24--- /dev/null+++ b/frontend/src/lib/components/TaxonomicFilter/utils/floatRecentPinned.ts@@ -0,0 +1,88 @@+import { hasRecentContext } from 'lib/components/TaxonomicFilter/recentTaxonomicFiltersLogic'+import { hasPinnedContext } from 'lib/components/TaxonomicFilter/taxonomicFilterPinnedPropertiesLogic'+import {+ isSkeletonItem,+ SkeletonItem,+ TaxonomicDefinitionTypes,+ TaxonomicFilterGroupType,+ TaxonomicFilterValue,+} from 'lib/components/TaxonomicFilter/types'++// The single source of truth for the key a recent, a pinned entry, and a group's+// own result all agree on, so the three can be compared. Recent/pinned entries key+// off their recorded source group + value; a group result keys off its own type ++// `getValue`. Everything that builds one of these keys must go through here.+export function groupItemKey(groupType: TaxonomicFilterGroupType, value: TaxonomicFilterValue): string | null {+ return value == null ? null : `${groupType}::${value}`+}++export function recentSourceKey(item: TaxonomicDefinitionTypes): string | null {+ return hasRecentContext(item)+ ? groupItemKey(item._recentContext.sourceGroupType, item._recentContext.sourceValue)+ : null+}++export function pinnedSourceKey(item: TaxonomicDefinitionTypes): string | null {+ return hasPinnedContext(item) ? groupItemKey(item._pinnedContext.sourceGroupType, item._pinnedContext.value) : null+}++// When a filter exposes a single substantive group there are no separate Recent/Pinned+// tabs to lean on, so the group's own list carries them: recent items (most-recent first)+// float to the top, then pinned, then everything else keeps its order. The list stays flat+// and deduped — each item appears once, because we reorder the group's own results in place+// rather than prepending copies. `keyOf` keys a group result the same way recent/pinned+// entries are keyed (via `groupItemKey`) so the tiers line up. Shared by the legacy+// `infiniteListLogic` and the rebuild `useGroupList`.+//+// A present synthetic aggregate row (e.g. "All events", whose value is null) leads and keeps+// its place — a promoted real item never displaces the group's own catch-all row. Skeletons+// and sparse-array holes (undefined, from a partially loaded legacy list) are left exactly+// where they are: they must never be keyed (`getValue(undefined)` throws) and must never+// float, so the virtualized loader's position math is preserved. Callers still gate the+// legacy path on a fully-loaded list; this is the defensive floor.+const LEADING_TIER = -1+const RECENT_TIER = 0+const PINNED_TIER = 1+const REST_TIER = 2++export function floatRecentAndPinnedToTop(+ items: (TaxonomicDefinitionTypes | SkeletonItem)[],+ keyOf: (item: TaxonomicDefinitionTypes) => string | null,+ recentItems: TaxonomicDefinitionTypes[],+ pinnedItems: TaxonomicDefinitionTypes[]+): (TaxonomicDefinitionTypes | SkeletonItem)[] {+ const recentRank = new Map<string, number>()+ recentItems.forEach((item, rank) => {+ const key = recentSourceKey(item)+ if (key != null && !recentRank.has(key)) {+ recentRank.set(key, rank)+ }+ })+ const pinnedKeys = new Set<string>()+ pinnedItems.forEach((item) => {+ const key = pinnedSourceKey(item)+ if (key != null) {+ pinnedKeys.add(key)+ }+ })+ if (recentRank.size === 0 && pinnedKeys.size === 0) {+ return items+ }+ return items+ .map((item, index) => {+ // Holes / skeletons stay put — never keyed (would throw), never floated.+ if (item == null || isSkeletonItem(item)) {+ return { item, index, tier: REST_TIER, rank: 0 }+ }+ const key = keyOf(item)+ if (key == null) {+ // Present synthetic aggregate row (e.g. "All events") — leads, keeps its place.+ return { item, index, tier: LEADING_TIER, rank: 0 }+ }+ const rank = recentRank.get(key)+ const tier = rank !== undefined ? RECENT_TIER : pinnedKeys.has(key) ? PINNED_TIER : REST_TIER+ return { item, index, tier, rank: rank ?? 0 }+ })+ .sort((a, b) => a.tier - b.tier || (a.tier === RECENT_TIER ? a.rank - b.rank : 0) || a.index - b.index)+ .map((entry) => entry.item)+}diff --git a/frontend/src/queries/nodes/EventsNode/EventName.tsx b/frontend/src/queries/nodes/EventsNode/EventName.tsxindex 06a8b03acd77..ec7c06c9c6de 100644--- a/frontend/src/queries/nodes/EventsNode/EventName.tsx+++ b/frontend/src/queries/nodes/EventsNode/EventName.tsx@@ -16,7 +16,7 @@ export function EventName({ query, setQuery }: EventNameProps): JSX.Element {disabled={!setQuery}onChange={(value) => setQuery?.({ ...query, event: value })}allEventsOption="clear"- groupTypes={[TaxonomicFilterGroupType.SuggestedFilters, TaxonomicFilterGroupType.Events]}+ groupTypes={[TaxonomicFilterGroupType.Events]}/>)}