: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): keep the right panel closed once someone closes it (#85625)
Adam Leith33ccbaf67fbd
diff --git a/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx b/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsxindex 88ab49f76506..2b8292935532 100644--- a/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx+++ b/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx@@ -87,11 +87,13 @@ function useRightPanelTask(taskId: string): Task | null {/** Which panel this session has open. */function useActiveSide(taskId: string): RightPanelSide | null {const stored = useRightPanelStore((s) => s.sideByKey[taskId]);+ const closedByDefault = useRightPanelStore((s) => s.closedByDefault);const reviewMode = useReviewNavigationStore((s) => s.reviewModes[taskId] ?? "closed",);return resolveRightPanelSide({stored,+ closedByDefault,isReviewOpen: reviewMode !== "closed",});}diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelSide.tsindex 41b5da1f061f..8e6231d60a29 100644--- a/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts@@ -26,8 +26,10 @@ export function openRightPanelSide(export function currentRightPanelSide(taskId: string): RightPanelSide | null {const reviewMode =useReviewNavigationStore.getState().reviewModes[taskId] ?? "closed";+ const { sideByKey, closedByDefault } = useRightPanelStore.getState();return resolveRightPanelSide({- stored: useRightPanelStore.getState().sideByKey[taskId],+ stored: sideByKey[taskId],+ closedByDefault,isReviewOpen: reviewMode !== "closed",});}@@ -52,12 +54,16 @@ export function useRightPanelOpen(taskId: string | undefined): boolean {const stored = useRightPanelStore((s) =>taskId ? s.sideByKey[taskId] : undefined,);+ const closedByDefault = useRightPanelStore((s) => s.closedByDefault);const reviewMode = useReviewNavigationStore((s) =>taskId ? (s.reviewModes[taskId] ?? "closed") : "closed",);if (!taskId) return false;return (- resolveRightPanelSide({ stored, isReviewOpen: reviewMode !== "closed" }) !=- null+ resolveRightPanelSide({+ stored,+ closedByDefault,+ isReviewOpen: reviewMode !== "closed",+ }) != null);}diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelStore.test.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelStore.test.tsindex 17a3e00c9521..4e1a747d5da8 100644--- a/products/desktop/packages/ui/src/features/navigation/rightPanelStore.test.ts+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelStore.test.ts@@ -1,55 +1,123 @@-import { describe, expect, it } from "vitest";+import { beforeEach, describe, expect, it } from "vitest";import {+ DEFAULT_RIGHT_PANEL_SIDE,type RightPanelSide,resolveArtifactMark,resolveRightPanelSide,+ useRightPanelStore,} from "./rightPanelStore";describe("resolveRightPanelSide", () => {it.each<{name: string;stored: RightPanelSide | null | undefined;+ closedByDefault: boolean;isReviewOpen: boolean;expected: RightPanelSide | null;}>([{name: "an untouched session opens on the timeline",stored: undefined,+ closedByDefault: false,isReviewOpen: false,expected: "timeline",},+ {+ name: "a session opened after someone put the panel away stays closed",+ stored: undefined,+ closedByDefault: true,+ isReviewOpen: false,+ expected: null,+ },{name: "a session someone closed the panel on stays closed",stored: null,+ closedByDefault: false,isReviewOpen: false,expected: null,},{name: "a session keeps the panel it was left on",stored: "artifacts",+ closedByDefault: false,+ isReviewOpen: false,+ expected: "artifacts",+ },+ {+ name: "a session left on a panel keeps it even after a close elsewhere",+ stored: "artifacts",+ closedByDefault: true,isReviewOpen: false,expected: "artifacts",},{name: "a review opened from elsewhere shows the changes",stored: "comments",+ closedByDefault: false,isReviewOpen: true,expected: "changes",},{name: "a review opened on a session someone closed the panel on still shows",stored: null,+ closedByDefault: false,isReviewOpen: true,expected: "changes",},{name: "a review closed from elsewhere closes the panel it was showing in",stored: "changes",+ closedByDefault: false,+ isReviewOpen: false,+ expected: null,+ },+ ])("$name", ({ stored, closedByDefault, isReviewOpen, expected }) => {+ expect(+ resolveRightPanelSide({ stored, closedByDefault, isReviewOpen }),+ ).toBe(expected);+ });+});++describe("setSideForKey", () => {+ beforeEach(() => {+ useRightPanelStore.setState({ sideByKey: {}, closedByDefault: false });+ });++ /** What a session nobody has touched would open on right now. */+ const freshSessionSide = (): RightPanelSide | null =>+ resolveRightPanelSide({+ stored: undefined,+ closedByDefault: useRightPanelStore.getState().closedByDefault,isReviewOpen: false,+ });++ it.each<{+ name: string;+ sides: (RightPanelSide | null)[];+ expected: RightPanelSide | null;+ }>([+ {+ name: "closing a panel leaves the next session closed too",+ sides: [null],+ expected: null,+ },+ {+ name: "opening one again brings the next session's panel back",+ sides: [null, "comments"],+ expected: DEFAULT_RIGHT_PANEL_SIDE,+ },+ {+ // Changes rides the review store, so PR links and diff toggles open it+ // without anyone reaching for the column.+ name: "a review opening over a closed panel leaves it closed",+ sides: [null, "changes"],expected: null,},- ])("$name", ({ stored, isReviewOpen, expected }) => {- expect(resolveRightPanelSide({ stored, isReviewOpen })).toBe(expected);+ ])("$name", ({ sides, expected }) => {+ for (const side of sides) {+ useRightPanelStore.getState().setSideForKey("task-1", side);+ }+ expect(freshSessionSide()).toBe(expected);});});diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelStore.tsindex 55a72778cf91..40f35c1334b6 100644--- a/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts@@ -8,7 +8,7 @@ import { persist } from "zustand/middleware";*/export type RightPanelSide = "timeline" | "artifacts" | "comments" | "changes";-/** What a session opens on before anyone touches its panel. */+/** The panel the column falls back to when it opens without a side of its own. */export const DEFAULT_RIGHT_PANEL_SIDE: RightPanelSide = "timeline";export const RIGHT_PANEL_MIN_WIDTH = 280;@@ -20,10 +20,19 @@ interface RightPanelStore {/*** The panel each session (or the sessionless fallback key) has open, so* coming back to a session finds it as it was left. `null` is a panel someone- * closed; a missing entry is a session nobody has touched, which opens on the- * default. Not persisted, because this is within-run memory.+ * closed; a missing entry is a session nobody has touched, which falls back to+ * `closedByDefault`. Not persisted, because this is within-run memory.*/sideByKey: Record<string, RightPanelSide | null | undefined>;+ /**+ * Whether a session nobody has touched opens with its panel away, following+ * whichever someone did last: closing one turns this on, opening one turns it+ * back off. Persisted, unlike `sideByKey`, because putting the panel away is a+ * standing preference rather than a fact about one session - someone working+ * in a narrow window closes it once and expects the sessions they open after+ * that, this run and the next, to leave the width to the content.+ */+ closedByDefault: boolean;/*** How many artifacts a session had the last time its panel showed them, so* the switcher can mark the ones that arrived since. A missing entry is a@@ -43,13 +52,16 @@ interface RightPanelStore {* wins, because every existing "open review" entry point (the command menu, PR* links, diff toggles) sets it and expects the changes to appear; then an* explicit choice, including the `null` of a panel someone closed; then the- * default, so opening a session lands on its timeline rather than on nothing.+ * timeline, unless the last thing anyone did to a panel was put it away, in+ * which case a session opens leaving the width to its content.*/export function resolveRightPanelSide({stored,+ closedByDefault,isReviewOpen,}: {stored: RightPanelSide | null | undefined;+ closedByDefault: boolean;isReviewOpen: boolean;}): RightPanelSide | null {if (isReviewOpen) return "changes";@@ -60,7 +72,7 @@ export function resolveRightPanelSide({// has dropped its queries.if (stored === "changes") return null;if (stored !== undefined) return stored;- return DEFAULT_RIGHT_PANEL_SIDE;+ return closedByDefault ? null : DEFAULT_RIGHT_PANEL_SIDE;}/**@@ -100,12 +112,20 @@ export const useRightPanelStore = create<RightPanelStore>()(width: RIGHT_PANEL_DEFAULT_WIDTH,isResizing: false,sideByKey: {},+ closedByDefault: false,seenArtifactCountByKey: {},setWidth: (width) =>set({ width: Math.max(RIGHT_PANEL_MIN_WIDTH, width) }),setIsResizing: (isResizing) => set({ isResizing }),setSideForKey: (key, side) =>- set((state) => ({ sideByKey: { ...state.sideByKey, [key]: side } })),+ set((state) => ({+ sideByKey: { ...state.sideByKey, [key]: side },+ // Opening a review is not a vote on the panel: PR links and diff+ // toggles open Changes without anyone reaching for the column, and+ // resolving refuses to carry Changes into a session with no review+ // open anyway. So a review leaves the preference where it was.+ closedByDefault: side === "changes" ? state.closedByDefault : !side,+ })),markArtifactsSeen: (key, count) =>set((state) =>state.seenArtifactCountByKey[key] === count@@ -124,7 +144,10 @@ export const useRightPanelStore = create<RightPanelStore>()(// coalesces the burst behind its debounce instead of writing// synchronously on each one, the way every other panel store does.storage: electronStorage,- partialize: (state) => ({ width: state.width }),+ partialize: (state) => ({+ width: state.width,+ closedByDefault: state.closedByDefault,+ }),},),);