Skip to content

: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.

fix(desktop): close a report once it is resolved or archived (#100809)

Adam Leith2b6613a8cce4
diff --git a/products/desktop/packages/ui/src/features/inbox/AGENTS.md b/products/desktop/packages/ui/src/features/inbox/AGENTS.md
index d264403cc399..c6a51fe9619a 100644
--- a/products/desktop/packages/ui/src/features/inbox/AGENTS.md
+++ b/products/desktop/packages/ui/src/features/inbox/AGENTS.md
@@ -111,6 +111,12 @@ the end of the header row and navigates to the `?from=` source, leaving the list
standing and the pane on its empty state, the way Activity closes an item. A
report with no source draws no button, because there is no list beside it.
+Resolving or archiving the open report closes it the same way, through `useCloseReportWhenTerminal` in `ReportPage`: the report has ended, so the list comes back instead of a terminal report with its actions gone.
+Only the transition into a terminal status closes.
+A report read out of the Archive is already terminal and stays, because its read-only detail is the destination.
+Both surfaces take the navigation from `useCloseReport`, so the source and triage's place in the queue are resolved in one place.
+Triage keeps its own advance-to-next behavior, since the focus view renders the queue rather than this page.
+
`InboxDetailFrameView` draws one header row, and only its container changes: on
the report's own page it goes to the app header bar through the header store,
and in a pane (Activity) the frame draws its own `ChromeBar` at the top. There
diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportDetailCloseButton.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportDetailCloseButton.tsx
index 598bc68d97ef..724f13acb31a 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/ReportDetailCloseButton.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportDetailCloseButton.tsx
@@ -5,12 +5,7 @@ import {
TooltipContent,
TooltipTrigger,
} from "@posthog/quill";
-import { useInboxTriageOrigin } from "@posthog/ui/features/inbox/hooks/useInboxBackTarget";
-import {
- resolveNavigationSource,
- useReportSourceHref,
-} from "@posthog/ui/router/reportNavigation";
-import { getRouterOrNull } from "@posthog/ui/router/routerRef";
+import { useCloseReport } from "@posthog/ui/features/inbox/hooks/useCloseReport";
import type { ReactElement } from "react";
/**
@@ -19,11 +14,8 @@ import type { ReactElement } from "react";
* source there is no list beside it and nothing to close back to.
*/
export function ReportDetailCloseButton(): ReactElement | null {
- const source = resolveNavigationSource(useReportSourceHref());
- // TanStack blanks history state on a plain navigate, so triage's place in
- // the queue has to travel with the click or the queue restarts at the top.
- const triageOrigin = useInboxTriageOrigin();
- if (!source) return null;
+ const closeReport = useCloseReport();
+ if (!closeReport) return null;
return (
<Tooltip>
@@ -36,15 +28,7 @@ export function ReportDetailCloseButton(): ReactElement | null {
className="no-drag shrink-0"
aria-label="Close report"
data-attr="report-detail-close"
- onClick={() =>
- void getRouterOrNull()?.navigate({
- href: source.href,
- state: (previous) => ({
- ...previous,
- ...(triageOrigin ? { inboxTriageOrigin: triageOrigin } : {}),
- }),
- })
- }
+ onClick={closeReport}
/>
}
>
diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportPage.test.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportPage.test.tsx
index 272c36940fdf..9397f19bc601 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/ReportPage.test.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportPage.test.tsx
@@ -9,11 +9,15 @@ const mocks = vi.hoisted(() => ({
gate: vi.fn(),
tracker: vi.fn(() => null),
navigate: vi.fn(),
+ routerNavigate: vi.fn(),
+ triageOrigin: undefined as { reportId: string } | undefined,
triageEnabled: true,
}));
vi.mock("@tanstack/react-router", () => ({
useNavigate: () => mocks.navigate,
+ useLocation: ({ select }: { select: (state: unknown) => unknown }) =>
+ select({ state: { inboxTriageOrigin: mocks.triageOrigin } }),
useRouterState: ({ select }: { select: (state: unknown) => unknown }) =>
select({
location: {
@@ -24,6 +28,10 @@ vi.mock("@tanstack/react-router", () => ({
}),
}));
+vi.mock("@posthog/ui/router/routerRef", () => ({
+ getRouterOrNull: () => ({ navigate: mocks.routerNavigate }),
+}));
+
vi.mock("@posthog/ui/features/feature-flags/useTriageFocusEnabled", () => ({
useTriageFocusEnabled: () => mocks.triageEnabled,
}));
@@ -75,6 +83,7 @@ describe("ReportPage", () => {
beforeEach(() => {
vi.clearAllMocks();
mocks.source = undefined;
+ mocks.triageOrigin = undefined;
mocks.triageEnabled = true;
mocks.report = { id: "report-1", status: "ready" } as SignalReport;
});
@@ -141,6 +150,7 @@ describe("ReportPage", () => {
it.each(["suppressed", "resolved"] as const)(
"renders %s reports read-only even with a PR",
(status) => {
+ mocks.source = "/inbox/dismissed";
mocks.report = {
...mocks.report,
status,
@@ -150,9 +160,42 @@ describe("ReportPage", () => {
expect(screen.getByText("Archived content")).toBeInTheDocument();
expect(screen.queryByText("PR content")).not.toBeInTheDocument();
expect(mocks.tracker).not.toHaveBeenCalled();
+ // A report read out of the Archive is already terminal, so the read-only
+ // detail is the destination and nothing closes it.
+ expect(mocks.routerNavigate).not.toHaveBeenCalled();
},
);
+ it.each(["resolved", "suppressed"] as const)(
+ "closes an open report back to its list once it is %s",
+ (status) => {
+ mocks.source = "/inbox";
+ mocks.triageOrigin = { reportId: "report-1" };
+ const { rerender } = render(
+ <ReportPage reportId="report-1" cachedReport={null} />,
+ );
+ expect(mocks.routerNavigate).not.toHaveBeenCalled();
+
+ mocks.report = { ...mocks.report, status };
+ rerender(<ReportPage reportId="report-1" cachedReport={null} />);
+
+ const [[navigation]] = mocks.routerNavigate.mock.calls;
+ expect(navigation.href).toBe("/inbox");
+ expect(navigation.state({})).toEqual({
+ inboxTriageOrigin: { reportId: "report-1" },
+ });
+ },
+ );
+
+ it("holds a resolved report open when it names no list to close back to", () => {
+ const { rerender } = render(
+ <ReportPage reportId="report-1" cachedReport={null} />,
+ );
+ mocks.report = { ...mocks.report, status: "resolved" };
+ rerender(<ReportPage reportId="report-1" cachedReport={null} />);
+ expect(mocks.routerNavigate).not.toHaveBeenCalled();
+ });
+
it("sends the settings Back button to the full source href", async () => {
mocks.source = "/settings/agents?agent=account-mrr&agentTab=output";
render(<ReportPage reportId="report-1" cachedReport={null} />);
@@ -165,7 +208,6 @@ describe("ReportPage", () => {
});
it("changes content in place as a report gains a PR, archives, and restores", () => {
- mocks.source = "/settings/agents";
const { rerender } = render(
<ReportPage reportId="report-1" cachedReport={null} />,
);
diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportPage.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportPage.tsx
index 986af310d201..e2022f8f2a59 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/ReportPage.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportPage.tsx
@@ -9,6 +9,7 @@ import {
import { PullRequestDetailContent } from "@posthog/ui/features/inbox/components/PullRequestDetail";
import { ReportDetailContent } from "@posthog/ui/features/inbox/components/ReportDetail";
import { ReportPageContext } from "@posthog/ui/features/inbox/components/ReportPageContext";
+import { useCloseReportWhenTerminal } from "@posthog/ui/features/inbox/hooks/useCloseReport";
import { useInboxTriageHotkey } from "@posthog/ui/features/inbox/hooks/useInboxTriageHotkey";
import { LoadingState } from "@posthog/ui/primitives/LoadingState";
import {
@@ -68,6 +69,7 @@ export function ReportPage({
function ReportPageContent({ report }: { report: SignalReport }) {
const archived = isDismissedReport(report);
const triageEnabled = useTriageFocusEnabled();
+ useCloseReportWhenTerminal(report);
useInboxTriageHotkey({ enabled: triageEnabled });
const hasPr = Boolean(report.implementation_pr_url);
return (
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useCloseReport.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useCloseReport.ts
new file mode 100644
index 000000000000..099c20826c1a
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useCloseReport.ts
@@ -0,0 +1,49 @@
+import { isDismissedReport } from "@posthog/core/inbox/reportMembership";
+import type { SignalReport } from "@posthog/shared/types";
+import { useInboxTriageOrigin } from "@posthog/ui/features/inbox/hooks/useInboxBackTarget";
+import { navigateToReportSource } from "@posthog/ui/router/navigationBridge";
+import {
+ resolveNavigationSource,
+ useReportSourceHref,
+} from "@posthog/ui/router/reportNavigation";
+import { useEffect, useMemo, useRef } from "react";
+
+/**
+ * Puts the report down and leaves its list standing, the way Activity closes an
+ * item. Null when the report names no source, because then no list sits beside
+ * it to close back to.
+ */
+export function useCloseReport(): (() => void) | null {
+ const href = resolveNavigationSource(useReportSourceHref())?.href;
+ const triageOrigin = useInboxTriageOrigin();
+ return useMemo(
+ () =>
+ href
+ ? () => navigateToReportSource(href, triageOrigin?.reportId ?? null)
+ : null,
+ [href, triageOrigin],
+ );
+}
+
+/**
+ * A report that ends while it is open closes itself, so the list comes back
+ * instead of a terminal report with its actions gone. Only the transition into
+ * a terminal status closes, because a report opened out of the Archive is
+ * already terminal and its read-only detail is the destination.
+ */
+export function useCloseReportWhenTerminal(report: SignalReport): void {
+ const closeReport = useCloseReport();
+ const terminal = isDismissedReport(report);
+ // The page swaps reports without remounting, so the id says whose transition this is.
+ const activeReportId = useRef<string | null>(null);
+
+ useEffect(() => {
+ if (!terminal) {
+ activeReportId.current = report.id;
+ return;
+ }
+ if (activeReportId.current !== report.id || !closeReport) return;
+ activeReportId.current = null;
+ closeReport();
+ }, [closeReport, report.id, terminal]);
+}
diff --git a/products/desktop/packages/ui/src/router/navigationBridge.ts b/products/desktop/packages/ui/src/router/navigationBridge.ts
index 8be778f5cbfb..85edb853f24d 100644
--- a/products/desktop/packages/ui/src/router/navigationBridge.ts
+++ b/products/desktop/packages/ui/src/router/navigationBridge.ts
@@ -180,6 +180,29 @@ export function navigateToInboxPullRequestDetail(reportId: string): void {
navigateToReport(reportId);
}
+/**
+ * Back to the list a report was opened from. Triage's place in the queue rides
+ * along in history state, because TanStack blanks that state on a plain
+ * navigate and the queue would restart at the top. The caller passes the report
+ * id rather than the origin object, so this file keeps no import of the feature
+ * module that augments the router's history state. That import reaches the
+ * route-tree cycle described above and drops the augmentations in the web host.
+ */
+export function navigateToReportSource(
+ href: string,
+ triageReportId: string | null,
+): void {
+ void getRouterOrNull()?.navigate({
+ href,
+ state: (previous) => ({
+ ...previous,
+ ...(triageReportId
+ ? { inboxTriageOrigin: { reportId: triageReportId } }
+ : {}),
+ }),
+ });
+}
+
export function navigateToInboxReportDetail(
reportId: string,
options?: { returnToTriage?: boolean },