: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(navigation): extract layout modes into readable modules (#124231)
Fernando Gomes44e2318cb3e9
diff --git a/frontend/src/layout/navigation-3000/Navigation.tsx b/frontend/src/layout/navigation-3000/Navigation.tsxindex 013cebd44df8..8cf160385db9 100644--- a/frontend/src/layout/navigation-3000/Navigation.tsx+++ b/frontend/src/layout/navigation-3000/Navigation.tsx@@ -1,43 +1,24 @@import './Navigation.scss'-import { useActions, useMountedLogic, useValues } from 'kea'-import { ReactNode, Suspense, useCallback, useEffect, useLayoutEffect, useRef } from 'react'+import { useMountedLogic, useValues } from 'kea'+import { ReactNode, useLayoutEffect } from 'react'import { mcpHintLogic } from 'lib/components/MCPHint/mcpHintLogic'-import { ScrollableShadows } from 'lib/components/ScrollableShadows/ScrollableShadows'-import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'-import { cn } from 'lib/utils/css-classes'-import { lazyWithRetry } from 'lib/utils/retryImport'import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'-import { sceneLogic } from 'scenes/sceneLogic'-import { Scene, SceneConfig } from 'scenes/sceneTypes'+import { SceneConfig } from 'scenes/sceneTypes'-import { PanelLayout } from '~/layout/panel-layout/PanelLayout'-import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'-import { ProjectDragAndDropProvider } from '~/layout/panel-layout/ProjectTree/ProjectDragAndDropContext'import { todayPanelChatSessionLogic } from '~/layout/today/todayPanelChatSessionLogic'-import { TODAY_RAIL_WIDTH, todayShellLogic } from '~/layout/today/todayShellLogic'--import { navigationLogic } from '../navigation/navigationLogic'-import { ProjectNotice } from '../navigation/ProjectNotice'-import { SceneTitlePanelButton } from '../scenes/components/SceneTitlePanelButton'-import { SceneLayout } from '../scenes/SceneLayout'-import { sceneLayoutLogic } from '../scenes/sceneLayoutLogic'-import { MinimalNavigation } from './components/MinimalNavigation'+import { todayShellLogic } from '~/layout/today/todayShellLogic'++import { BareLayout } from './layout-modes/BareLayout'+import { ClassicLayout } from './layout-modes/ClassicLayout'+import { EmbeddedLayout } from './layout-modes/EmbeddedLayout'+import { MinimalLayout } from './layout-modes/MinimalLayout'+import { TodayFramedLayout } from './layout-modes/TodayFramedLayout'+import { TodayPhoneLayout } from './layout-modes/TodayPhoneLayout'+import { ZenLayout } from './layout-modes/ZenLayout'+import { resolveLayoutMode } from './layoutMode'import { navigation3000Logic } from './navigationLogic'-import { SidePanel } from './sidepanel/SidePanel'-import { sidePanelStateLogic } from './sidepanel/sidePanelStateLogic'-import { themeLogic } from './themeLogic'--// The Today layout renders only behind the today-rail-nav flag, and its quill UI would otherwise load on every logged-in page.-const TodayContextPanelFloating = lazyWithRetry(() =>- import('~/layout/today/TodayContextPanelFloating').then((m) => ({ default: m.TodayContextPanelFloating }))-)-const TodayShell = lazyWithRetry(() => import('~/layout/today/TodayShell').then((m) => ({ default: m.TodayShell })))-const TodaySidePanel = lazyWithRetry(() =>- import('~/layout/today/TodaySidePanel').then((m) => ({ default: m.TodaySidePanel }))-)-const TodayTopBar = lazyWithRetry(() => import('~/layout/today/TodayTopBar').then((m) => ({ default: m.TodayTopBar })))export function Navigation({children,@@ -49,323 +30,50 @@ export function Navigation({useMountedLogic(maxGlobalLogic)useMountedLogic(mcpHintLogic)- const { theme } = useValues(themeLogic)- const { mobileLayout } = useValues(navigationLogic)const { mode } = useValues(navigation3000Logic)- const mainRef = useRef<HTMLElement>(null)- const { mainContentRect, isLayoutNavCollapsed, isLayoutPanelVisible, navbarWidth } = useValues(panelLayoutLogic)- const { setMainContentRef, setMainContentRect } = useActions(panelLayoutLogic)- const { activeSceneId } = useValues(sceneLogic)- const { registerScenePanelElement, registerSceneTakeoverElement } = useActions(sceneLayoutLogic)- const { scenePanelIsPresent, scenePanelOpenManual, sceneTakeoverActive } = useValues(sceneLayoutLogic)- const { sidePanelOpen } = useValues(sidePanelStateLogic)- const { sidePanelWidth } = useValues(panelLayoutLogic)- const {- leftNavWidth: todayLeftNavWidth,- todayRailEnabled: todayRail,- sidebarVisible: todaySidebarVisible,- phoneLayout: todayPhoneLayout,- phoneHeaderHidden: todayPhoneHeaderHidden,- onAiPage: todayOnAiPage,- } = useValues(todayShellLogic)- const todayDrawerOpen = todayRail && mobileLayout && todaySidebarVisible- const todayPhone = todayRail && todayPhoneLayout- const todayFramed = todayRail && !todayPhone- // The framed Today layout gives the side panel its own grid column, so the panel no longer overlaps the scene.- const sidePanelOverlapsMain = sidePanelOpen && !todayFramed-- // SceneMenuBar (when enabled) replaces ProjectNotice's role of conveying project-level- // context above scene content, so we hide the notice for users on the new menu bar.- const sceneMenuBarEnabled = useFeatureFlag('SCENE_MENU_BAR')- const inlinePanelRef = useRef<HTMLDivElement | null>(null)- const inlinePanelCallbackRef = useCallback(- (node: HTMLDivElement | null) => {- inlinePanelRef.current = node- registerScenePanelElement(node)- },- [registerScenePanelElement]- )-- // SidePanelInfo overrides scenePanelElement while the Info tab is open and- // clears it on unmount, leaving it null even though Navigation's inline- // panel div is still in the DOM. Re-register it when the side panel closes.- useEffect(() => {- if (!sidePanelOpen && inlinePanelRef.current) {- registerScenePanelElement(inlinePanelRef.current)- }- }, [sidePanelOpen, registerScenePanelElement])-- // Null the registration on Navigation unmount so the detached inline- // panel div is not pinned by sceneLayoutLogic's reducer. Kept in its own- // empty-deps effect so it fires only on final unmount, not on every- // sidePanelOpen toggle (which would briefly blank SceneLayout's portal).- useEffect(() => {- return () => {- registerScenePanelElement(null)- }- }, [registerScenePanelElement])-- // Unlike the inline panel above, nothing else ever overrides this registration, so the- // callback ref's own null call on unmount is enough cleanup.- const takeoverCallbackRef = useCallback(- (node: HTMLDivElement | null) => registerSceneTakeoverElement(node),- [registerSceneTakeoverElement]- )-- const deferSceneMeasurementsDuringResize = sceneConfig?.deferSceneMeasurementsDuringResize ?? false+ const { todayRailEnabled: todayRail, phoneLayout } = useValues(todayShellLogic)- // Set container ref so we can measure the width of the scene layout in logic- useEffect(() => {- if (mainRef.current) {- setMainContentRef(mainRef, deferSceneMeasurementsDuringResize)- // Set main content rect so we can measure the width of the scene layout in logic- setMainContentRect(mainRef.current.getBoundingClientRect())- }- }, [mainRef, setMainContentRef, setMainContentRect, deferSceneMeasurementsDuringResize])+ // Runs before scene effects, so a scene cannot clear the restored chat. TodayShell is lazy, so mount it here.+ useLayoutEffect(() => (todayRail ? todayPanelChatSessionLogic.mount() : undefined), [todayRail])- const noPaddingScene = sceneConfig?.layout === 'app-raw-no-header' || sceneConfig?.layout === 'app-raw'+ /**+ * 'Today' is the new scene shell for PostHog.+ *+ * Controlled under 'today-rail-nav' flag.+ */- // The chat session restores a saved run when it mounts. A layout effect runs before any scene's passive effect,- // so a scene that clears the panel on show (the AI-first composer) clears it after the restore. The lazy TodayShell- // loads too late to mount it.- useLayoutEffect(() => (todayRail ? todayPanelChatSessionLogic.mount() : undefined), [todayRail])+ const todayPhoneBodyClass = todayRail && phoneLayout && mode === 'full'- const todayPhoneBodyClass = todayPhone && mode === 'full'useLayoutEffect(() => {if (!todayPhoneBodyClass) {return}+document.body.classList.add('has-today-phone-layout')+return () => document.body.classList.remove('has-today-phone-layout')}, [todayPhoneBodyClass])- if (mode !== 'full') {- const showMinimalNavigation = mode === 'minimal' || mode === 'zen'- return (- // eslint-disable-next-line react/forbid-dom-props- <div- className="Navigation3000 flex-col"- style={- {- ...theme?.mainStyle,- // The MinimalNavigation bar sits above the scene, so push the- // settings scene's viewport-fixed nav down to clear it.- ...(showMinimalNavigation && {- '--settings-nav-top': 'calc(var(--minimal-navigation-height) + var(--scene-padding))',- }),- } as React.CSSProperties- }- >- {showMinimalNavigation && <MinimalNavigation />}- <main- className={- mode === 'zen'- ? '@container/main-content p-4'- : mode === 'embedded'- ? '@container/main-content min-h-screen p-4'- : mode === 'minimal' && sceneConfig?.layout !== 'plain'- ? '@container/main-content flex flex-col p-4'- : undefined- }- >- {children}- </main>- </div>- )+ const layoutMode = resolveLayoutMode({+ mode,+ todayRail,+ phoneLayout,+ })++ switch (layoutMode) {+ case 'bare':+ return <BareLayout>{children}</BareLayout>+ case 'minimal':+ return <MinimalLayout sceneConfig={sceneConfig}>{children}</MinimalLayout>+ case 'zen':+ return <ZenLayout>{children}</ZenLayout>+ case 'embedded':+ return <EmbeddedLayout>{children}</EmbeddedLayout>+ case 'classic':+ return <ClassicLayout sceneConfig={sceneConfig}>{children}</ClassicLayout>+ case 'today-framed':+ return <TodayFramedLayout sceneConfig={sceneConfig}>{children}</TodayFramedLayout>+ case 'today-phone':+ return <TodayPhoneLayout sceneConfig={sceneConfig}>{children}</TodayPhoneLayout>}-- return (- <>- {/* eslint-disable-next-line react/forbid-elements */}- <a- href="#main-content"- className="sr-only focus:not-sr-only focus:fixed focus:z-top focus:top-4 focus:left-4 focus:p-4 focus:bg-white focus:dark:bg-gray-800 focus:rounded focus:shadow-lg"- tabIndex={0}- >- Skip to content- </a>- <div- className={cn('app-layout bg-surface-tertiary', {- 'app-layout--mobile': (mobileLayout && !todayRail) || todayPhone,- 'TodayAppLayout scrollbar-thin scrollbar-track-transparent scrollbar-thumb-[var(--color-bg-fill-scroll-thumb)]':- todayRail,- 'TodayAppLayout--phone': todayPhone,- 'TodayAppLayout--top-bar': todayFramed,- 'TodayAppLayout--no-phone-header': todayPhoneHeaderHidden,- })}- style={- {- ...theme?.mainStyle,- // The Today layout keeps one background on every scene, so it leaves out the notebook canvas.- '--scene-layout-background':- sceneConfig?.canvasBackground && !todayRail- ? 'var(--color-bg-surface-primary)'- : 'var(--color-bg-primary)',- '--side-panel-width': sidePanelWidth + 'px',- '--project-navbar-width':- !mobileLayout && !isLayoutNavCollapsed ? `${navbarWidth}px` : undefined,- '--today-rail-width': todayRail ? `${TODAY_RAIL_WIDTH}px` : undefined,- '--left-nav-width': todayRail- ? `${todayLeftNavWidth}px`- : isLayoutNavCollapsed- ? 'var(--project-navbar-width-collapsed)'- : 'var(--project-navbar-width)',- } as React.CSSProperties- }- >- <ProjectDragAndDropProvider>- {todayFramed && (- <Suspense fallback={null}>- <TodayTopBar />- </Suspense>- )}- {todayRail ? (- <Suspense fallback={null}>- <TodayShell className="left-nav" />- </Suspense>- ) : (- <PanelLayout className="left-nav" />- )}- {todayFramed && <div aria-hidden className="TodayAppLayout__shadow" />}- {todayFramed && (- // The chrome token exists only inside a quill scope, so the backdrop that fills the gap above the frame carries data-quill.- <div data-quill aria-hidden className="TodayAppLayout__backdrop bg-[var(--chrome)]" />- )}-- <div- className={cn(- '@container/main-content-container main-content-container flex overflow-hidden border-primary relative [--left-nav-width:initial] [--project-navbar-width:initial]',- todayRail- ? todayFramed && [- 'TodayAppLayout__content',- // A docked sidebar owns the corner and the seam, so the content draws them only without one.- (mobileLayout || !todaySidebarVisible) && 'TodayAppLayout__content--corner',- sidePanelWidth > 0 && 'TodayAppLayout__content--side-panel',- ]- : [- 'lg:rounded border-t lg:border lg:mr-1 lg:mb-1 lg:mt-1',- sidePanelOpen && 'rounded-r-none',- ]- )}- {...(todayDrawerOpen ? { inert: '' } : {})}- style={- {- '--scene-layout-rect-right': mainContentRect?.right + 'px',- '--scene-layout-rect-width': mainContentRect?.width + 'px',- '--scene-layout-rect-height': mainContentRect?.height + 'px',- } as React.CSSProperties- }- >- {todayFramed && (- // The frame edge uses quill's border token so it matches the sidebar seam, and that token exists only inside a quill scope.- <div data-quill aria-hidden className="TodayAppLayout__frame" />- )}- <main- ref={mainRef}- role="main"- tabIndex={0}- id="main-content"- className={cn(- // The container rounds the corners. In Chrome, a rounded scroller that holds many canvases stops painting.- '@container/main-content bg-[var(--scene-layout-background)] overflow-y-auto overflow-x-hidden show-scrollbar-on-hover p-4 pb-0 h-full flex-1 focus-visible:outline-none flex flex-col',- {- 'p-0': noPaddingScene,- 'lg:max-w-[calc(100%-var(--side-panel-width))]': sidePanelOverlapsMain,- }- )}- >- <SceneLayout sceneConfig={sceneConfig}>- {/* While a takeover covers the scene its controls must leave the tab- order and the accessibility tree, or keyboard and screen-reader- users can operate them invisibly. The side panel stays outside the- wrapper: it renders beside the takeover and must stay usable. */}- {/* The attribute rides a spread with the empty-string form: React 18's- types lack `inert`, and its runtime serializes `inert={false}` to a- string, which is still inert (presence-based attribute). */}- <div- className="contents [--side-panel-width:initial]"- {...(sceneTakeoverActive ? { inert: '' } : {})}- >- {!sceneMenuBarEnabled && !sceneConfig?.hideProjectNotice && (- <div- className={cn({- 'px-4 empty:hidden': sceneConfig?.layout === 'app-raw-no-header',- // Settings scene's nav is viewport-fixed on desktop, so the- // banner needs to clear it (nav width + column gap) to align- // with the settings content column.- 'md:ml-[calc(var(--settings-nav-width)+2rem)]':- activeSceneId === Scene.Settings,- })}- >- <ProjectNotice- className={cn('my-0 mb-4', {- 'mt-4': noPaddingScene,- })}- />- </div>- )}- {children}- </div>- {!todayFramed && <SidePanel />}- </SceneLayout>- </main>-- {/* Scene takeover host: fullscreen-in-scene surfaces (the email editor)- portal here to fill the main well at full height, while the navigation- stays visible and the side panel stays usable beside it (z-50 keeps this- under the side panel). Mirrors main's max-width shrink so it never sits- underneath the open side panel. */}- <div- ref={takeoverCallbackRef}- tabIndex={-1}- className={cn(- 'absolute inset-0 z-50 bg-[var(--scene-layout-background)] flex flex-col outline-none',- {- hidden: !sceneTakeoverActive,- 'lg:max-w-[calc(100%-var(--side-panel-width))]': sidePanelOverlapsMain,- }- )}- />-- {scenePanelIsPresent && (- <>- <div- className={cn(- 'scene-layout__content-panel starting:w-0 bg-surface-secondary flex flex-col overflow-hidden h-full min-w-0',- 'absolute right-0 top-0 @[1200px]/main-content-container:relative @[1200px]/main-content-container:right-auto @[1200px]/main-content-container:top-auto',- {- hidden: !scenePanelOpenManual,- 'z-1': isLayoutPanelVisible,- }- )}- >- <div className="h-[50px] flex items-center justify-end gap-2 -mx-2 px-4 py-2 border-b border-primary shrink-0">- <SceneTitlePanelButton />- </div>- <ScrollableShadows- direction="vertical"- className="grow flex-1"- innerClassName="px-2 py-2 bg-primary"- styledScrollbars- >- <div ref={inlinePanelCallbackRef} />- </ScrollableShadows>- </div>- </>- )}- {todayFramed && !todayOnAiPage && (- <Suspense fallback={null}>- <TodayContextPanelFloating />- </Suspense>- )}- </div>- {todayFramed && (- <Suspense fallback={null}>- <TodaySidePanel />- </Suspense>- )}- </ProjectDragAndDropProvider>- </div>- </>- )}diff --git a/frontend/src/layout/navigation-3000/components/FullLayoutFrame.tsx b/frontend/src/layout/navigation-3000/components/FullLayoutFrame.tsxnew file mode 100644index 000000000000..535df8b317ec--- /dev/null+++ b/frontend/src/layout/navigation-3000/components/FullLayoutFrame.tsx@@ -0,0 +1,41 @@+import { useValues } from 'kea'+import { CSSProperties, ReactNode } from 'react'++import { cn } from 'lib/utils/css-classes'++import { ProjectDragAndDropProvider } from '~/layout/panel-layout/ProjectTree/ProjectDragAndDropContext'++import { themeLogic } from '../themeLogic'++/** Outer frame for the layouts with the app chrome. */+export function FullLayoutFrame({+ className,+ style,+ children,+}: {+ className?: string+ style?: CSSProperties+ children: ReactNode+}): JSX.Element {+ const { theme } = useValues(themeLogic)++ return (+ <>+ {/* eslint-disable-next-line react/forbid-elements */}+ <a+ href="#main-content"+ className="sr-only focus:not-sr-only focus:fixed focus:z-top focus:top-4 focus:left-4 focus:p-4 focus:bg-white focus:dark:bg-gray-800 focus:rounded focus:shadow-lg"+ tabIndex={0}+ >+ Skip to content+ </a>+ <div+ className={cn('app-layout bg-surface-tertiary', className)}+ // eslint-disable-next-line react/forbid-dom-props+ style={{ ...theme?.mainStyle, ...style } as CSSProperties}+ >+ <ProjectDragAndDropProvider>{children}</ProjectDragAndDropProvider>+ </div>+ </>+ )+}diff --git a/frontend/src/layout/navigation-3000/components/MainContentColumn.tsx b/frontend/src/layout/navigation-3000/components/MainContentColumn.tsxnew file mode 100644index 000000000000..2bb52513ca42--- /dev/null+++ b/frontend/src/layout/navigation-3000/components/MainContentColumn.tsx@@ -0,0 +1,99 @@+import { useActions, useValues } from 'kea'+import { CSSProperties, ReactNode, useEffect, useRef } from 'react'++import { cn } from 'lib/utils/css-classes'+import { SceneConfig } from 'scenes/sceneTypes'++import { panelLayoutLogic } from '../../panel-layout/panelLayoutLogic'+import { SceneLayout } from '../../scenes/SceneLayout'+import { sceneLayoutLogic } from '../../scenes/sceneLayoutLogic'+import { ProjectNoticeSlot } from './ProjectNoticeSlot'+import { ScenePanelColumn } from './ScenePanelColumn'+import { SceneTakeoverHost } from './SceneTakeoverHost'++export function MainContentColumn({+ children,+ sceneConfig,+ className,+ inert,+ frame,+ overlay,+ sidePanel,+ sidePanelOverlapsMain = false,+}: {+ children: ReactNode+ sceneConfig: SceneConfig | null+ className?: string+ inert?: boolean+ frame?: ReactNode+ overlay?: ReactNode+ sidePanel?: ReactNode+ sidePanelOverlapsMain?: boolean+}): JSX.Element {+ const { mainContentRect } = useValues(panelLayoutLogic)+ const { setMainContentRef, setMainContentRect } = useActions(panelLayoutLogic)+ const { sceneTakeoverActive } = useValues(sceneLayoutLogic)++ const mainRef = useRef<HTMLElement>(null)+ const deferSceneMeasurementsDuringResize = sceneConfig?.deferSceneMeasurementsDuringResize ?? false++ useEffect(() => {+ if (mainRef.current) {+ setMainContentRef(mainRef, deferSceneMeasurementsDuringResize)+ setMainContentRect(mainRef.current.getBoundingClientRect())+ }+ }, [mainRef, setMainContentRef, setMainContentRect, deferSceneMeasurementsDuringResize])++ const noPaddingScene = sceneConfig?.layout === 'app-raw-no-header' || sceneConfig?.layout === 'app-raw'++ return (+ <div+ className={cn(+ '@container/main-content-container main-content-container flex overflow-hidden border-primary relative [--left-nav-width:initial] [--project-navbar-width:initial]',+ className+ )}+ // React 18 types lack `inert`, and `inert={false}` still serializes to an inert element.+ {...(inert ? { inert: '' } : {})}+ // eslint-disable-next-line react/forbid-dom-props+ style={+ {+ '--scene-layout-rect-right': mainContentRect?.right + 'px',+ '--scene-layout-rect-width': mainContentRect?.width + 'px',+ '--scene-layout-rect-height': mainContentRect?.height + 'px',+ } as CSSProperties+ }+ >+ {frame}+ <main+ ref={mainRef}+ role="main"+ tabIndex={0}+ id="main-content"+ className={cn(+ // In Chrome, a rounded scroller that holds many canvases stops painting.+ '@container/main-content bg-[var(--scene-layout-background)] overflow-y-auto overflow-x-hidden show-scrollbar-on-hover p-4 pb-0 h-full flex-1 focus-visible:outline-none flex flex-col',+ {+ 'p-0': noPaddingScene,+ 'lg:max-w-[calc(100%-var(--side-panel-width))]': sidePanelOverlapsMain,+ }+ )}+ >+ <SceneLayout sceneConfig={sceneConfig}>+ {/* Controls under a takeover leave the tab order and the accessibility tree. The side panel stays usable. */}+ <div+ className="contents [--side-panel-width:initial]"+ {...(sceneTakeoverActive ? { inert: '' } : {})}+ >+ <ProjectNoticeSlot sceneConfig={sceneConfig} noPaddingScene={noPaddingScene} />+ {children}+ </div>+ {sidePanel}+ </SceneLayout>+ </main>++ <SceneTakeoverHost sidePanelOverlapsMain={sidePanelOverlapsMain} />+ <ScenePanelColumn />+ {overlay}+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/components/ProjectNoticeSlot.tsx b/frontend/src/layout/navigation-3000/components/ProjectNoticeSlot.tsxnew file mode 100644index 000000000000..842a8c680cbc--- /dev/null+++ b/frontend/src/layout/navigation-3000/components/ProjectNoticeSlot.tsx@@ -0,0 +1,40 @@+import { useValues } from 'kea'++import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'+import { cn } from 'lib/utils/css-classes'+import { sceneLogic } from 'scenes/sceneLogic'+import { Scene, SceneConfig } from 'scenes/sceneTypes'++import { ProjectNotice } from '../../navigation/ProjectNotice'++/** SceneMenuBar replaces the project notice, so hide the notice when the menu bar is on. */+export function ProjectNoticeSlot({+ sceneConfig,+ noPaddingScene,+}: {+ sceneConfig: SceneConfig | null+ noPaddingScene: boolean+}): JSX.Element | null {+ const sceneMenuBarEnabled = useFeatureFlag('SCENE_MENU_BAR')+ const { activeSceneId } = useValues(sceneLogic)++ if (sceneMenuBarEnabled || sceneConfig?.hideProjectNotice) {+ return null+ }++ return (+ <div+ className={cn({+ 'px-4 empty:hidden': sceneConfig?.layout === 'app-raw-no-header',+ // Clear the viewport-fixed settings nav so the banner aligns with the content column.+ 'md:ml-[calc(var(--settings-nav-width)+2rem)]': activeSceneId === Scene.Settings,+ })}+ >+ <ProjectNotice+ className={cn('my-0 mb-4', {+ 'mt-4': noPaddingScene,+ })}+ />+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/components/ScenePanelColumn.tsx b/frontend/src/layout/navigation-3000/components/ScenePanelColumn.tsxnew file mode 100644index 000000000000..1b9ce8868c8b--- /dev/null+++ b/frontend/src/layout/navigation-3000/components/ScenePanelColumn.tsx@@ -0,0 +1,69 @@+import { useActions, useValues } from 'kea'+import { useCallback, useEffect, useRef } from 'react'++import { ScrollableShadows } from 'lib/components/ScrollableShadows/ScrollableShadows'+import { cn } from 'lib/utils/css-classes'++import { panelLayoutLogic } from '../../panel-layout/panelLayoutLogic'+import { SceneTitlePanelButton } from '../../scenes/components/SceneTitlePanelButton'+import { sceneLayoutLogic } from '../../scenes/sceneLayoutLogic'+import { sidePanelStateLogic } from '../sidepanel/sidePanelStateLogic'++export function ScenePanelColumn(): JSX.Element | null {+ const { scenePanelIsPresent, scenePanelOpenManual } = useValues(sceneLayoutLogic)+ const { registerScenePanelElement } = useActions(sceneLayoutLogic)+ const { isLayoutPanelVisible } = useValues(panelLayoutLogic)+ const { sidePanelOpen } = useValues(sidePanelStateLogic)++ const inlinePanelRef = useRef<HTMLDivElement | null>(null)+ const inlinePanelCallbackRef = useCallback(+ (node: HTMLDivElement | null) => {+ inlinePanelRef.current = node+ registerScenePanelElement(node)+ },+ [registerScenePanelElement]+ )++ // SidePanelInfo clears the registration while open. Register this panel again when the side panel closes.+ useEffect(() => {+ if (!sidePanelOpen && inlinePanelRef.current) {+ registerScenePanelElement(inlinePanelRef.current)+ }+ }, [sidePanelOpen, registerScenePanelElement])++ // Clear the detached panel on unmount. A separate effect avoids blanking the portal on every side panel toggle.+ useEffect(() => {+ return () => {+ registerScenePanelElement(null)+ }+ }, [registerScenePanelElement])++ if (!scenePanelIsPresent) {+ return null+ }++ return (+ <div+ className={cn(+ 'scene-layout__content-panel starting:w-0 bg-surface-secondary flex flex-col overflow-hidden h-full min-w-0',+ 'absolute right-0 top-0 @[1200px]/main-content-container:relative @[1200px]/main-content-container:right-auto @[1200px]/main-content-container:top-auto',+ {+ hidden: !scenePanelOpenManual,+ 'z-1': isLayoutPanelVisible,+ }+ )}+ >+ <div className="h-[50px] flex items-center justify-end gap-2 -mx-2 px-4 py-2 border-b border-primary shrink-0">+ <SceneTitlePanelButton />+ </div>+ <ScrollableShadows+ direction="vertical"+ className="grow flex-1"+ innerClassName="px-2 py-2 bg-primary"+ styledScrollbars+ >+ <div ref={inlinePanelCallbackRef} />+ </ScrollableShadows>+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/components/SceneTakeoverHost.tsx b/frontend/src/layout/navigation-3000/components/SceneTakeoverHost.tsxnew file mode 100644index 000000000000..c96dcd28ba1c--- /dev/null+++ b/frontend/src/layout/navigation-3000/components/SceneTakeoverHost.tsx@@ -0,0 +1,29 @@+import { useActions, useValues } from 'kea'+import { useCallback } from 'react'++import { cn } from 'lib/utils/css-classes'++import { sceneLayoutLogic } from '../../scenes/sceneLayoutLogic'++/** Portal target for fullscreen-in-scene surfaces such as the email editor. */+export function SceneTakeoverHost({ sidePanelOverlapsMain }: { sidePanelOverlapsMain: boolean }): JSX.Element {+ const { registerSceneTakeoverElement } = useActions(sceneLayoutLogic)+ const { sceneTakeoverActive } = useValues(sceneLayoutLogic)++ // Nothing else overrides this registration, so the ref's null call on unmount cleans up.+ const takeoverCallbackRef = useCallback(+ (node: HTMLDivElement | null) => registerSceneTakeoverElement(node),+ [registerSceneTakeoverElement]+ )++ return (+ <div+ ref={takeoverCallbackRef}+ tabIndex={-1}+ className={cn('absolute inset-0 z-50 bg-[var(--scene-layout-background)] flex flex-col outline-none', {+ hidden: !sceneTakeoverActive,+ 'lg:max-w-[calc(100%-var(--side-panel-width))]': sidePanelOverlapsMain,+ })}+ />+ )+}diff --git a/frontend/src/layout/navigation-3000/components/SimpleLayoutFrame.tsx b/frontend/src/layout/navigation-3000/components/SimpleLayoutFrame.tsxnew file mode 100644index 000000000000..fc0cc32bb3fb--- /dev/null+++ b/frontend/src/layout/navigation-3000/components/SimpleLayoutFrame.tsx@@ -0,0 +1,36 @@+import { useValues } from 'kea'+import { CSSProperties, ReactNode } from 'react'++import { themeLogic } from '../themeLogic'++/** Outer frame for the layouts without app chrome. */+export function SimpleLayoutFrame({+ nav,+ mainClassName,+ children,+}: {+ nav?: ReactNode+ mainClassName?: string+ children: ReactNode+}): JSX.Element {+ const { theme } = useValues(themeLogic)++ return (+ // eslint-disable-next-line react/forbid-dom-props+ <div+ className="Navigation3000 flex-col"+ style={+ {+ ...theme?.mainStyle,+ // MinimalNavigation sits above the scene, so the fixed settings nav must clear it.+ ...(nav && {+ '--settings-nav-top': 'calc(var(--minimal-navigation-height) + var(--scene-padding))',+ }),+ } as CSSProperties+ }+ >+ {nav}+ <main className={mainClassName}>{children}</main>+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/BareLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/BareLayout.tsxnew file mode 100644index 000000000000..12a15d4a748b--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/BareLayout.tsx@@ -0,0 +1,7 @@+import { ReactNode } from 'react'++import { SimpleLayoutFrame } from '../components/SimpleLayoutFrame'++export function BareLayout({ children }: { children: ReactNode }): JSX.Element {+ return <SimpleLayoutFrame>{children}</SimpleLayoutFrame>+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/ClassicLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/ClassicLayout.tsxnew file mode 100644index 000000000000..a0a491725405--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/ClassicLayout.tsx@@ -0,0 +1,55 @@+import { useValues } from 'kea'+import { CSSProperties, ReactNode } from 'react'++import { cn } from 'lib/utils/css-classes'+import { SceneConfig } from 'scenes/sceneTypes'++import { navigationLogic } from '../../navigation/navigationLogic'+import { PanelLayout } from '../../panel-layout/PanelLayout'+import { panelLayoutLogic } from '../../panel-layout/panelLayoutLogic'+import { FullLayoutFrame } from '../components/FullLayoutFrame'+import { MainContentColumn } from '../components/MainContentColumn'+import { SidePanel } from '../sidepanel/SidePanel'+import { sidePanelStateLogic } from '../sidepanel/sidePanelStateLogic'++export function ClassicLayout({+ children,+ sceneConfig,+}: {+ children: ReactNode+ sceneConfig: SceneConfig | null+}): JSX.Element {+ const { mobileLayout } = useValues(navigationLogic)+ const { isLayoutNavCollapsed, navbarWidth, sidePanelWidth } = useValues(panelLayoutLogic)+ const { sidePanelOpen } = useValues(sidePanelStateLogic)++ return (+ <FullLayoutFrame+ className={cn({ 'app-layout--mobile': mobileLayout })}+ style={+ {+ '--scene-layout-background': sceneConfig?.canvasBackground+ ? 'var(--color-bg-surface-primary)'+ : 'var(--color-bg-primary)',+ '--side-panel-width': sidePanelWidth + 'px',+ '--project-navbar-width': !mobileLayout && !isLayoutNavCollapsed ? `${navbarWidth}px` : undefined,+ '--left-nav-width': isLayoutNavCollapsed+ ? 'var(--project-navbar-width-collapsed)'+ : 'var(--project-navbar-width)',+ } as CSSProperties+ }+ >+ <PanelLayout className="left-nav" />+ <MainContentColumn+ sceneConfig={sceneConfig}+ className={cn('lg:rounded border-t lg:border lg:mr-1 lg:mb-1 lg:mt-1', {+ 'rounded-r-none': sidePanelOpen,+ })}+ sidePanel={<SidePanel />}+ sidePanelOverlapsMain={sidePanelOpen}+ >+ {children}+ </MainContentColumn>+ </FullLayoutFrame>+ )+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/EmbeddedLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/EmbeddedLayout.tsxnew file mode 100644index 000000000000..3bdb5ee0ed6e--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/EmbeddedLayout.tsx@@ -0,0 +1,7 @@+import { ReactNode } from 'react'++import { SimpleLayoutFrame } from '../components/SimpleLayoutFrame'++export function EmbeddedLayout({ children }: { children: ReactNode }): JSX.Element {+ return <SimpleLayoutFrame mainClassName="@container/main-content min-h-screen p-4">{children}</SimpleLayoutFrame>+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/MinimalLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/MinimalLayout.tsxnew file mode 100644index 000000000000..286664e88268--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/MinimalLayout.tsx@@ -0,0 +1,23 @@+import { ReactNode } from 'react'++import { SceneConfig } from 'scenes/sceneTypes'++import { MinimalNavigation } from '../components/MinimalNavigation'+import { SimpleLayoutFrame } from '../components/SimpleLayoutFrame'++export function MinimalLayout({+ children,+ sceneConfig,+}: {+ children: ReactNode+ sceneConfig: SceneConfig | null+}): JSX.Element {+ return (+ <SimpleLayoutFrame+ nav={<MinimalNavigation />}+ mainClassName={sceneConfig?.layout !== 'plain' ? '@container/main-content flex flex-col p-4' : undefined}+ >+ {children}+ </SimpleLayoutFrame>+ )+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/TodayFramedLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/TodayFramedLayout.tsxnew file mode 100644index 000000000000..1ef313205da7--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/TodayFramedLayout.tsx@@ -0,0 +1,86 @@+import { useValues } from 'kea'+import { CSSProperties, ReactNode, Suspense } from 'react'++import { cn } from 'lib/utils/css-classes'+import { lazyWithRetry } from 'lib/utils/retryImport'+import { SceneConfig } from 'scenes/sceneTypes'++import { navigationLogic } from '../../navigation/navigationLogic'+import { panelLayoutLogic } from '../../panel-layout/panelLayoutLogic'+import { TODAY_RAIL_WIDTH, todayShellLogic } from '../../today/todayShellLogic'+import { FullLayoutFrame } from '../components/FullLayoutFrame'+import { MainContentColumn } from '../components/MainContentColumn'++// Load the Today UI only behind the flag, so quill does not load on every page.+const TodayContextPanelFloating = lazyWithRetry(() =>+ import('~/layout/today/TodayContextPanelFloating').then((m) => ({ default: m.TodayContextPanelFloating }))+)+const TodayShell = lazyWithRetry(() => import('~/layout/today/TodayShell').then((m) => ({ default: m.TodayShell })))+const TodaySidePanel = lazyWithRetry(() =>+ import('~/layout/today/TodaySidePanel').then((m) => ({ default: m.TodaySidePanel }))+)+const TodayTopBar = lazyWithRetry(() => import('~/layout/today/TodayTopBar').then((m) => ({ default: m.TodayTopBar })))++export function TodayFramedLayout({+ children,+ sceneConfig,+}: {+ children: ReactNode+ sceneConfig: SceneConfig | null+}): JSX.Element {+ const { mobileLayout } = useValues(navigationLogic)+ const { isLayoutNavCollapsed, navbarWidth, sidePanelWidth } = useValues(panelLayoutLogic)+ const { leftNavWidth, onAiPage, sidebarVisible } = useValues(todayShellLogic)++ const drawerOpen = mobileLayout && sidebarVisible++ return (+ <FullLayoutFrame+ className="TodayAppLayout scrollbar-thin scrollbar-track-transparent scrollbar-thumb-[var(--color-bg-fill-scroll-thumb)] TodayAppLayout--top-bar"+ style={+ {+ '--scene-layout-background': 'var(--color-bg-primary)',+ '--side-panel-width': sidePanelWidth + 'px',+ '--project-navbar-width': !mobileLayout && !isLayoutNavCollapsed ? `${navbarWidth}px` : undefined,+ '--today-rail-width': `${TODAY_RAIL_WIDTH}px`,+ '--left-nav-width': `${leftNavWidth}px`,+ } as CSSProperties+ }+ >+ <Suspense fallback={null}>+ <TodayTopBar />+ </Suspense>+ <Suspense fallback={null}>+ <TodayShell className="left-nav" />+ </Suspense>+ <div aria-hidden className="TodayAppLayout__shadow" />+ {/* The chrome token exists only in a quill scope, so the backdrop carries data-quill. */}+ <div data-quill aria-hidden className="TodayAppLayout__backdrop bg-[var(--chrome)]" />++ <MainContentColumn+ sceneConfig={sceneConfig}+ className={cn('TodayAppLayout__content', {+ // A docked sidebar draws the corner and the seam.+ 'TodayAppLayout__content--corner': mobileLayout || !sidebarVisible,+ 'TodayAppLayout__content--side-panel': sidePanelWidth > 0,+ })}+ inert={drawerOpen}+ // The frame uses quill's border token to match the sidebar seam.+ frame={<div data-quill aria-hidden className="TodayAppLayout__frame" />}+ overlay={+ !onAiPage && (+ <Suspense fallback={null}>+ <TodayContextPanelFloating />+ </Suspense>+ )+ }+ >+ {children}+ </MainContentColumn>++ <Suspense fallback={null}>+ <TodaySidePanel />+ </Suspense>+ </FullLayoutFrame>+ )+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/TodayPhoneLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/TodayPhoneLayout.tsxnew file mode 100644index 000000000000..3e81aa6b29fd--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/TodayPhoneLayout.tsx@@ -0,0 +1,62 @@+import { useValues } from 'kea'+import { CSSProperties, ReactNode, Suspense } from 'react'++import { cn } from 'lib/utils/css-classes'+import { lazyWithRetry } from 'lib/utils/retryImport'+import { SceneConfig } from 'scenes/sceneTypes'++import { navigationLogic } from '../../navigation/navigationLogic'+import { panelLayoutLogic } from '../../panel-layout/panelLayoutLogic'+import { TODAY_RAIL_WIDTH, todayShellLogic } from '../../today/todayShellLogic'+import { FullLayoutFrame } from '../components/FullLayoutFrame'+import { MainContentColumn } from '../components/MainContentColumn'+import { SidePanel } from '../sidepanel/SidePanel'+import { sidePanelStateLogic } from '../sidepanel/sidePanelStateLogic'++const TodayShell = lazyWithRetry(() => import('~/layout/today/TodayShell').then((m) => ({ default: m.TodayShell })))++export function TodayPhoneLayout({+ children,+ sceneConfig,+}: {+ children: ReactNode+ sceneConfig: SceneConfig | null+}): JSX.Element {+ const { mobileLayout } = useValues(navigationLogic)+ const { isLayoutNavCollapsed, navbarWidth, sidePanelWidth } = useValues(panelLayoutLogic)+ const { leftNavWidth, phoneHeaderHidden, sidebarVisible } = useValues(todayShellLogic)+ const { sidePanelOpen } = useValues(sidePanelStateLogic)++ const drawerOpen = mobileLayout && sidebarVisible++ return (+ <FullLayoutFrame+ className={cn(+ 'app-layout--mobile TodayAppLayout scrollbar-thin scrollbar-track-transparent scrollbar-thumb-[var(--color-bg-fill-scroll-thumb)] TodayAppLayout--phone',+ { 'TodayAppLayout--no-phone-header': phoneHeaderHidden }+ )}+ style={+ {+ '--scene-layout-background': 'var(--color-bg-primary)',+ '--side-panel-width': sidePanelWidth + 'px',+ '--project-navbar-width': !mobileLayout && !isLayoutNavCollapsed ? `${navbarWidth}px` : undefined,+ '--today-rail-width': `${TODAY_RAIL_WIDTH}px`,+ '--left-nav-width': `${leftNavWidth}px`,+ } as CSSProperties+ }+ >+ <Suspense fallback={null}>+ <TodayShell className="left-nav" />+ </Suspense>++ <MainContentColumn+ sceneConfig={sceneConfig}+ inert={drawerOpen}+ sidePanel={<SidePanel />}+ sidePanelOverlapsMain={sidePanelOpen}+ >+ {children}+ </MainContentColumn>+ </FullLayoutFrame>+ )+}diff --git a/frontend/src/layout/navigation-3000/layout-modes/ZenLayout.tsx b/frontend/src/layout/navigation-3000/layout-modes/ZenLayout.tsxnew file mode 100644index 000000000000..512d35eec959--- /dev/null+++ b/frontend/src/layout/navigation-3000/layout-modes/ZenLayout.tsx@@ -0,0 +1,12 @@+import { ReactNode } from 'react'++import { MinimalNavigation } from '../components/MinimalNavigation'+import { SimpleLayoutFrame } from '../components/SimpleLayoutFrame'++export function ZenLayout({ children }: { children: ReactNode }): JSX.Element {+ return (+ <SimpleLayoutFrame nav={<MinimalNavigation />} mainClassName="@container/main-content p-4">+ {children}+ </SimpleLayoutFrame>+ )+}diff --git a/frontend/src/layout/navigation-3000/layoutMode.test.ts b/frontend/src/layout/navigation-3000/layoutMode.test.tsnew file mode 100644index 000000000000..000298da0c5d--- /dev/null+++ b/frontend/src/layout/navigation-3000/layoutMode.test.ts@@ -0,0 +1,16 @@+import { resolveLayoutMode } from './layoutMode'++describe('resolveLayoutMode', () => {+ it.each([+ ['none', false, false, 'bare'],+ ['minimal', false, false, 'minimal'],+ ['zen', false, false, 'zen'],+ ['embedded', false, false, 'embedded'],+ ['full', false, false, 'classic'],+ ['full', false, true, 'classic'],+ ['full', true, false, 'today-framed'],+ ['full', true, true, 'today-phone'],+ ] as const)('maps mode %s with todayRail %s and phoneLayout %s to %s', (mode, todayRail, phoneLayout, expected) => {+ expect(resolveLayoutMode({ mode, todayRail, phoneLayout })).toBe(expected)+ })+})diff --git a/frontend/src/layout/navigation-3000/layoutMode.ts b/frontend/src/layout/navigation-3000/layoutMode.tsnew file mode 100644index 000000000000..f0d36ff2badb--- /dev/null+++ b/frontend/src/layout/navigation-3000/layoutMode.ts@@ -0,0 +1,30 @@+import type { Navigation3000Mode } from './navigationLogic'++/** The page layout. Splits `Navigation3000Mode`'s `full` into classic and the two Today forms. */+export type LayoutMode = 'bare' | 'minimal' | 'zen' | 'embedded' | 'classic' | 'today-framed' | 'today-phone'++export function resolveLayoutMode({+ mode,+ todayRail,+ phoneLayout,+}: {+ mode: Navigation3000Mode+ todayRail: boolean+ phoneLayout: boolean+}): LayoutMode {+ switch (mode) {+ case 'none':+ return 'bare'+ case 'minimal':+ return 'minimal'+ case 'zen':+ return 'zen'+ case 'embedded':+ return 'embedded'+ case 'full':+ if (!todayRail) {+ return 'classic'+ }+ return phoneLayout ? 'today-phone' : 'today-framed'+ }+}