: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(wizard): show wizard runs in the today more menu (#129132)
Fernando Gomes04e2557b0ea0
diff --git a/frontend/src/layout/today/TodayMoreMenu.tsx b/frontend/src/layout/today/TodayMoreMenu.tsxindex 849b5f96337d..2f8d8a7b2926 100644--- a/frontend/src/layout/today/TodayMoreMenu.tsx+++ b/frontend/src/layout/today/TodayMoreMenu.tsx@@ -1,4 +1,5 @@import { useActions, useValues } from 'kea'+import { Suspense, useState } from 'react'import { IconEllipsis, IconExternal, IconWarning } from '@posthog/icons'import {@@ -8,9 +9,13 @@ import {DropdownMenuSeparator,DropdownMenuTrigger,} from '@posthog/quill'+import { PostHogErrorBoundary } from '@posthog/react'import { helpMenuLogic } from 'lib/components/HelpMenu/helpMenuLogic'import { posthogStatusLogic } from 'lib/components/HelpMenu/posthogStatusLogic'+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'+import { lazyWithRetry } from 'lib/utils/retryImport'+import { projectLogic } from 'scenes/projectLogic'import { urls } from 'scenes/urls'import { todayMenuLinkItem } from './todayMenuLinkItem'@@ -18,6 +23,18 @@ import { SEVERITY_TEXT_CLASS } from './todayRailSeverity'import { todayRailStatusLogic } from './todayRailStatusLogic'import { TodayRailTile } from './TodayRailTile'+// Flag-gated, so users without the flag skip the wizard chunk.+const WizardRunsUnseenDot = lazyWithRetry(() =>+ import('products/wizard/frontend/views/run-sidebar/WizardRunsUnseenDot').then(({ WizardRunsUnseenDot }) => ({+ default: WizardRunsUnseenDot,+ }))+)+const WizardRunsMoreMenuItem = lazyWithRetry(() =>+ import('products/wizard/frontend/views/run-sidebar/WizardRunsMoreMenuItem').then(({ WizardRunsMoreMenuItem }) => ({+ default: WizardRunsMoreMenuItem,+ }))+)+/*** The rail's "More" menu. The help menu shortcut opens it too.* Its `data-attr`s are pinned: they match the classic help menu, so autocapture data stays continuous.@@ -28,6 +45,9 @@ export function TodayMoreMenu(): JSX.Element {const { statusPageUrl } = useValues(posthogStatusLogic)const { statusSeverity, statusText, healthSeverity, healthText, moreSeverity, moreLabel } =useValues(todayRailStatusLogic)+ const wizardUiEnabled = useFeatureFlag('WIZARD_UI_ENABLED')+ const { currentProjectId } = useValues(projectLogic)+ const [hasUnseenWizardRuns, setHasUnseenWizardRuns] = useState(false)return (<DropdownMenu open={isHelpMenuOpen} onOpenChange={setHelpMenuOpen}>@@ -36,16 +56,31 @@ export function TodayMoreMenu(): JSX.Element {<TodayRailTilelabel="More"icon={- statusSeverity === 'ok' ? (- <IconEllipsis />- ) : (- <IconWarning className={SEVERITY_TEXT_CLASS[statusSeverity]} />- )+ <>+ {statusSeverity === 'ok' ? (+ <IconEllipsis />+ ) : (+ <IconWarning className={SEVERITY_TEXT_CLASS[statusSeverity]} />+ )}+ {wizardUiEnabled &&+ currentProjectId !== null && (+ // A local boundary keeps a failed wizard chunk from reaching the shell's+ // ChunkLoadErrorBoundary, which reloads the whole app.+ <PostHogErrorBoundary fallback={<></>}>+ <Suspense fallback={null}>+ <WizardRunsUnseenDot+ projectId={String(currentProjectId)}+ onUnseenChange={setHasUnseenWizardRuns}+ />+ </Suspense>+ </PostHogErrorBoundary>+ )}+ </>}active={isHelpMenuOpen}dataAttr="help-menu-button"severity={moreSeverity}- aria-label={moreLabel}+ aria-label={hasUnseenWizardRuns ? `${moreLabel}, new Wizard runs` : moreLabel}/>}/>@@ -73,6 +108,13 @@ export function TodayMoreMenu(): JSX.Element {>Health</DropdownMenuItem>+ {wizardUiEnabled && currentProjectId !== null && (+ <PostHogErrorBoundary fallback={<></>}>+ <Suspense fallback={null}>+ <WizardRunsMoreMenuItem projectId={String(currentProjectId)} />+ </Suspense>+ </PostHogErrorBoundary>+ )}<DropdownMenuSeparator /><DropdownMenuItemrender={todayMenuLinkItem('https://posthog.com/changelog', { external: true })}diff --git a/products/wizard/frontend/views/run-sidebar/WizardRunSidebarWidget.tsx b/products/wizard/frontend/views/run-sidebar/WizardRunSidebarWidget.tsxindex cb0d613bc76e..e6064fa2be42 100644--- a/products/wizard/frontend/views/run-sidebar/WizardRunSidebarWidget.tsx+++ b/products/wizard/frontend/views/run-sidebar/WizardRunSidebarWidget.tsx@@ -18,7 +18,7 @@ export function WizardRunSidebarWidget({ projectId }: { projectId: string }): JSkey={`${projectId}.${user?.id}`}runs={visibleRuns}tasksByRunId={tasksByRunId}- onStateClick={clickState}+ onStateClick={() => clickState('navbar_sidebar')}onDismissRuns={dismissRuns}/>)diff --git a/products/wizard/frontend/views/run-sidebar/WizardRunsMoreMenuItem.tsx b/products/wizard/frontend/views/run-sidebar/WizardRunsMoreMenuItem.tsxnew file mode 100644index 000000000000..a7eacfc72f8f--- /dev/null+++ b/products/wizard/frontend/views/run-sidebar/WizardRunsMoreMenuItem.tsx@@ -0,0 +1,79 @@+import { useActions, useValues } from 'kea'+import { useEffect } from 'react'++import { IconCheckCircle, IconXCircle } from '@posthog/icons'+import { DropdownMenuItem, Spinner } from '@posthog/quill-primitives'++import { urls } from 'scenes/urls'+import { userLogic } from 'scenes/userLogic'++import { todayMenuLinkItem } from '~/layout/today/todayMenuLinkItem'++import type { WizardRunApi } from '../../generated/api.schemas'+import { wizardRunIsActive } from '../../lib/wizardRunDisplay'+import { wizardRunSyncLogic } from '../../logics/wizardRunSyncLogic'+import { wizardRunSidebarLogic } from './wizardRunSidebarLogic'++function RunCount({ count, label, icon }: { count: number; label: string; icon: JSX.Element }): JSX.Element | null {+ if (count === 0) {+ return null+ }+ return (+ <span className="flex items-center gap-1" title={`${count} ${label}`}>+ {icon}+ <span translate="no">{count}</span>+ <span className="sr-only">{label}</span>+ </span>+ )+}++function RunCounts({ runs }: { runs: WizardRunApi[] }): JSX.Element {+ const running = runs.filter(wizardRunIsActive).length+ const failed = runs.filter((run) => run.status === 'failed').length+ const completed = runs.filter((run) => run.status === 'completed').length+ if (running + failed + completed === 0) {+ return <span>No recent runs</span>+ }+ return (+ <span className="flex items-center gap-2">+ <RunCount count={running} label="running" icon={<Spinner className="size-3" />} />+ <RunCount+ count={failed}+ label="failed"+ icon={<IconXCircle className="size-3 text-destructive-foreground" />}+ />+ <RunCount+ count={completed}+ label="completed"+ icon={<IconCheckCircle className="size-3 text-success-foreground" />}+ />+ </span>+ )+}++export function WizardRunsMoreMenuItem({ projectId }: { projectId: string }): JSX.Element {+ const { userRuns } = useValues(wizardRunSyncLogic({ projectId }))+ const { user } = useValues(userLogic)+ const { clickState, markRunsSeen } = useActions(wizardRunSidebarLogic({ projectId, userId: user?.id ?? 0 }))++ // The item renders only while the More menu is open, so mounting it means the user saw the runs.+ useEffect(() => {+ markRunsSeen()+ }, [markRunsSeen])++ return (+ <DropdownMenuItem+ render={todayMenuLinkItem(urls.wizardRuns())}+ description={+ <span className="flex flex-col gap-1">+ <span>The Wizard is a setup agent that automatically installs PostHog for you</span>+ <RunCounts runs={userRuns} />+ </span>+ }+ onClick={() => clickState('today_more_menu')}+ data-attr="more-menu-wizard-runs-button"+ >+ Wizard+ </DropdownMenuItem>+ )+}diff --git a/products/wizard/frontend/views/run-sidebar/WizardRunsUnseenDot.tsx b/products/wizard/frontend/views/run-sidebar/WizardRunsUnseenDot.tsxnew file mode 100644index 000000000000..59a94f1b4c5d--- /dev/null+++ b/products/wizard/frontend/views/run-sidebar/WizardRunsUnseenDot.tsx@@ -0,0 +1,33 @@+import { useValues } from 'kea'+import { useEffect } from 'react'++import { userLogic } from 'scenes/userLogic'++import { wizardRunSidebarLogic } from './wizardRunSidebarLogic'++export function WizardRunsUnseenDot({+ projectId,+ onUnseenChange,+}: {+ projectId: string+ /** The dot is aria-hidden, so the trigger needs the state for its accessible name. */+ onUnseenChange: (hasUnseenRuns: boolean) => void+}): JSX.Element | null {+ const { user } = useValues(userLogic)+ const { hasUnseenRuns } = useValues(wizardRunSidebarLogic({ projectId, userId: user?.id ?? 0 }))++ useEffect(() => {+ onUnseenChange(hasUnseenRuns)+ return () => onUnseenChange(false)+ }, [hasUnseenRuns, onUnseenChange])++ if (!hasUnseenRuns) {+ return null+ }+ return (+ <span+ aria-hidden+ className="absolute -top-0.5 -end-0.5 size-2 rounded-full bg-[var(--primary)] ring-2 ring-[var(--chrome)]"+ />+ )+}diff --git a/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.test.ts b/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.test.tsindex 7c05bca31f0f..a96d1d35e090 100644--- a/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.test.ts+++ b/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.test.ts@@ -42,10 +42,11 @@ describe('wizardRunSidebarLogic', () => {const sync = wizardRunSyncLogic({ projectId: '1' })const runs = ['first', 'second', 'third'].map((id) => ({ ...run(id), status: 'running' as const }))sync.actions.runsLoaded(runs)- logic.actions.clickState()+ logic.actions.clickState('navbar_sidebar')expect(posthog.capture).toHaveBeenCalledWith('wizard sidebar state clicked', {event_source: 'wizard_ui',project_id: '1',+ location: 'navbar_sidebar',run_count: 3,active_run_count: 3,})@@ -65,6 +66,14 @@ describe('wizardRunSidebarLogic', () => {remaining_run_count: 0,})expect(logic.values.visibleRuns).toEqual([])+ logic.actions.clickState('today_more_menu')+ expect(posthog.capture).toHaveBeenLastCalledWith('wizard sidebar state clicked', {+ event_source: 'wizard_ui',+ project_id: '1',+ location: 'today_more_menu',+ run_count: 3,+ active_run_count: 3,+ })expect(MockEventSource.instances.every((stream) => stream.readyState === MockEventSource.CLOSED)).toBe(true)sync.actions.runsLoaded([{ ...run('new'), status: 'running' }, ...runs])expect(logic.values.visibleRuns.map((run) => run.id)).toEqual(['new'])diff --git a/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.ts b/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.tsindex bcf64124cf2f..594bc077b0b6 100644--- a/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.ts+++ b/products/wizard/frontend/views/run-sidebar/wizardRunSidebarLogic.ts@@ -18,6 +18,9 @@ import type { WizardRunApi } from '../../generated/api.schemas'import { wizardRunIsActive } from '../../lib/wizardRunDisplay'import { wizardRunSyncLogic } from '../../logics/wizardRunSyncLogic'+// pinned: analytics property values, renaming breaks dashboards+export type WizardRunStateLocation = 'navbar_sidebar' | 'today_more_menu'+interface WizardRunSidebarProps {projectId: stringuserId: number@@ -27,11 +30,14 @@ export interface wizardRunSidebarLogicValues {userRuns: WizardRunApi[]dismissedRunIds: string[]visibleRuns: WizardRunApi[]+ runsSeenAt: string | null+ hasUnseenRuns: boolean}export interface wizardRunSidebarLogicActions {- clickState: () => { value: true }+ clickState: (location: WizardRunStateLocation) => { location: WizardRunStateLocation }dismissRuns: (runIds: string[]) => { runIds: string[] }+ markRunsSeen: () => { seenAt: string }syncWatchedRuns: () => { value: true }watchRuns: (source: string, runIds: string[]) => { source: string; runIds: string[] }}@@ -50,7 +56,12 @@ export const wizardRunSidebarLogic: LogicWrapper<wizardRunSidebarLogicType> = kevalues: [wizardRunSyncLogic({ projectId }), ['userRuns']],actions: [wizardRunSyncLogic({ projectId }), ['watchRuns']],})),- actions({ clickState: true, dismissRuns: (runIds: string[]) => ({ runIds }), syncWatchedRuns: true }),+ actions({+ clickState: (location: WizardRunStateLocation) => ({ location }),+ dismissRuns: (runIds: string[]) => ({ runIds }),+ markRunsSeen: () => ({ seenAt: new Date().toISOString() }),+ syncWatchedRuns: true,+ }),reducers(({ props: { projectId, userId } }) => ({dismissedRunIds: [[] as string[],@@ -58,8 +69,18 @@ export const wizardRunSidebarLogic: LogicWrapper<wizardRunSidebarLogicType> = ke// Store IDs instead of a cutoff so dismissing history cannot hide a subsequently discovered run.{ dismissRuns: (state, { runIds }) => [...new Set([...(Array.isArray(state) ? state : []), ...runIds])] },],+ runsSeenAt: [+ null as string | null,+ { persist: true, storageKey: `${projectId}.${userId}.wizard_runs_seen_at` },+ { markRunsSeen: (_, { seenAt }) => seenAt },+ ],})),selectors({+ hasUnseenRuns: [+ (s) => [s.userRuns, s.runsSeenAt],+ (runs: WizardRunApi[], seenAt: string | null): boolean =>+ runs.some((run) => seenAt === null || (run.finished_at ?? run.created_at) > seenAt),+ ],visibleRuns: [(s) => [s.userRuns, s.dismissedRunIds],(runs: WizardRunApi[], dismissed: string[]): WizardRunApi[] => {@@ -78,12 +99,15 @@ export const wizardRunSidebarLogic: LogicWrapper<wizardRunSidebarLogicType> = ke'sidebar',values.visibleRuns.map((run) => run.id)),- clickState: () => {+ clickState: ({ location }) => {+ // The More menu ignores sidebar dismissals, so count the runs it displays.+ const runs = location === 'today_more_menu' ? values.userRuns : values.visibleRunsposthog.capture('wizard sidebar state clicked', {event_source: 'wizard_ui',project_id: projectId,- run_count: values.visibleRuns.length,- active_run_count: values.visibleRuns.filter(wizardRunIsActive).length,+ location,+ run_count: runs.length,+ active_run_count: runs.filter(wizardRunIsActive).length,})},dismissRuns: ({ runIds }) => {