: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
fix(desktop): show archive shortcut in task menus (#104279)
Paul D'Ambra54b72c9325a6
diff --git a/products/desktop/packages/ui/src/features/archive/TaskArchiveMenuItem.tsx b/products/desktop/packages/ui/src/features/archive/TaskArchiveMenuItem.tsxnew file mode 100644index 000000000000..780c7edd5a12--- /dev/null+++ b/products/desktop/packages/ui/src/features/archive/TaskArchiveMenuItem.tsx@@ -0,0 +1,34 @@+import { ArchiveIcon } from "@phosphor-icons/react";+import {+ formatHotkey,+ SHORTCUTS,+} from "@posthog/ui/features/command/keyboard-shortcuts";+import type { ComponentType, ReactElement, ReactNode } from "react";++export interface TaskArchiveMenuParts {+ Item: ComponentType<{+ children: ReactNode;+ disabled?: boolean;+ variant?: "default" | "destructive";+ onClick?: () => void;+ }>;+ Shortcut: ComponentType<{ children: ReactNode }>;+}++export function TaskArchiveMenuItem({+ parts,+ onClick,+}: {+ parts: TaskArchiveMenuParts;+ onClick: () => void;+}): ReactElement {+ const { Item, Shortcut } = parts;++ return (+ <Item onClick={onClick}>+ <ArchiveIcon size={14} />+ Archive+ <Shortcut>{formatHotkey(SHORTCUTS.ARCHIVE_TASK)}</Shortcut>+ </Item>+ );+}diff --git a/products/desktop/packages/ui/src/features/archive/useArchiveShortcut.ts b/products/desktop/packages/ui/src/features/archive/useArchiveShortcut.tsnew file mode 100644index 000000000000..506c4b97380f--- /dev/null+++ b/products/desktop/packages/ui/src/features/archive/useArchiveShortcut.ts@@ -0,0 +1,85 @@+import { SHORTCUTS } from "@posthog/ui/features/command/keyboard-shortcuts";+import { useId, useLayoutEffect } from "react";+import { useHotkeys } from "react-hotkeys-hook";++type ArchiveShortcutPriority = "visible-task" | "active-menu";++const PRIORITY: Record<ArchiveShortcutPriority, number> = {+ "visible-task": 0,+ "active-menu": 1,+};++let activationOrder = 0;+const activeTargets = new Map<+ string,+ { priority: number; activationOrder: number }+>();++function registerTarget(+ id: string,+ priority: ArchiveShortcutPriority,+): () => void {+ activationOrder += 1;+ activeTargets.set(id, {+ priority: PRIORITY[priority],+ activationOrder,+ });+ return () => activeTargets.delete(id);+}++function isActiveTarget(id: string): boolean {+ let activeId: string | null = null;+ let activePriority = -1;+ let activeOrder = -1;++ for (const [candidateId, target] of activeTargets) {+ if (+ target.priority > activePriority ||+ (target.priority === activePriority &&+ target.activationOrder > activeOrder)+ ) {+ activeId = candidateId;+ activePriority = target.priority;+ activeOrder = target.activationOrder;+ }+ }++ return activeId === id;+}++export function useArchiveShortcut({+ onArchive,+ enabled,+ priority,+ scopes,+}: {+ onArchive: (() => void) | undefined;+ enabled: boolean;+ priority: ArchiveShortcutPriority;+ scopes?: string | readonly string[];+}): void {+ const targetId = useId();+ const active = enabled && onArchive !== undefined;++ useLayoutEffect(() => {+ if (!active) return;+ return registerTarget(targetId, priority);+ }, [active, priority, targetId]);++ useHotkeys(+ SHORTCUTS.ARCHIVE_TASK,+ (event) => {+ if (event.repeat) return;+ if (!isActiveTarget(targetId)) return;+ event.preventDefault();+ onArchive?.();+ },+ {+ enabled: active,+ enableOnContentEditable: true,+ enableOnFormTags: true,+ scopes,+ },+ [onArchive, targetId],+ );+}diff --git a/products/desktop/packages/ui/src/features/canvas/AGENTS.md b/products/desktop/packages/ui/src/features/canvas/AGENTS.mdindex cac26a700f97..30c799e7f114 100644--- a/products/desktop/packages/ui/src/features/canvas/AGENTS.md+++ b/products/desktop/packages/ui/src/features/canvas/AGENTS.md@@ -150,6 +150,8 @@ changing breadcrumbs, canvas naming, or the canvas generation harness. The root- **A session row carries the same card and menu as the space's own list.**Both surfaces render `ChannelItemHoverCard` and `TaskRowContextMenu` from one`TaskRowMenuProps`, so the facts and the actions can't drift.+ While either menu is open, its Archive shortcut acts on that menu's task.+ When the menu closes, the shortcut acts on the visible task again.Rename is the one item the tree drops, because it edits in place and there isno inline editor on a row the keyboard is walking.The card also opens on the keyboard's highlight, 350ms after it lands — on a space row as well as a session one, so walking the tree shows the same card whichever kind of row the highlight lands on.diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemHoverCard.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemHoverCard.tsxindex 76c6c8fdc908..d35b115b7902 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemHoverCard.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemHoverCard.tsx@@ -180,6 +180,7 @@ export function ChannelItemPreviewCardProvider({payload={payload}onAction={close}onSubmenuOpenChange={setSubmenuOpen}+ shortcutActive={open || submenuOpen}/>)}</PreviewCard.Popup>diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.tsxindex 9182c3d68b66..2d0a44fe689e 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemPreview.tsx@@ -303,10 +303,12 @@ export function ChannelItemPreview({payload,onAction,onSubmenuOpenChange,+ shortcutActive = true,}: {payload: ChannelItemPreviewPayload;onAction: () => void;onSubmenuOpenChange: (open: boolean) => void;+ shortcutActive?: boolean;}) {const { item, menu } = payload;// The submenu flag lives on the provider, and Base UI reports no close when@@ -367,6 +369,7 @@ export function ChannelItemPreview({menu={menu}onAction={onAction}onSubmenuOpenChange={onSubmenuOpenChange}+ shortcutActive={shortcutActive}/></div></ItemGroup>diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsxindex 374f50671e6a..67facf6524dc 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.test.tsx@@ -1,6 +1,7 @@import type { ChannelItemModel } from "@posthog/core/canvas/channelItems";import { formatRelativeTimeShort } from "@posthog/shared";import type { Task } from "@posthog/shared/domain-types";+import { useArchiveShortcut } from "@posthog/ui/features/archive/useArchiveShortcut";import { CANVAS_DRAG_TYPE } from "@posthog/ui/features/canvas/canvasDrag";import { useArchivingTasksStore } from "@posthog/ui/features/sidebar/archivingTasksStore";import type { TaskStatusInput } from "@posthog/ui/features/sidebar/components/items/taskStatusVocabulary";@@ -86,7 +87,7 @@ const actions = {open: () => {},togglePin: () => {},setPinned: () => {},- archive: () => {},+ archive: vi.fn(),remove: () => {},fileCanvas: () => {},};@@ -148,6 +149,7 @@ beforeEach(() => {selectedTaskIds: [],lastClickedId: null,});+ actions.archive.mockClear();});describe("ChannelItemRow", () => {@@ -524,8 +526,13 @@ describe("ChannelItemRow", () => {await openCard();for (const label of MENU_ITEMS) {- expect(screen.getByRole("button", { name: label })).not.toBeNull();+ expect(+ screen.getByRole("button", {+ name: label === "Archive" ? /^Archive/ : label,+ }),+ ).not.toBeNull();}+ expect(screen.getByText("Ctrl+Shift+A")).not.toBeNull();});it("opens the same menu on right-click", () => {@@ -534,8 +541,69 @@ describe("ChannelItemRow", () => {fireEvent.contextMenu(screen.getByText("Investigate signup drop-off"));for (const label of MENU_ITEMS) {- expect(screen.getByRole("menuitem", { name: label })).not.toBeNull();+ expect(+ screen.getByRole("menuitem", {+ name: label === "Archive" ? /^Archive/ : label,+ }),+ ).not.toBeNull();}+ expect(screen.getByText("Ctrl+Shift+A")).not.toBeNull();+ });++ it("archives the active menu task before the visible task", () => {+ const archiveVisibleTask = vi.fn();+ function VisibleTaskShortcut() {+ useArchiveShortcut({+ onArchive: archiveVisibleTask,+ enabled: true,+ priority: "visible-task",+ });+ return null;+ }+ renderInList(+ <>+ <VisibleTaskShortcut />+ <ChannelItemRow actions={actions} isActive={false} item={item()} />+ </>,+ );++ fireEvent.contextMenu(screen.getByText("Investigate signup drop-off"));+ fireEvent.keyDown(document, {+ key: "a",+ code: "KeyA",+ ctrlKey: true,+ shiftKey: true,+ });++ expect(actions.archive).toHaveBeenCalledWith(+ expect.objectContaining({ id: "task-1" }),+ );+ expect(archiveVisibleTask).not.toHaveBeenCalled();++ fireEvent.keyDown(document, {+ key: "a",+ code: "KeyA",+ ctrlKey: true,+ shiftKey: true,+ repeat: true,+ });++ expect(archiveVisibleTask).not.toHaveBeenCalled();++ fireEvent.keyUp(document, {+ key: "a",+ code: "KeyA",+ ctrlKey: true,+ shiftKey: true,+ });+ fireEvent.keyDown(document, {+ key: "a",+ code: "KeyA",+ ctrlKey: true,+ shiftKey: true,+ });++ expect(archiveVisibleTask).toHaveBeenCalledOnce();});it("opens a task in a new tab from the context menu", () => {@@ -585,9 +653,15 @@ describe("ChannelItemRow", () => {expect(useSidebarPeekStore.getState().peek).toBe(true);- fireEvent.keyDown(document, { key: "Escape" });+ fireEvent.keyDown(document, {+ key: "a",+ code: "KeyA",+ ctrlKey: true,+ shiftKey: true,+ });act(() => vi.runAllTimers());+ expect(actions.archive).toHaveBeenCalledOnce();expect(useSidebarPeekStore.getState().peek).toBe(false);} finally {cleanup();diff --git a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsxindex ed5bae30c875..27b995111919 100644--- a/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/TaskRowMenu.tsx@@ -20,18 +20,25 @@ import {ContextMenu,ContextMenuContent,ContextMenuItem,+ ContextMenuShortcut,ContextMenuSub,ContextMenuSubTrigger,ContextMenuTrigger,DropdownMenu,DropdownMenuContent,DropdownMenuItem,+ DropdownMenuShortcut,DropdownMenuSub,DropdownMenuSubTrigger,DropdownMenuTrigger,} from "@posthog/quill";import { PROJECT_BLUEBIRD_FLAG } from "@posthog/shared";import type { Task } from "@posthog/shared/domain-types";+import {+ TaskArchiveMenuItem,+ type TaskArchiveMenuParts,+} from "@posthog/ui/features/archive/TaskArchiveMenuItem";+import { useArchiveShortcut } from "@posthog/ui/features/archive/useArchiveShortcut";import { useOpenBrowserTab } from "@posthog/ui/features/browser-tabs/useOpenBrowserTab";import { useChannels } from "@posthog/ui/features/canvas/hooks/useChannels";import { useFileTaskToChannel } from "@posthog/ui/features/canvas/hooks/useFileTaskToChannel";@@ -92,25 +99,21 @@ export interface TaskRowMenuProps {// written once against this shape. Base UI builds context menus on the same Menu// parts as dropdowns, so the props line up; typing them structurally keeps the// shared content from having to know which surface it's on.-interface MenuParts {- Item: ComponentType<{- children: ReactNode;- disabled?: boolean;- variant?: "default" | "destructive";- onClick?: () => void;- }>;+interface MenuParts extends TaskArchiveMenuParts {Sub: ComponentType<{ children: ReactNode }>;SubTrigger: ComponentType<{ children: ReactNode }>;}const CONTEXT_PARTS: MenuParts = {Item: ContextMenuItem,+ Shortcut: ContextMenuShortcut,Sub: ContextMenuSub,SubTrigger: ContextMenuSubTrigger,};const DROPDOWN_PARTS: MenuParts = {Item: DropdownMenuItem,+ Shortcut: DropdownMenuShortcut,Sub: DropdownMenuSub,SubTrigger: DropdownMenuSubTrigger,};@@ -254,10 +257,7 @@ function TaskRowMenuItems({</Item>)}{menu.onArchive && (- <Item onClick={menu.onArchive}>- <ArchiveIcon size={14} />- Archive- </Item>+ <TaskArchiveMenuItem parts={parts} onClick={menu.onArchive} />)}{/* The ellipsis is the promise that a confirm follows — deleting a canvastakes it away from everyone in the space. */}@@ -357,6 +357,15 @@ function TaskRowBulkMenuItems({*/export function TaskRowDropdownMenu({ menu }: { menu: TaskRowMenuProps }) {const [open, setOpen] = useState(false);+ const archiveFromMenu = useCallback(() => {+ setOpen(false);+ menu.onArchive?.();+ }, [menu]);+ useArchiveShortcut({+ onArchive: archiveFromMenu,+ enabled: open && menu.onArchive !== undefined,+ priority: "active-menu",+ });return (<DropdownMenu open={open} onOpenChange={setOpen}>@@ -383,11 +392,22 @@ export function TaskRowMenuList({menu,onAction,onSubmenuOpenChange,+ shortcutActive = true,}: {menu: TaskRowMenuProps;onAction: () => void;onSubmenuOpenChange: (open: boolean) => void;+ shortcutActive?: boolean;}) {+ const archiveFromMenu = useCallback(() => {+ menu.onArchive?.();+ onAction();+ }, [menu, onAction]);+ useArchiveShortcut({+ onArchive: archiveFromMenu,+ enabled: shortcutActive && menu.onArchive !== undefined,+ priority: "active-menu",+ });const parts: MenuParts = useMemo(() => ({Item: ({ children, disabled, variant, onClick }) => (@@ -404,6 +424,7 @@ export function TaskRowMenuList({{children}</Button>),+ Shortcut: DropdownMenuShortcut,Sub: ({ children }) => (<DropdownMenu onOpenChange={onSubmenuOpenChange}>{children}@@ -454,9 +475,12 @@ export function TaskRowContextMenu({onOpenChange?: (open: boolean) => void;children: ReactNode;}) {+ const [open, setOpen] = useState(false);const holdSidebarPeek = useHoldSidebarPeek();+ const archiveFromMenu = bulk?.onArchive ?? menu.onArchive;const handleOpenChange = useCallback((open: boolean): void => {+ setOpen(open);if (!open || useSidebarPeekStore.getState().peek) {holdSidebarPeek(open);}@@ -464,9 +488,18 @@ export function TaskRowContextMenu({},[holdSidebarPeek, onOpenChange],);+ const handleArchiveShortcut = useCallback(() => {+ handleOpenChange(false);+ archiveFromMenu?.();+ }, [archiveFromMenu, handleOpenChange]);+ useArchiveShortcut({+ onArchive: handleArchiveShortcut,+ enabled: open && archiveFromMenu !== undefined,+ priority: "active-menu",+ });return (- <ContextMenu onOpenChange={handleOpenChange}>+ <ContextMenu open={open} onOpenChange={handleOpenChange}><ContextMenuTrigger render={<div className="min-w-0" />}>{children}</ContextMenuTrigger>diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsxindex b01fe2170f0b..117e192a75e3 100644--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsx+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskDetail.tsx@@ -5,6 +5,7 @@ import { useHotkeys, useHotkeysContext } from "react-hotkeys-hook";import { useBlurOnEscape } from "../../../hooks/useBlurOnEscape";import { useSetHeaderContent } from "../../../hooks/useSetHeaderContent";import { logger } from "../../../shell/logger";+import { useArchiveShortcut } from "../../archive/useArchiveShortcut";import { useTaskArchive } from "../../archive/useTaskArchive";import { ChannelBreadcrumb } from "../../canvas/components/ChannelBreadcrumb";import { CopyThreadLinkButton } from "../../canvas/components/CopyThreadLinkButton";@@ -15,7 +16,6 @@ import {} from "../../code-review/components/LazyReviewPages";import { useReviewNavigationStore } from "../../code-review/reviewNavigationStore";import { useFileSearchStore } from "../../command/fileSearchStore";-import { SHORTCUTS } from "../../command/keyboard-shortcuts";import { useRepoFileWatcher } from "../../file-watcher/useRepoFileWatcher";import { clearGitReviewQueries } from "../../git-interaction/gitCacheKeys";import { useRightPanelStore } from "../../navigation/rightPanelStore";@@ -68,20 +68,12 @@ export function TaskDetail({navigateUnscoped: !channelId,});- useHotkeys(- SHORTCUTS.ARCHIVE_TASK,- (event) => {- event.preventDefault();- requestArchive();- },- {- scopes: ["taskDetail"],- enabled: !inBackgroundTile,- enableOnContentEditable: true,- enableOnFormTags: true,- },- [requestArchive],- );+ useArchiveShortcut({+ onArchive: requestArchive,+ enabled: !inBackgroundTile,+ priority: "visible-task",+ scopes: ["taskDetail"],+ });useEffect(() => {if (inBackgroundTile) return;diff --git a/products/desktop/packages/ui/src/features/task-detail/components/TaskOverflowMenu.tsx b/products/desktop/packages/ui/src/features/task-detail/components/TaskOverflowMenu.tsxindex 3431f649f6fc..62137e875d34 100644--- a/products/desktop/packages/ui/src/features/task-detail/components/TaskOverflowMenu.tsx+++ b/products/desktop/packages/ui/src/features/task-detail/components/TaskOverflowMenu.tsx@@ -15,11 +15,8 @@ import {} from "@posthog/quill";import { sessionSupportsSideQuestion } from "@posthog/shared";import type { Task } from "@posthog/shared/domain-types";+import { TaskArchiveMenuItem } from "@posthog/ui/features/archive/TaskArchiveMenuItem";import { useTaskArchive } from "@posthog/ui/features/archive/useTaskArchive";-import {- formatHotkey,- SHORTCUTS,-} from "@posthog/ui/features/command/keyboard-shortcuts";import { StopCloudRunDialog } from "@posthog/ui/features/sessions/components/StopCloudRunDialog";import { startSessionSummary } from "@posthog/ui/features/sessions/sessionSummary";import { useSideQuestionStore } from "@posthog/ui/features/sessions/sideQuestionStore";@@ -27,6 +24,11 @@ import { useSessionSelector } from "@posthog/ui/features/sessions/useSession";import { useState } from "react";import { shallow } from "zustand/shallow";+const TASK_ARCHIVE_MENU_PARTS = {+ Item: DropdownMenuItem,+ Shortcut: DropdownMenuShortcut,+};+/*** The task header's overflow menu: everything that acts on the task itself* rather than on its branch or its diff.@@ -96,12 +98,10 @@ export function TaskOverflowMenu({ task }: { task: Task }) {Summarize for another agent</DropdownMenuItem>)}- <DropdownMenuItem onClick={requestArchive}>- Archive- <DropdownMenuShortcut>- {formatHotkey(SHORTCUTS.ARCHIVE_TASK)}- </DropdownMenuShortcut>- </DropdownMenuItem>+ <TaskArchiveMenuItem+ parts={TASK_ARCHIVE_MENU_PARTS}+ onClick={requestArchive}+ /></DropdownMenuContent></DropdownMenu></div>