: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
feat(today): add a back header to phone pages (#111195)
Shy Alter0aa15963c44b
diff --git a/frontend/src/layout/today/TodayPhoneHeader.tsx b/frontend/src/layout/today/TodayPhoneHeader.tsxnew file mode 100644index 000000000000..7ff3c782a7da--- /dev/null+++ b/frontend/src/layout/today/TodayPhoneHeader.tsx@@ -0,0 +1,51 @@+import { useActions, useValues } from 'kea'+import { useEffect, useState } from 'react'++import { IconChevronLeft } from '@posthog/icons'+import { Button, Text } from '@posthog/quill'++import { breadcrumbsLogic } from '~/layout/navigation/Breadcrumbs/breadcrumbsLogic'++import { todayShellLogic } from './todayShellLogic'++const TITLE_SCROLL_THRESHOLD = 56++export function TodayPhoneHeader(): JSX.Element {+ const { sceneBreadcrumbs } = useValues(breadcrumbsLogic)+ const { goBackOnPhone } = useActions(todayShellLogic)+ const [scrolled, setScrolled] = useState(false)+ const title = [...sceneBreadcrumbs].reverse().find((breadcrumb) => !!breadcrumb.name)?.name++ useEffect(() => {+ const main = document.getElementById('main-content')+ if (!main) {+ return+ }+ const onScroll = (): void => setScrolled(main.scrollTop > TITLE_SCROLL_THRESHOLD)+ onScroll()+ main.addEventListener('scroll', onScroll, { passive: true })+ return () => main.removeEventListener('scroll', onScroll)+ }, [title])++ return (+ <header className="TodayPhoneHeader" data-scrolled={scrolled} data-quill>+ <Button+ size="icon-lg"+ className="rounded-full"+ aria-label="Back"+ data-attr="today-phone-back"+ onClick={goBackOnPhone}+ >+ <IconChevronLeft />+ </Button>+ <Text+ render={<span />}+ weight="semibold"+ className="TodayPhoneHeader__title min-w-0 flex-1 truncate"+ aria-hidden={!scrolled}+ >+ {title}+ </Text>+ </header>+ )+}diff --git a/frontend/src/layout/today/TodayShell.scss b/frontend/src/layout/today/TodayShell.scssindex f60c89838808..f20e0c3a360f 100644--- a/frontend/src/layout/today/TodayShell.scss+++ b/frontend/src/layout/today/TodayShell.scss@@ -64,11 +64,47 @@}.TodayAppLayout--phone {+ --today-phone-header-height: 52px;--today-tab-bar-height: calc(76px + env(safe-area-inset-bottom));+ padding-top: var(--today-phone-header-height);padding-bottom: var(--today-tab-bar-height);}+.TodayPhoneHeader {+ position: fixed;+ top: 0;+ right: 0;+ left: 0;+ z-index: var(--z-layout-navbar);+ display: flex;+ gap: 4px;+ align-items: center;+ height: var(--today-phone-header-height);+ padding: 0 12px 0 8px;+ color: var(--today-ink);+ background: var(--today-paper);+ border-bottom: 1px solid transparent;+ transition: border-color 200ms var(--today-ease);++ &[data-scrolled='true'] {+ border-bottom-color: var(--today-line);+ }+}++.TodayPhoneHeader__title {+ opacity: 0;+ transition:+ opacity 200ms var(--today-ease),+ transform 200ms var(--today-ease);+ transform: translateY(4px);++ .TodayPhoneHeader[data-scrolled='true'] & {+ opacity: 1;+ transform: none;+ }+}+.TodayShell--phone {display: contents;}@@ -115,7 +151,9 @@ body:has(.TodayAppLayout--phone) .Toastify__toast-container--bottom-right {@media (prefers-reduced-motion: reduce) {.TodayShell__scrim,.TodayShell__drawer,- .TodayShell__page {+ .TodayShell__page,+ .TodayPhoneHeader,+ .TodayPhoneHeader__title {transition: none;}}diff --git a/frontend/src/layout/today/TodayShell.tsx b/frontend/src/layout/today/TodayShell.tsxindex 2d373b451fb6..a2973860a65e 100644--- a/frontend/src/layout/today/TodayShell.tsx+++ b/frontend/src/layout/today/TodayShell.tsx@@ -15,6 +15,7 @@ import { TodayHomeSidebar } from 'scenes/project-homepage/today/TodayHomeSidebarimport { QuillSceneHeader } from '~/layout/scenes/components/QuillSceneHeader'+import { TodayPhoneHeader } from './TodayPhoneHeader'import { TodayPreviewCardProvider } from './TodayPreviewCardProvider'import { TodayRail } from './TodayRail'import { todayRecentsLogic } from './todayRecentsLogic'@@ -140,6 +141,7 @@ export function TodayShell({ className }: { className?: string }): JSX.Element {return (<ToastProvider><div data-quill className={cn('Today TodayShell TodayShell--phone', className)}>+ {!sidebarVisible && <TodayPhoneHeader />}<asideref={drawerRef}tabIndex={-1}diff --git a/frontend/src/layout/today/todayShellLogic.test.ts b/frontend/src/layout/today/todayShellLogic.test.tsindex 729342b89e99..9047f04d0377 100644--- a/frontend/src/layout/today/todayShellLogic.test.ts+++ b/frontend/src/layout/today/todayShellLogic.test.ts@@ -132,4 +132,30 @@ describe('todayShellLogic', () => {Object.defineProperty(window, 'innerWidth', { configurable: true, value: originalWidth })}})++ it('on phone widths, goes back through pages and then to the pane', () => {+ const originalWidth = window.innerWidth+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: 390 })+ try {+ const logic = todayShellLogic()+ logic.mount()++ logic.actions.pickPane('tools')+ router.actions.push('/project/1/sql')+ router.actions.push('/project/1/sql?open_query=abc')+ router.actions.push('/project/1/insights/abc')+ expect(logic.values.sidebarVisible).toBe(false)++ logic.actions.goBackOnPhone()+ expect(router.values.location.pathname).toBe('/project/1/sql')+ expect(router.values.location.search).toBe('?open_query=abc')+ expect(logic.values.sidebarVisible).toBe(false)++ logic.actions.goBackOnPhone()+ expect(logic.values.sidebarVisible).toBe(true)+ expect(logic.values.activePane).toBe('tools')+ } finally {+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: originalWidth })+ }+ })})diff --git a/frontend/src/layout/today/todayShellLogic.ts b/frontend/src/layout/today/todayShellLogic.tsindex 5818cca31dff..c2ffa32b117e 100644--- a/frontend/src/layout/today/todayShellLogic.ts+++ b/frontend/src/layout/today/todayShellLogic.ts@@ -1,4 +1,4 @@-import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'import { router } from 'kea-router'import type { LocationChangedPayload } from 'kea-router/lib/types'import { subscriptions } from 'kea-subscriptions'@@ -45,6 +45,28 @@ const RAIL_PANE_HOME: Record<Exclude<TodayRailPane, 'more'>, () => string> = {tools: () => urls.tools(),}+const PHONE_PAGE_LIMIT = 50++export interface TodayPhonePage {+ pathname: string+ url: string+}++export function nextPhonePages(+ pages: TodayPhonePage[],+ method: LocationChangedPayload['method'],+ page: TodayPhonePage+): TodayPhonePage[] {+ const current = pages[pages.length - 1]+ if (method === 'PUSH' && current?.pathname !== page.pathname) {+ return [...pages, page].slice(-PHONE_PAGE_LIMIT)+ }+ if (method === 'POP' && pages[pages.length - 2]?.pathname === page.pathname) {+ return [...pages.slice(0, -2), page]+ }+ return [...pages.slice(0, -1), page]+}+/** The pane a route belongs to, or null for pages that keep whichever pane was open. */export function railPaneForPath(pathname: string): TodayRailPane | null {const path = removeProjectIdIfPresent(pathname)@@ -79,6 +101,7 @@ export interface todayShellLogicValues {leftNavWidth: numbermobileSidebarOpen: booleanphoneLayout: boolean+ phonePages: TodayPhonePage[]pickedPane: TodayRailPane | nullroutePane: TodayRailPane | nullsidebarOpen: boolean@@ -110,12 +133,18 @@ export interface todayShellLogicActions {searchParams: Record<string, any>url: string} // router+ goBackOnPhone: () => {+ value: true+ }pickPane: (pane: TodayRailPane) => {pane: TodayRailPane}setMobileSidebarOpen: (open: boolean) => {open: boolean}+ setPhonePages: (pages: TodayPhonePage[]) => {+ pages: TodayPhonePage[]+ }setSidebarOpen: (open: boolean) => {open: boolean}@@ -162,6 +191,8 @@ export const todayShellLogic = kea<todayShellLogicType>([})),actions({pickPane: (pane: TodayRailPane) => ({ pane }),+ goBackOnPhone: true,+ setPhonePages: (pages: TodayPhonePage[]) => ({ pages }),setMobileSidebarOpen: (open: boolean) => ({ open }),setSidebarOpen: (open: boolean) => ({ open }),setSidebarWidth: (width: number) => ({ width }),@@ -193,6 +224,15 @@ export const todayShellLogic = kea<todayShellLogicType>([locationChanged: () => false,},],+ phonePages: [+ [] as TodayPhonePage[],+ {+ setPhonePages: (_, { pages }) => pages,+ setMobileSidebarOpen: (state, { open }) => (open ? [] : state),+ locationChanged: (state, { method, pathname, search, hash }) =>+ nextPhonePages(state, method, { pathname, url: `${pathname}${search}${hash}` }),+ },+ ],// The resizer persists the width itself. This copy lets the app layout size the main column from it.sidebarWidth: [TODAY_SIDEBAR_DEFAULT_WIDTH, { setSidebarWidth: (_, { width }) => clampSidebarWidth(width) }],}),@@ -247,6 +287,15 @@ export const todayShellLogic = kea<todayShellLogicType>([return () => window.removeEventListener('keydown', onKeyDown)}, 'drawerEscape')},+ goBackOnPhone: () => {+ const previous = values.phonePages[values.phonePages.length - 2]+ if (!previous) {+ actions.setMobileSidebarOpen(true)+ return+ }+ actions.setPhonePages(values.phonePages.slice(0, -1))+ router.actions.replace(previous.url)+ },pickPane: ({ pane }) => {// pinned: analytics event name and property. Renaming them breaks dashboards.posthog.capture('today rail pane picked', { pane, phone_layout: values.phoneLayout })@@ -260,4 +309,8 @@ export const todayShellLogic = kea<todayShellLogicType>([}},})),+ afterMount(({ actions }) => {+ const { pathname, search, hash } = router.values.location+ actions.setPhonePages([{ pathname, url: `${pathname}${search}${hash}` }])+ }),])