: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
refactor(today): extract the nav product list into getNavProductItems (#112178)
Adam Leithba3e2e7b7964
diff --git a/frontend/src/layout/panel-layout/navbar/tabs/navProductItems.ts b/frontend/src/layout/panel-layout/navbar/tabs/navProductItems.tsnew file mode 100644index 000000000000..d109941fb902--- /dev/null+++ b/frontend/src/layout/panel-layout/navbar/tabs/navProductItems.ts@@ -0,0 +1,69 @@+import { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'+import { DEFINITIONS_TABS } from 'scenes/data-management/definitionsSceneTabsLogic'+import { urls } from 'scenes/urls'++import { FileSystemImport } from '~/queries/schema/schema-general'+import { ActivityTab } from '~/types'++import { getDefaultTreeData, getDefaultTreeProducts } from '../../ProjectTree/defaultTree'+import { POPULAR_CATEGORY, POPULAR_PRODUCT_PATHS } from './productsCatalog'++// These pages are tabs of Event definitions, so the sidebar lists only that entry for them.+const DEFINITIONS_TAB_HREFS = new Set(DEFINITIONS_TABS.filter((tab) => tab.key !== 'events').map((tab) => tab.url))++// Items in this category sit above Starred and All products, so they are never starred or grouped.+export const PINNED_CATEGORY = 'Project'++export function getNavProductItems(featureFlags: FeatureFlagsSet): FileSystemImport[] {+ const items: FileSystemImport[] = [+ {+ path: 'Home',+ category: PINNED_CATEGORY,+ iconType: 'home',+ href: urls.projectRoot(),+ visualOrder: 0,+ },+ {+ path: 'Activity',+ category: PINNED_CATEGORY,+ iconType: 'activity',+ href: urls.activity(ActivityTab.ExploreEvents),+ visualOrder: 2,+ },+ {+ path: 'Persons',+ displayLabel: 'People and groups',+ category: PINNED_CATEGORY,+ iconType: 'persons',+ href: urls.persons(),+ visualOrder: 3,+ },+ ...getDefaultTreeProducts().map(+ (item): FileSystemImport =>+ item.href === urls.inbox()+ ? {+ ...item,+ displayLabel: 'Self-driving',+ category: PINNED_CATEGORY,+ visualOrder: 1,+ }+ : item+ ),+ ...getDefaultTreeData(),+ ]+ const destinations = new Map<string, FileSystemImport>()+ for (const item of items) {+ if (+ !item.href ||+ DEFINITIONS_TAB_HREFS.has(item.href) ||+ (item.flag && !featureFlags[item.flag as keyof FeatureFlagsSet])+ ) {+ continue+ }+ const existing = destinations.get(item.href)+ destinations.set(item.href, existing ? { ...item, ...existing } : item)+ }+ return [...destinations.values()].map((item) =>+ POPULAR_PRODUCT_PATHS.includes(item.path) ? { ...item, category: POPULAR_CATEGORY } : item+ )+}diff --git a/frontend/src/layout/panel-layout/navbar/tabs/navProductsTabLogic.ts b/frontend/src/layout/panel-layout/navbar/tabs/navProductsTabLogic.tsindex 03a014709649..371e026e6400 100644--- a/frontend/src/layout/panel-layout/navbar/tabs/navProductsTabLogic.ts+++ b/frontend/src/layout/panel-layout/navbar/tabs/navProductsTabLogic.ts@@ -11,44 +11,29 @@ import { FeatureFlagsSet, featureFlagLogic } from 'lib/logic/featureFlagLogic'import { getProductAccessDisabledReason } from 'lib/utils/accessControlUtils'import { withTimeout } from 'lib/utils/async'import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'-import { DEFINITIONS_TABS } from 'scenes/data-management/definitionsSceneTabsLogic'import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { teamLogic } from 'scenes/teamLogic'-import { urls } from 'scenes/urls'import { fileSystemShortcutBulkUpdateCreate } from '~/generated/core/api'import { uiCustomizationLogic } from '~/layout/uiCustomizationLogic'import { FileSystemEntry, FileSystemImport, UserProductListItem } from '~/queries/schema/schema-general'-import { ActivityTab } from '~/types'import type { PreflightStatus } from '~/types'import * as decisionsApi from 'products/ml_inference/frontend/generated/api'import { customProductsLogic } from '../../ProjectTree/customProductsLogic'-import { getDefaultTreeData, getDefaultTreeProducts, withProductShortcutHref } from '../../ProjectTree/defaultTree'+import { withProductShortcutHref } from '../../ProjectTree/defaultTree'import { projectTreeDataLogic } from '../../ProjectTree/projectTreeDataLogic'import { projectTreeLogic } from '../../ProjectTree/projectTreeLogic'import { findProductShortcut, shortcutFromEntry } from '../../ProjectTree/utils'import { APP_MATCH_THRESHOLD, AppMatchGroups, buildAppRankingQuestions, readAppRankings } from './appRanking'-import {- POPULAR_CATEGORY,- POPULAR_PRODUCT_PATHS,- ProductsItemGroup,- groupProducts,- productMatchesSearch,- productsItemName,-} from './productsCatalog'+import { PINNED_CATEGORY, getNavProductItems } from './navProductItems'+import { ProductsItemGroup, groupProducts, productMatchesSearch, productsItemName } from './productsCatalog'// projectTreeLogic persists state under its logic key, so renaming this value resets it.export const PRODUCTS_STARRED_TREE_KEY = 'navbar-apps-starred'-// These pages are tabs of Event definitions, so the sidebar lists only that entry for them.-const DEFINITIONS_TAB_HREFS = new Set(DEFINITIONS_TABS.filter((tab) => tab.key !== 'events').map((tab) => tab.url))--// Items in this category sit above Starred and All products, so they are never starred or grouped.-const PINNED_CATEGORY = 'Project'-// `starred-setup` moves a user's custom products to starred products when they switch to the simple sidebar.export type CustomizeSidebarMode = 'customize' | 'starred-setup'@@ -540,59 +525,7 @@ export const navProductsTabLogic = kea<navProductsTabLogicType>([],allItems: [(s) => [s.featureFlags],- (featureFlags: FeatureFlagsSet): FileSystemImport[] => {- const items: FileSystemImport[] = [- {- path: 'Home',- category: PINNED_CATEGORY,- iconType: 'home',- href: urls.projectRoot(),- visualOrder: 0,- },- {- path: 'Activity',- category: PINNED_CATEGORY,- iconType: 'activity',- href: urls.activity(ActivityTab.ExploreEvents),- visualOrder: 2,- },- {- path: 'Persons',- displayLabel: 'People and groups',- category: PINNED_CATEGORY,- iconType: 'persons',- href: urls.persons(),- visualOrder: 3,- },- ...getDefaultTreeProducts().map(- (item): FileSystemImport =>- item.href === urls.inbox()- ? {- ...item,- displayLabel: 'Self-driving',- category: PINNED_CATEGORY,- visualOrder: 1,- }- : item- ),- ...getDefaultTreeData(),- ]- const destinations = new Map<string, FileSystemImport>()- for (const item of items) {- if (- !item.href ||- DEFINITIONS_TAB_HREFS.has(item.href) ||- (item.flag && !featureFlags[item.flag as keyof FeatureFlagsSet])- ) {- continue- }- const existing = destinations.get(item.href)- destinations.set(item.href, existing ? { ...item, ...existing } : item)- }- return [...destinations.values()].map((item) =>- POPULAR_PRODUCT_PATHS.includes(item.path) ? { ...item, category: POPULAR_CATEGORY } : item- )- },+ (featureFlags: FeatureFlagsSet): FileSystemImport[] => getNavProductItems(featureFlags),],pinnedItems: [(s) => [s.allItems, s.search],