: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(desktop): add command center and rail navigation shortcuts (#107776)
Harley Alexanderc4f968c24f24
diff --git a/products/desktop/packages/shared/src/analytics-events.ts b/products/desktop/packages/shared/src/analytics-events.tsindex aa0e016b0990..1852b7881d25 100644--- a/products/desktop/packages/shared/src/analytics-events.ts+++ b/products/desktop/packages/shared/src/analytics-events.ts@@ -320,6 +320,8 @@ export interface SidebarNavItemClickedProperties {* them is the whole point of running one behind a flag.*/layout?: SidebarLayout;+ /** How a rail destination was picked. Only the channels rail sends it. */+ source?: "click" | "shortcut";}/** Every row of the account / project / org menu, plus opening it. */diff --git a/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsxindex c3483425ca18..00ece1bfb5f8 100644--- a/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/NavRail.test.tsx@@ -14,6 +14,7 @@ const mocks = vi.hoisted(() => ({navigateToChannel: vi.fn(),navigateToHome: vi.fn(),navigateToInbox: vi.fn(),+ navigateToCommandCenter: vi.fn(),openSettings: vi.fn(),openBrowserTab: vi.fn(),}));@@ -85,7 +86,8 @@ vi.mock("@posthog/ui/router/navigationBridge", () => ({navigateToInbox: (...a: unknown[]) => mocks.navigateToInbox(...a),navigateToFeeds: vi.fn(),navigateToLoops: vi.fn(),- navigateToCommandCenter: vi.fn(),+ navigateToCommandCenter: (...a: unknown[]) =>+ mocks.navigateToCommandCenter(...a),navigateToSpacesContext: vi.fn(),}));vi.mock("@posthog/ui/features/canvas/hooks/useProjectTaskFeeds", () => ({@@ -123,6 +125,7 @@ import {import { useCurrentChannelStore } from "@posthog/ui/features/canvas/stores/currentChannelStore";import { useSidebarSearchStore } from "@posthog/ui/features/canvas/stores/sidebarSearchStore";import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";+import { isMac } from "@posthog/ui/utils/platform";import { NavRail } from "./NavRail";it("stays above floating sidebar layers", () => {@@ -279,6 +282,34 @@ describe("NavRail", () => {);});+ describe("rail keys", () => {+ function pressRailKey(direction: "up" | "down"): void {+ fireEvent.keyDown(document, {+ key: direction === "up" ? "ArrowUp" : "ArrowDown",+ code: direction === "up" ? "ArrowUp" : "ArrowDown",+ ctrlKey: true,+ altKey: true,+ metaKey: isMac,+ shiftKey: !isMac,+ });+ }++ it.each([+ ["/activity", "down", "navigateToCanvases"],+ ["/activity", "up", "navigateToSpaces"],+ ["/inbox", "down", "navigateToCommandCenter"],+ ["/command-center", "down", "navigateToHome"],+ ] as const)("from %s, %s opens %s", (fullPath, direction, expected) => {+ mocks.fullPath = fullPath;+ mocks.href = fullPath;+ render(<NavRail />);++ pressRailKey(direction);++ expect(mocks[expected]).toHaveBeenCalledOnce();+ });+ });+describe("with nothing remembered", () => {it("opens a destination in a new tab on Cmd-click", () => {render(<NavRail />);diff --git a/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx b/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsxindex beffb0b00412..4504d7e36d28 100644--- a/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx@@ -27,10 +27,13 @@ import { useSpacesTabs } from "@posthog/ui/features/browser-tabs/useSpacesTabs";import { ActivityHoverCard } from "@posthog/ui/features/canvas/components/ActivityHoverCard";import { ChannelsFab } from "@posthog/ui/features/canvas/components/ChannelsFab";import {+ isRailDestinationActive,pickRailDestination,type RailCounts,type RailDestination,+ type RailState,showWorkColumn,+ stepRailDestination,visibleRailDestinations,visibleWorkRailDestinations,} from "@posthog/ui/features/canvas/components/railDestinations";@@ -50,6 +53,7 @@ import {} from "@posthog/ui/features/canvas/stores/workActivityStore";import {formatHotkey,+ GLOBAL_HOTKEY_OPTIONS,SHORTCUTS,} from "@posthog/ui/features/command/keyboard-shortcuts";import { useCommandCenterActiveCount } from "@posthog/ui/features/command-center/useCommandCenterActiveCount";@@ -73,6 +77,7 @@ import {type ReactNode,useState,} from "react";+import { useHotkeys } from "react-hotkeys-hook";const ICON_BADGE_CLASS ="-top-1 -right-1 absolute h-3.5 min-w-3.5 w-auto px-1 font-semibold text-[9px] ring-2 ring-chrome";@@ -176,12 +181,12 @@ function ActivityHoverPopover({ trigger }: { trigger: ReactElement }) {function MoreNavItem({destinations,- railPane,+ isDestinationActive,counts,onPick,}: {destinations: readonly RailDestination[];- railPane: NavRailPane;+ isDestinationActive: (pane: NavRailPane) => boolean;counts: RailCounts;onPick: (destination: RailDestination,@@ -189,7 +194,7 @@ function MoreNavItem({}) {const { iconSize } = useNavRailMetrics();const [open, setOpen] = useState(false);- const isActive = destinations.some(({ pane }) => pane === railPane);+ const isActive = destinations.some(({ pane }) => isDestinationActive(pane));const hasCount = destinations.some(({ count }) => (count?.(counts) ?? 0) > 0);return (@@ -214,27 +219,27 @@ function MoreNavItem({className="w-52 gap-0.5 p-1">{destinations.map((destination) => {- const { pane, label, Icon, count, countTone } = destination;+ const { pane, label, Icon, count, countTone, shortcut } = destination;const pick = onPick(destination);+ const selected = isDestinationActive(pane);return (<Buttonkey={pane}variant="default"size="sm"- data-selected={railPane === pane || undefined}+ data-selected={selected || undefined}className="w-full justify-start data-selected:bg-fill-selected"onClick={(event) => {setOpen(false);pick(event);}}>- <Icon size={16} weight={railPane === pane ? "fill" : "regular"} />+ <Icon size={16} weight={selected ? "fill" : "regular"} />{label}- <CountBadge- count={count?.(counts) ?? 0}- tone={countTone}- className="ml-auto"- />+ <span className="ml-auto flex items-center gap-1">+ <CountBadge count={count?.(counts) ?? 0} tone={countTone} />+ {shortcut && <Kbd>{shortcut}</Kbd>}+ </span></Button>);})}@@ -329,43 +334,69 @@ function NavRailImpl() {// So the create button files into the space you are in, like the shortcut.const currentChannelId = useCurrentChannelStore((s) => s.currentChannelId);+ const go = (destination: RailDestination): void => {+ if (workLayout) {+ if (destination.pane === "activity") {+ if (!workActivityOpen) showWorkColumn();+ toggleWorkActivity();+ return;+ }+ closeWorkActivity();+ if (destination.pane === "spaces" && railPaneFoldsIntoWork(railPane)) {+ showWorkColumn();+ return;+ }+ }+ pickRailDestination(destination, railPane);+ };++ const trackPick = (+ destination: RailDestination,+ source: "click" | "shortcut",+ ): void => {+ track(ANALYTICS_EVENTS.SIDEBAR_NAV_ITEM_CLICKED, {+ item: destination.analyticsId,+ in_more: destination.placement === "more",+ layout: "channels",+ source,+ });+ };+const pick =(destination: RailDestination) =>(event: MouseEvent<HTMLElement>): void => {- track(ANALYTICS_EVENTS.SIDEBAR_NAV_ITEM_CLICKED, {- item: destination.analyticsId,- in_more: destination.placement === "more",- layout: "channels",- });+ trackPick(destination, "click");if (tabsEnabled && (event.metaKey || event.ctrlKey)) {event.preventDefault();openBrowserTab(destination.href);return;}- if (workLayout) {- if (destination.pane === "activity") {- if (!workActivityOpen) showWorkColumn();- toggleWorkActivity();- return;- }- closeWorkActivity();- if (destination.pane === "spaces" && railPaneFoldsIntoWork(railPane)) {- showWorkColumn();- return;- }- }- pickRailDestination(destination, railPane);+ go(destination);};+ const railState: RailState = { railPane, workLayout, workActivityOpen };+ const isDestinationActive = (pane: NavRailPane): boolean =>+ isRailDestinationActive(pane, railState);++ const step = (direction: 1 | -1): void => {+ // Visual order, so the keys walk the rail the way the eye reads it, More+ // included.+ const destination = stepRailDestination(+ [...topDestinations, ...moreDestinations, ...bottomDestinations],+ railState,+ direction,+ );+ if (!destination) return;+ trackPick(destination, "shortcut");+ go(destination);+ };+ // No deps: the hook calls the newest callback, so `step` never goes stale.+ useHotkeys(SHORTCUTS.RAIL_PREV, () => step(-1), GLOBAL_HOTKEY_OPTIONS);+ useHotkeys(SHORTCUTS.RAIL_NEXT, () => step(1), GLOBAL_HOTKEY_OPTIONS);+const renderDestination = (destination: RailDestination): ReactNode => {const { pane, label, Icon, count, countTone } = destination;- const isActive = workLayout- ? pane === "activity"- ? workActivityOpen- : pane === "spaces"- ? !workActivityOpen && railPaneFoldsIntoWork(railPane)- : !workActivityOpen && railPane === pane- : railPane === pane;+ const isActive = isDestinationActive(pane);const destinationCount = count?.(counts) ?? 0;const usesNotificationDot = pane === "activity" || pane === "inbox";let badge: ReactNode;@@ -427,7 +458,7 @@ function NavRailImpl() {{moreDestinations.length > 0 && (<MoreNavItemdestinations={moreDestinations}- railPane={railPane}+ isDestinationActive={isDestinationActive}counts={counts}onPick={pick}/>diff --git a/products/desktop/packages/ui/src/features/canvas/components/railDestinations.test.ts b/products/desktop/packages/ui/src/features/canvas/components/railDestinations.test.tsnew file mode 100644index 000000000000..1c9f696becbb--- /dev/null+++ b/products/desktop/packages/ui/src/features/canvas/components/railDestinations.test.ts@@ -0,0 +1,58 @@+import { describe, expect, it } from "vitest";+import {+ isRailDestinationActive,+ type RailState,+ stepRailDestination,+ visibleRailDestinations,+} from "./railDestinations";++const order = visibleRailDestinations({+ home: true,+ inbox: true,+ loops: false,+ context: false,+ savedSearches: false,+});+const first = order[0]?.pane;+const last = order[order.length - 1]?.pane;++function state(overrides: Partial<RailState>): RailState {+ return {+ railPane: "home",+ workLayout: false,+ workActivityOpen: false,+ ...overrides,+ };+}++describe("rail destinations", () => {+ it.each([+ ["down from the last wraps to the first", last, 1, first],+ ["up from the first wraps to the last", first, -1, last],+ ] as const)("steps %s", (_, from, direction, expected) => {+ expect(+ stepRailDestination(order, state({ railPane: from }), direction)?.pane,+ ).toBe(expected);+ });++ // Loops is hidden in this order, so on its screen nothing is lit.+ it.each([+ [1, first],+ [-1, last],+ ] as const)("with nothing lit, %i lands on %s", (direction, expected) => {+ expect(+ stepRailDestination(order, state({ railPane: "loops" }), direction)?.pane,+ ).toBe(expected);+ });++ it("lights only Activity while its Work panel is open over a route", () => {+ const open = state({+ railPane: "command-center",+ workLayout: true,+ workActivityOpen: true,+ });++ expect(isRailDestinationActive("activity", open)).toBe(true);+ expect(isRailDestinationActive("command-center", open)).toBe(false);+ });+});diff --git a/products/desktop/packages/ui/src/features/canvas/components/railDestinations.ts b/products/desktop/packages/ui/src/features/canvas/components/railDestinations.tsindex 867dcdb18281..b12236e56a0b 100644--- a/products/desktop/packages/ui/src/features/canvas/components/railDestinations.ts+++ b/products/desktop/packages/ui/src/features/canvas/components/railDestinations.ts@@ -238,6 +238,7 @@ const RAIL_DESTINATIONS: readonly RailDestination[] = [count: (counts) => counts.commandCenter,countTone: "neutral",placement: "more",+ shortcut: formatHotkey(SHORTCUTS.COMMAND_CENTER),},{pane: "loops",@@ -270,6 +271,50 @@ const RAIL_DESTINATIONS: readonly RailDestination[] = [},];+/** What decides which destination the rail lights. */+export interface RailState {+ railPane: NavRailPane;+ workLayout: boolean;+ workActivityOpen: boolean;+}++/**+ * In the Work layout the Activity panel opens over the route, so while it is+ * open it is the only lit destination.+ */+export function isRailDestinationActive(+ pane: NavRailPane,+ { railPane, workLayout, workActivityOpen }: RailState,+): boolean {+ if (!workLayout) return railPane === pane;+ if (pane === "activity") return workActivityOpen;+ if (workActivityOpen) return false;+ return pane === "spaces"+ ? railPaneFoldsIntoWork(railPane)+ : railPane === pane;+}++/**+ * The destination one step from the lit one in `order`, wrapping at both ends.+ * With nothing lit, down lands on the first destination and up on the last.+ */+export function stepRailDestination(+ order: readonly RailDestination[],+ state: RailState,+ direction: 1 | -1,+): RailDestination | undefined {+ const current = order.findIndex(({ pane }) =>+ isRailDestinationActive(pane, state),+ );+ const next =+ current === -1+ ? direction === 1+ ? 0+ : order.length - 1+ : (current + direction + order.length) % order.length;+ return order[next];+}+export function visibleRailDestinations(flags: RailFlags,): readonly RailDestination[] {diff --git a/products/desktop/packages/ui/src/features/command/CommandMenu.tsx b/products/desktop/packages/ui/src/features/command/CommandMenu.tsxindex f11ce51d0562..a98f6d22fbe9 100644--- a/products/desktop/packages/ui/src/features/command/CommandMenu.tsx+++ b/products/desktop/packages/ui/src/features/command/CommandMenu.tsx@@ -470,6 +470,7 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {keywords: "grid tasks parallel dashboard",icon: <SquaresFourIcon size={12} className="text-muted-foreground" />,action: "open-command-center",+ shortcut: SHORTCUTS.COMMAND_CENTER,onRun: () => {closeSettingsDialog();navigateToCommandCenter();diff --git a/products/desktop/packages/ui/src/features/command/keyboard-shortcuts.ts b/products/desktop/packages/ui/src/features/command/keyboard-shortcuts.tsindex c921faf283a1..eb2c899ab051 100644--- a/products/desktop/packages/ui/src/features/command/keyboard-shortcuts.ts+++ b/products/desktop/packages/ui/src/features/command/keyboard-shortcuts.ts@@ -8,6 +8,13 @@ export function panelTabShortcut(macPlatform: boolean): string {).join(",");}+/** App-wide shortcuts that must also fire while focus is in a text field. */+export const GLOBAL_HOTKEY_OPTIONS = {+ enableOnFormTags: true,+ enableOnContentEditable: true,+ preventDefault: true,+} as const;+export const SHORTCUTS = {COMMAND_MENU: "mod+k",NEW_TASK: "mod+n",@@ -43,6 +50,11 @@ export const SHORTCUTS = {TOGGLE_FOCUS: "mod+r",PASTE_AS_FILE: "mod+shift+v",INBOX: "mod+i",+ COMMAND_CENTER: "mod+shift+c",+ // Off macOS, mod is ctrl and ctrl+alt+up/down already belongs to the OS+ // (workspace switching, screen rotation), so shift takes the mod slot.+ RAIL_PREV: isMac ? "ctrl+alt+mod+up" : "ctrl+alt+shift+up",+ RAIL_NEXT: isMac ? "ctrl+alt+mod+down" : "ctrl+alt+shift+down",SPACE_UP: "mod+up",SPACE_DOWN: "mod+down",FIND_IN_CONVERSATION: "mod+f",@@ -149,6 +161,27 @@ export const KEYBOARD_SHORTCUTS: KeyboardShortcut[] = [description: "Open Self-driving",category: "navigation",},+ {+ id: "command-center",+ keys: SHORTCUTS.COMMAND_CENTER,+ description: "Open Command Center",+ category: "navigation",+ },+ {+ id: "rail-prev",+ keys: SHORTCUTS.RAIL_PREV,+ description: "Previous rail destination",+ category: "navigation",+ // The nav rail that owns these only exists in the channels layout.+ availability: "channels-layout",+ },+ {+ id: "rail-next",+ keys: SHORTCUTS.RAIL_NEXT,+ description: "Next rail destination",+ category: "navigation",+ availability: "channels-layout",+ },{id: "switch-task",keys: "mod+1-9",diff --git a/products/desktop/packages/ui/src/features/sidebar/components/items/CommandCenterItem.tsx b/products/desktop/packages/ui/src/features/sidebar/components/items/CommandCenterItem.tsxindex 8181b6310999..8a92277a40b2 100644--- a/products/desktop/packages/ui/src/features/sidebar/components/items/CommandCenterItem.tsx+++ b/products/desktop/packages/ui/src/features/sidebar/components/items/CommandCenterItem.tsx@@ -1,7 +1,9 @@import { SquaresFourIcon } from "@phosphor-icons/react";+import { SHORTCUTS } from "@posthog/ui/features/command/keyboard-shortcuts";import { CountBadge } from "@posthog/ui/primitives/CountBadge";import type { MouseEventHandler } from "react";import { SidebarItem } from "../SidebarItem";+import { SidebarKbdHint } from "./SidebarKbdHint";interface CommandCenterItemProps {isActive: boolean;@@ -39,6 +41,7 @@ export function CommandCenterItem({title={`${activeCount} active`}/>}+ endHint={<SidebarKbdHint keys={SHORTCUTS.COMMAND_CENTER} />}/>);}diff --git a/products/desktop/packages/ui/src/shell/GlobalEventHandlers.tsx b/products/desktop/packages/ui/src/shell/GlobalEventHandlers.tsxindex b861c18d8e05..0c5918df0b55 100644--- a/products/desktop/packages/ui/src/shell/GlobalEventHandlers.tsx+++ b/products/desktop/packages/ui/src/shell/GlobalEventHandlers.tsx@@ -13,7 +13,10 @@ import { useChannelsLayout } from "@posthog/ui/features/canvas/hooks/useChannelsimport { toggleActivityPanel } from "@posthog/ui/features/canvas/toggleActivityPanel";import { getDefaultReviewMode } from "@posthog/ui/features/code-review/getDefaultReviewMode";import { useReviewNavigationStore } from "@posthog/ui/features/code-review/reviewNavigationStore";-import { SHORTCUTS } from "@posthog/ui/features/command/keyboard-shortcuts";+import {+ GLOBAL_HOTKEY_OPTIONS,+ SHORTCUTS,+} from "@posthog/ui/features/command/keyboard-shortcuts";import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";import { useInboxAvailable } from "@posthog/ui/features/feature-flags/useInboxAvailable";import { useFeedbackStore } from "@posthog/ui/features/feedback/feedbackStore";@@ -29,6 +32,7 @@ import { shipIt } from "@posthog/ui/primitives/confetti";import {goBackInHistory,goForwardInHistory,+ navigateToCommandCenter,navigateToFolderSettings,navigateToInbox,} from "@posthog/ui/router/navigationBridge";@@ -50,12 +54,6 @@ interface GlobalEventHandlersProps {visualTaskOrder: TaskData[];}-const GLOBAL_HOTKEY_OPTIONS = {- enableOnFormTags: true,- enableOnContentEditable: true,- preventDefault: true,-} as const;-function useGlobalEventHandlers({allTasks,onToggleCommandMenu,@@ -248,6 +246,11 @@ function useGlobalEventHandlers({...GLOBAL_HOTKEY_OPTIONS,enabled: inboxAvailable,});+ useHotkeys(+ SHORTCUTS.COMMAND_CENTER,+ navigateToCommandCenter,+ GLOBAL_HOTKEY_OPTIONS,+ );useHotkeys(SHORTCUTS.PREV_TASK, handlePrevTask, GLOBAL_HOTKEY_OPTIONS, [handlePrevTask,]);