: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): use s for triage summary shortcut (#100349)
Dylan Martinc9a39eaf1782
diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.test.ts b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.test.tsdeleted file mode 100644index 816c25a97fd0..000000000000--- a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.test.ts+++ /dev/null@@ -1,55 +0,0 @@-import { describe, expect, it } from "vitest";-import { isInteractiveTarget, triageEnterAction } from "./ReportTriageFocus";--describe("isInteractiveTarget", () => {- function firstEl(html: string): HTMLElement {- const container = document.createElement("div");- container.innerHTML = html;- return container.firstElementChild as HTMLElement;- }-- // Guards the triage Enter shortcut: any control the card renders (Next, Exit,- // a section toggle, a verdict button, the merged-PR link) must own Enter, or- // Tab-then-Enter exits triage instead of activating the control.- it.each<[string, boolean]>([- ["<button>Exit</button>", true],- ['<a href="https://x">PR</a>', true],- ["<a>no href</a>", false],- ['<div role="button">toggle</div>', true],- ["<div>plain</div>", false],- ])("classifies %s as interactive=%s", (html, expected) => {- expect(isInteractiveTarget(firstEl(html))).toBe(expected);- });-- it("resolves a nested child up to its interactive ancestor", () => {- const button = firstEl("<button><span>icon</span></button>");- expect(isInteractiveTarget(button.firstElementChild)).toBe(true);- });-- it("returns false for null or a non-element target", () => {- expect(isInteractiveTarget(null)).toBe(false);- expect(isInteractiveTarget(document)).toBe(false);- });-});--describe("triageEnterAction", () => {- const plainTarget = document.createElement("div");- const buttonTarget = document.createElement("button");-- it.each([- ["plain Enter expands in place", false, false, plainTarget, "toggle"],- ["Command+Enter opens the full report", true, false, plainTarget, "open"],- ["Control+Enter opens the full report", false, true, plainTarget, "open"],- ["a focused control owns Enter", false, false, buttonTarget, null],- ] as const)("%s", (_label, metaKey, ctrlKey, target, expected) => {- expect(- triageEnterAction({- key: "Enter",- metaKey,- ctrlKey,- altKey: false,- target,- }),- ).toBe(expected);- });-});diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.test.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.test.tsxnew file mode 100644index 000000000000..98c1e04d544c--- /dev/null+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.test.tsx@@ -0,0 +1,115 @@+import type { SignalReport } from "@posthog/shared/types";+import { useReportChatPanelStore } from "@posthog/ui/features/inbox/stores/reportChatPanelStore";+import { navigateToInboxReportDetail } from "@posthog/ui/router/navigationBridge";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { createEvent, fireEvent, render, screen } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { ReportTriageFocus } from "./ReportTriageFocus";++vi.mock("@posthog/ui/features/auth/authClient", () => ({+ useOptionalAuthenticatedClient: () => null,+}));++vi.mock("@tanstack/react-router", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@tanstack/react-router")>()),+ useRouter: () => ({ preloadRoute: vi.fn() }),+}));++vi.mock("@posthog/ui/router/navigationBridge", () => ({+ navigateToInboxReportDetail: vi.fn(),+}));++vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));++vi.mock("@posthog/ui/features/inbox/components/ReportVerdictBanner", () => ({+ ReportVerdictBanner: () => null,+}));++const summaryDetail = "The summary contains the evidence for this report.";++function renderTriage(): { onExit: ReturnType<typeof vi.fn> } {+ const timestamp = new Date().toISOString();+ const report: SignalReport = {+ id: "report-1",+ title: "Report one",+ summary: `A report headline.\n\n${summaryDetail}`,+ status: "ready",+ total_weight: 1,+ signal_count: 1,+ artefact_count: 0,+ created_at: timestamp,+ updated_at: timestamp,+ };+ const onExit = vi.fn();+ render(+ <QueryClientProvider client={new QueryClient()}>+ <ReportTriageFocus+ reports={[report]}+ allReports={[report]}+ scope="entire-project"+ hasActiveFilters={false}+ onExit={onExit}+ />+ <a href="https://example.com">Related page</a>+ </QueryClientProvider>,+ );+ return { onExit };+}++describe("ReportTriageFocus", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ useReportChatPanelStore.setState({ open: false });+ });++ it.each(["s", "S"])("shows and hides the summary with %s", (key) => {+ renderTriage();+ expect(screen.queryByText(summaryDetail)).not.toBeInTheDocument();+ expect(screen.getByText("Read summary")).toBeInTheDocument();++ fireEvent.keyDown(window, { key });+ expect(screen.getByText(summaryDetail)).toBeVisible();+ expect(screen.getByText("Hide summary")).toBeInTheDocument();++ fireEvent.keyDown(window, { key });+ expect(screen.queryByText(summaryDetail)).not.toBeInTheDocument();+ expect(screen.getByText("Read summary")).toBeInTheDocument();+ });++ it.each([+ { label: "Enter on the page", key: "Enter", target: "page" },+ { label: "Enter on a button", key: "Enter", target: "button" },+ { label: "Enter on a link", key: "Enter", target: "link" },+ { label: "Command+Enter", key: "Enter", metaKey: true, target: "page" },+ { label: "Control+Enter", key: "Enter", ctrlKey: true, target: "page" },+ { label: "Command+S", key: "s", metaKey: true, target: "page" },+ { label: "Control+S", key: "s", ctrlKey: true, target: "page" },+ { label: "Alt+S", key: "s", altKey: true, target: "page" },+ ])("does not intercept $label", ({ target, label: _label, ...keys }) => {+ const { onExit } = renderTriage();+ const element =+ target === "button"+ ? screen.getByText("Exit triage")+ : target === "link"+ ? screen.getByText("Related page")+ : document.body;+ element.focus();++ for (const expanded of [false, true]) {+ const event = createEvent.keyDown(element, keys);+ fireEvent(element, event);++ expect(event.defaultPrevented).toBe(false);+ if (expanded) {+ expect(screen.getByText(summaryDetail)).toBeVisible();+ expect(screen.getByText("Hide summary")).toBeInTheDocument();+ } else {+ expect(screen.queryByText(summaryDetail)).not.toBeInTheDocument();+ expect(screen.getByText("Read summary")).toBeInTheDocument();+ fireEvent.keyDown(window, { key: "s" });+ }+ expect(onExit).not.toHaveBeenCalled();+ expect(navigateToInboxReportDetail).not.toHaveBeenCalled();+ }+ });+});diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsxindex 0d18baba6219..3698e793adad 100644--- a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsx+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocus.tsx@@ -34,34 +34,18 @@ function isTypingTarget(target: EventTarget | null): boolean {);}-/**- * A focused button or link owns Enter/Space activation. The global Enter- * shortcut must yield to it, or Tab-then-Enter on any control in the card- * (Next, Exit, a section toggle, a verdict button) exits triage instead of- * doing what the control says.- */-export function isInteractiveTarget(target: EventTarget | null): boolean {- return (- target instanceof HTMLElement &&- target.closest("button, a[href], [role='button']") !== null- );-}--export function triageEnterAction(input: {+export function isTriageSummaryHotkey(input: {key: string;metaKey: boolean;ctrlKey: boolean;altKey: boolean;- target: EventTarget | null;-}): "toggle" | "open" | null {- if (- input.key !== "Enter" ||- input.altKey ||- isInteractiveTarget(input.target)- ) {- return null;- }- return input.metaKey || input.ctrlKey ? "open" : "toggle";+}): boolean {+ return (+ input.key.toLowerCase() === "s" &&+ !input.metaKey &&+ !input.ctrlKey &&+ !input.altKey+ );}/**@@ -173,8 +157,8 @@ export function ReportTriageFocus({}, [finishSession, reportId, setChatOpen]);// Triage is intentionally sequential, so the next destination is known as- // soon as the card renders. Warm it before Enter/Review is pressed instead- // of making the detail route begin its work after navigation.+ // soon as the card renders. Warm it before navigation so the detail route+ // does not begin its work only after the user opens it.useEffect(() => {prefetch();}, [prefetch]);@@ -226,13 +210,7 @@ export function ReportTriageFocus({) {return;}- const enterAction = triageEnterAction(event);- if (enterAction === "open") {- event.preventDefault();- handleOpenReport();- return;- }- if (enterAction === "toggle") {+ if (isTriageSummaryHotkey(event)) {event.preventDefault();if (report) setExpanded((current) => !current);return;diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocusView.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocusView.tsxindex 0fe031776830..423b5ff98687 100644--- a/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocusView.tsx+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportTriageFocusView.tsx@@ -283,7 +283,7 @@ export function ReportTriageFocusView({</span>)}<span className="flex items-center gap-1">- <KeyHint>Enter</KeyHint>+ <KeyHint>S</KeyHint>summary</span><span className="flex items-center gap-1">