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.

feat(desktop): expand the right panel over the content (#85654)

Adam Leith21d7d3fcd7d5
diff --git a/products/desktop/apps/code/src/renderer/features/code-review/reviewHost.tsx b/products/desktop/apps/code/src/renderer/features/code-review/reviewHost.tsx
index 01b0e49ad263..061d3b417dbd 100644
--- a/products/desktop/apps/code/src/renderer/features/code-review/reviewHost.tsx
+++ b/products/desktop/apps/code/src/renderer/features/code-review/reviewHost.tsx
@@ -7,7 +7,5 @@ export const diffWorkerFactory = () =>
export const reviewHost: ReviewHost = {
diffWorkerFactory,
- renderExpandedSidebar: (task) => (
- <ChangesPanel taskId={task.id} task={task} />
- ),
+ renderFileBrowser: (task) => <ChangesPanel taskId={task.id} task={task} />,
};
diff --git a/products/desktop/apps/web/src/web-review-host.tsx b/products/desktop/apps/web/src/web-review-host.tsx
index d277a80db7d3..3ad565e888a7 100644
--- a/products/desktop/apps/web/src/web-review-host.tsx
+++ b/products/desktop/apps/web/src/web-review-host.tsx
@@ -11,7 +11,5 @@ export const webDiffWorkerFactory = () =>
export const webReviewHost: ReviewHost = {
diffWorkerFactory: webDiffWorkerFactory,
- renderExpandedSidebar: (task) => (
- <ChangesPanel taskId={task.id} task={task} />
- ),
+ renderFileBrowser: (task) => <ChangesPanel taskId={task.id} task={task} />,
};
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
index feaf74b78ece..1005e954e438 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelsSidebar.tsx
@@ -27,6 +27,7 @@ import {
import { useCurrentChannelStore } from "@posthog/ui/features/canvas/stores/currentChannelStore";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
import { useOnboardingStore } from "@posthog/ui/features/onboarding/onboardingStore";
+import { NavResizeTooltip } from "@posthog/ui/features/sidebar/components/NavResizeTooltip";
import { ProjectSwitcher } from "@posthog/ui/features/sidebar/components/ProjectSwitcher";
import { SidebarMenu } from "@posthog/ui/features/sidebar/components/SidebarMenu";
import { SidebarNavSection } from "@posthog/ui/features/sidebar/components/SidebarNavSection";
@@ -250,6 +251,7 @@ export function ChannelsSidebar() {
onPeekEnter={beginSidebarPeek}
onPeekLeave={() => endSidebarPeek()}
onPeekDismiss={cancelSidebarPeek}
+ resizeTooltip={<NavResizeTooltip />}
>
{/* One preview card for every row in here — the channel's own list and
the space tree both draw their rows as triggers on it. */}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx
index 6e98408a6365..d5bda519908c 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/WebsiteLayout.tsx
@@ -46,12 +46,10 @@ import {
useIsDashboardEditing,
} from "@posthog/ui/features/canvas/stores/dashboardEditStore";
import { copyCanvasLink } from "@posthog/ui/features/canvas/utils/copyCanvasLink";
-import {
- RightPanel,
- SWITCHER_WIDTH_PX,
-} from "@posthog/ui/features/navigation/components/RightPanel";
+import { RightPanel } from "@posthog/ui/features/navigation/components/RightPanel";
import {
CONTENT_CHROME_RIGHT_VAR,
+ SWITCHER_WIDTH_PX,
useRightPanelOpen,
} from "@posthog/ui/features/navigation/rightPanelSide";
import { buildCommentThreads } from "@posthog/ui/features/sessions/components/commentViewTypes";
@@ -443,13 +441,14 @@ export function WebsiteLayout() {
)}
</div>
)}
- {/* The right panel's switcher pins itself to this row's top right, so the
- row is its positioning context. `isolate` keeps the switcher's stacking
- rank inside the row, where it only has to beat the panel's own layer,
- rather than reaching the app's dialogs and popovers. While the panel is
- closed the switcher floats over the content pane, so the row publishes
- how much of its right edge is spoken for and the pane's own chrome
- stops short of it. */}
+ {/* The right panel lays itself over this row's right edge and pins its
+ switcher to the row's top right, so the row is its positioning context
+ and its ceiling - the panel never reaches over the nav beside it.
+ `isolate` keeps the switcher's stacking rank inside the row, where it
+ only has to beat the panel's own layer, rather than reaching the app's
+ dialogs and popovers. While the panel is closed the switcher floats
+ over the content pane, so the row publishes how much of its right edge
+ is spoken for and the pane's own chrome stops short of it. */}
<div
className="relative isolate flex min-h-0 flex-1 overflow-hidden"
style={
@@ -460,13 +459,17 @@ export function WebsiteLayout() {
} as CSSProperties
}
>
- <div className="min-w-0 flex-1 overflow-hidden">
+ {/* `isolate`: the pane's own chrome climbs to z-50, and without a
+ stacking context of its own that would outrank the right panel's
+ scrim, which has to sit under the panel and so cannot simply outbid
+ it. */}
+ <div className="isolate min-w-0 flex-1 overflow-hidden">
<MentionAvailabilityProvider disabledReason={mentionsDisabledReason}>
<Outlet />
</MentionAvailabilityProvider>
</div>
- {/* One panel at a time beside the content: the session's timeline,
- artifacts, comments, or changes, as a push column. */}
+ {/* One panel at a time at the right of the content: the session's
+ timeline, artifacts, comments, or changes. */}
{spacesLayout && <RightPanel />}
</div>
{/* Warm-iframe pool for canvases. Mounted once here so it persists across
diff --git a/products/desktop/packages/ui/src/features/code-review/components/ReviewShell.tsx b/products/desktop/packages/ui/src/features/code-review/components/ReviewShell.tsx
index 3ee8c28b5368..eff275135858 100644
--- a/products/desktop/packages/ui/src/features/code-review/components/ReviewShell.tsx
+++ b/products/desktop/packages/ui/src/features/code-review/components/ReviewShell.tsx
@@ -4,6 +4,8 @@ import type { Task } from "@posthog/shared/domain-types";
import { useArchivedTaskIds } from "@posthog/ui/features/archive/useArchivedTaskIds";
import { useCloudPrUrl } from "@posthog/ui/features/git-interaction/useCloudPrUrl";
import { useTaskPrStatus } from "@posthog/ui/features/sidebar/useTaskPrStatus";
+import { useIsWiderThan } from "@posthog/ui/primitives/hooks/useObservedWidth";
+import { ResizeHandle } from "@posthog/ui/primitives/ResizeHandle";
import { Flex, Spinner, Text } from "@radix-ui/themes";
import {
type ReactNode,
@@ -22,6 +24,7 @@ import {
resolveVisibleActiveFilePath,
} from "../commentFileFilter";
import {
+ REVIEW_FILE_BROWSER_MIN_WIDTH,
REVIEW_LIST_BUFFER_PX,
REVIEW_LIST_ESTIMATED_ITEM_SIZE,
} from "../constants";
@@ -50,71 +53,38 @@ const SIDEBAR_MIN_WIDTH = 200;
const SIDEBAR_MAX_WIDTH = 500;
const SIDEBAR_DEFAULT_WIDTH = 280;
-function ExpandedSidebar({ task }: { task: Task }) {
+function FileBrowser({ task }: { task: Task }) {
const reviewHost = useService<ReviewHost>(REVIEW_HOST);
const [width, setWidth] = useState(SIDEBAR_DEFAULT_WIDTH);
- const isDragging = useRef(false);
-
- const handleMouseDown = useCallback(
- (e: React.MouseEvent) => {
- e.preventDefault();
- isDragging.current = true;
- const startX = e.clientX;
- const startWidth = width;
-
- const handleMouseMove = (e: MouseEvent) => {
- if (!isDragging.current) return;
- const delta = startX - e.clientX;
- const newWidth = Math.min(
- SIDEBAR_MAX_WIDTH,
- Math.max(SIDEBAR_MIN_WIDTH, startWidth + delta),
- );
- setWidth(newWidth);
- };
-
- const handleMouseUp = () => {
- isDragging.current = false;
- document.removeEventListener("mousemove", handleMouseMove);
- document.removeEventListener("mouseup", handleMouseUp);
- document.body.style.cursor = "";
- document.body.style.userSelect = "";
- };
-
- document.addEventListener("mousemove", handleMouseMove);
- document.addEventListener("mouseup", handleMouseUp);
- document.body.style.cursor = "col-resize";
- document.body.style.userSelect = "none";
- },
- [width],
- );
+ const [isResizing, setIsResizing] = useState(false);
+ const boxRef = useRef<HTMLDivElement | null>(null);
+ const rightRef = useRef(0);
return (
- <Flex direction="row" className="shrink-0">
- <button
- type="button"
- aria-label="Resize sidebar"
- onMouseDown={handleMouseDown}
- style={{ transition: "background 0.1s" }}
- onMouseEnter={(e) => {
- e.currentTarget.style.background = "var(--accent-8)";
- }}
- onMouseLeave={(e) => {
- if (!isDragging.current) {
- e.currentTarget.style.background = "transparent";
- }
+ <Flex
+ ref={boxRef}
+ direction="column"
+ style={{ width: `${width}px`, minWidth: `${SIDEBAR_MIN_WIDTH}px` }}
+ className="relative shrink-0 border-l border-l-(--gray-6) bg-(--color-background)"
+ >
+ {reviewHost.renderFileBrowser(task)}
+ <ResizeHandle
+ edge="left"
+ tooltip="Resize"
+ isResizing={isResizing}
+ setIsResizing={setIsResizing}
+ onDragStart={() => {
+ rightRef.current = boxRef.current?.getBoundingClientRect().right ?? 0;
}}
- className="w-[4px] shrink-0 cursor-col-resize border-l border-l-(--gray-6) bg-transparent p-0"
+ onDrag={(event) =>
+ setWidth(
+ Math.min(
+ SIDEBAR_MAX_WIDTH,
+ Math.max(SIDEBAR_MIN_WIDTH, rightRef.current - event.clientX),
+ ),
+ )
+ }
/>
- <Flex
- direction="column"
- style={{
- width: `${width}px`,
- minWidth: `${SIDEBAR_MIN_WIDTH}px`,
- }}
- className="shrink-0 bg-(--color-background)"
- >
- {reviewHost.renderExpandedSidebar(task)}
- </Flex>
</Flex>
);
}
@@ -148,6 +118,7 @@ export function ReviewShell({
const taskId = task.id;
const listRef = useRef<VListHandle | null>(null);
const listContainerRef = useRef<HTMLDivElement | null>(null);
+ const shellRef = useRef<HTMLDivElement | null>(null);
const lastActiveRef = useRef<string | null>(null);
const pendingNavigationRef = useRef<string | null>(null);
const navigationFrameRef = useRef<number | null>(null);
@@ -200,10 +171,12 @@ export function ReviewShell({
[reviewHost],
);
- const reviewMode = useReviewNavigationStore(
- (s) => s.reviewModes[taskId] ?? "closed",
+ // The room the review was given, not the mode it was opened in: the same
+ // review is a column, a widened panel, and a scene of its own.
+ const showFileBrowser = useIsWiderThan(
+ shellRef,
+ REVIEW_FILE_BROWSER_MIN_WIDTH,
);
- const isExpanded = reviewMode === "expanded";
const viewedCount = useMemo(() => {
const visibleKeys =
@@ -442,7 +415,7 @@ export function ReviewShell({
}}
>
<ReviewViewedContext.Provider value={viewedContextValue}>
- <Flex direction="column" height="100%" id="review-shell">
+ <Flex ref={shellRef} direction="column" height="100%" id="review-shell">
<ReviewToolbar
taskId={taskId}
fileCount={fileCount}
@@ -482,7 +455,7 @@ export function ReviewShell({
<PendingReviewBar taskId={taskId} />
</Flex>
- {isExpanded && <ExpandedSidebar task={task} />}
+ {showFileBrowser && <FileBrowser task={task} />}
</Flex>
</Flex>
</ReviewViewedContext.Provider>
diff --git a/products/desktop/packages/ui/src/features/code-review/constants.ts b/products/desktop/packages/ui/src/features/code-review/constants.ts
index eb62947ef632..a5e26b2de555 100644
--- a/products/desktop/packages/ui/src/features/code-review/constants.ts
+++ b/products/desktop/packages/ui/src/features/code-review/constants.ts
@@ -4,6 +4,9 @@ export const REVIEW_MAX_FILE_LINES = 5_000;
export const REVIEW_LIST_BUFFER_PX = 1_600;
export const REVIEW_LIST_ESTIMATED_ITEM_SIZE = 320;
+/** Below this the browser would take the room the diff needs to stay readable. */
+export const REVIEW_FILE_BROWSER_MIN_WIDTH = 880;
+
export const DIFF_METRICS = {
hunkLineCount: 50,
lineHeight: 20,
diff --git a/products/desktop/packages/ui/src/features/code-review/reviewHost.ts b/products/desktop/packages/ui/src/features/code-review/reviewHost.ts
index 425e7f3edf29..2bfa88af06f1 100644
--- a/products/desktop/packages/ui/src/features/code-review/reviewHost.ts
+++ b/products/desktop/packages/ui/src/features/code-review/reviewHost.ts
@@ -3,7 +3,8 @@ import type { ReactNode } from "react";
export interface ReviewHost {
diffWorkerFactory(): Worker;
- renderExpandedSidebar(task: Task): ReactNode;
+ /** The list of a review's files, shown beside the diff when there is room. */
+ renderFileBrowser(task: Task): ReactNode;
}
export const REVIEW_HOST = Symbol.for("posthog.ui.ReviewHost");
diff --git a/products/desktop/packages/ui/src/features/navigation/components/PanelResizeHandle.tsx b/products/desktop/packages/ui/src/features/navigation/components/PanelResizeHandle.tsx
new file mode 100644
index 000000000000..b590692d2dc8
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/navigation/components/PanelResizeHandle.tsx
@@ -0,0 +1,88 @@
+import { resolvePanelDrag } from "@posthog/ui/features/navigation/rightPanelGeometry";
+import {
+ currentRightPanelSide,
+ openRightPanelSide,
+} from "@posthog/ui/features/navigation/rightPanelSide";
+import {
+ DEFAULT_RIGHT_PANEL_SIDE,
+ type RightPanelSide,
+ useRightPanelStore,
+} from "@posthog/ui/features/navigation/rightPanelStore";
+import { ResizeHandle } from "@posthog/ui/primitives/ResizeHandle";
+import React from "react";
+
+/**
+ * The panel is anchored to the row's right edge, so the width being asked for
+ * is the pointer's distance from it. `resolvePanelDrag` says what each distance
+ * means; this carries it out.
+ */
+export function PanelResizeHandle({
+ taskId,
+ panelRef,
+ rowWidth,
+}: {
+ taskId: string;
+ panelRef: React.RefObject<HTMLDivElement | null>;
+ rowWidth: number;
+}) {
+ const isResizing = useRightPanelStore((s) => s.isResizing);
+ const setIsResizing = useRightPanelStore((s) => s.setIsResizing);
+
+ // Captured on mousedown. The width is what a drag-to-close puts back, since
+ // closing walks the stored width down to the floor on its way out.
+ const start = React.useRef({
+ right: 0,
+ width: 0,
+ side: DEFAULT_RIGHT_PANEL_SIDE as RightPanelSide,
+ });
+ const closed = React.useRef(false);
+
+ return (
+ <ResizeHandle
+ edge="left"
+ tooltip="Resize"
+ isResizing={isResizing}
+ setIsResizing={setIsResizing}
+ onDragStart={() => {
+ start.current = {
+ right: panelRef.current?.getBoundingClientRect().right ?? 0,
+ width: useRightPanelStore.getState().width,
+ side: currentRightPanelSide(taskId) ?? DEFAULT_RIGHT_PANEL_SIDE,
+ };
+ closed.current = false;
+ }}
+ onDrag={(event) => {
+ const { setWidth, setExpandedForKey, expandedByKey } =
+ useRightPanelStore.getState();
+ const drag = resolvePanelDrag({
+ pointer: start.current.right - event.clientX,
+ rowWidth,
+ open: currentRightPanelSide(taskId) != null,
+ expanded: expandedByKey[taskId] ?? false,
+ });
+
+ switch (drag.action) {
+ case "hold":
+ return;
+ case "resize":
+ return setWidth(drag.width);
+ case "collapse":
+ setExpandedForKey(taskId, false);
+ return setWidth(drag.width);
+ case "close":
+ closed.current = true;
+ return openRightPanelSide(null, taskId);
+ case "reopen":
+ closed.current = false;
+ openRightPanelSide(start.current.side, taskId);
+ return setWidth(drag.width);
+ }
+ }}
+ onDragEnd={() => {
+ if (closed.current) {
+ useRightPanelStore.getState().setWidth(start.current.width);
+ }
+ }}
+ />
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx b/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx
index 2b8292935532..05109eec2b44 100644
--- a/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx
+++ b/products/desktop/packages/ui/src/features/navigation/components/RightPanel.tsx
@@ -1,10 +1,4 @@
-import {
- ChatCircleIcon,
- GitDiffIcon,
- type Icon,
- PackageIcon,
- PulseIcon,
-} from "@phosphor-icons/react";
+import { ArrowsHorizontalIcon } from "@phosphor-icons/react";
import {
Button,
Tooltip,
@@ -20,58 +14,44 @@ import {
} from "@posthog/ui/features/code-review/components/LazyReviewPages";
import { preloadReviewPages } from "@posthog/ui/features/code-review/components/preloadReviewPages";
import { useReviewNavigationStore } from "@posthog/ui/features/code-review/reviewNavigationStore";
-import { openRightPanelSide } from "@posthog/ui/features/navigation/rightPanelSide";
+import { PanelResizeHandle } from "@posthog/ui/features/navigation/components/PanelResizeHandle";
+import { RightPanelButtons } from "@posthog/ui/features/navigation/components/RightPanelButtons";
+import {
+ RightPanelSurface,
+ SLIDE_MS,
+} from "@posthog/ui/features/navigation/components/RightPanelSurface";
+import { resolvePanelGeometry } from "@posthog/ui/features/navigation/rightPanelGeometry";
+import {
+ openRightPanelSide,
+ SIDES,
+ SWITCHER_WIDTH_PX,
+} from "@posthog/ui/features/navigation/rightPanelSide";
import { useCommentFocusRequest } from "@posthog/ui/features/sessions/useCommentFocusRequest";
import {
useSessionArtifactCount,
useSessionIsWorking,
} from "@posthog/ui/features/sessions/useSessionArtifactCount";
-import { TIP_KEYS } from "@posthog/ui/features/settings/tipKeys";
import { taskDetailQuery } from "@posthog/ui/features/tasks/queries";
import { useTasks } from "@posthog/ui/features/tasks/useTasks";
import { useIsCloudTask } from "@posthog/ui/features/workspace/useWorkspace";
-import {
- ResizableSidebar,
- SLIDE_MS,
-} from "@posthog/ui/primitives/ResizableSidebar";
-import { TeachingTip } from "@posthog/ui/primitives/TeachingTip";
+import { useParentWidth } from "@posthog/ui/primitives/hooks/useObservedWidth";
import { useQuery } from "@tanstack/react-query";
import { useParams } from "@tanstack/react-router";
-import { useCallback, useEffect, useState } from "react";
import {
- DEFAULT_RIGHT_PANEL_SIDE,
- RIGHT_PANEL_MIN_WIDTH,
+ memo,
+ type ReactNode,
+ useCallback,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
+import {
type RightPanelSide,
resolveArtifactMark,
resolveRightPanelSide,
useRightPanelStore,
} from "../rightPanelStore";
-const SIDES: Record<RightPanelSide, { label: string; Icon: Icon }> = {
- timeline: { label: "Timeline", Icon: PulseIcon },
- artifacts: { label: "Artifacts", Icon: PackageIcon },
- comments: { label: "Comments", Icon: ChatCircleIcon },
- changes: { label: "Changes", Icon: GitDiffIcon },
-};
-
-const SIDE_ORDER: readonly RightPanelSide[] = [
- "timeline",
- "artifacts",
- "comments",
- "changes",
-];
-
-/**
- * The room the switcher takes at the right of the row, covering SIDE_ORDER at
- * icon-sm. The panel's header row leaves it free for the title, and while the
- * panel is closed the content pane's own chrome (the tab strip and its split
- * and close controls) keeps out of it through CONTENT_CHROME_RIGHT_VAR.
- */
-export const SWITCHER_WIDTH_PX = 112;
-
-/** The one lesson this switcher teaches: where a run's deliverables land. */
-const ARTIFACTS_PANEL_TIP = TIP_KEYS.sessionArtifactsLocation;
-
/** The task the right panel talks about: the one on the current route. */
function useRightPanelTask(taskId: string): Task | null {
const { data: tasks } = useTasks();
@@ -98,125 +78,15 @@ function useActiveSide(taskId: string): RightPanelSide | null {
});
}
-/** One side's button: opens that panel, or closes it when it is the one open. */
-function SideButton({
- side,
- active,
- taskId,
- marked = false,
-}: {
- side: RightPanelSide;
- active: RightPanelSide | null;
- taskId: string;
- /** Something has arrived on this side that the panel hasn't shown yet. */
- marked?: boolean;
-}) {
- const { label, Icon } = SIDES[side];
- return (
- <Tooltip>
- <TooltipTrigger
- render={
- <Button
- variant="default"
- size="icon-sm"
- aria-label={marked ? `${label} (new)` : label}
- data-selected={active === side || undefined}
- onClick={() =>
- openRightPanelSide(active === side ? null : side, taskId)
- }
- className="relative text-muted-foreground data-selected:bg-fill-selected data-selected:text-foreground"
- >
- <Icon size={16} />
- {marked && (
- // Ringed in the row's own background so the dot still reads
- // where it overlaps the icon's strokes.
- <span
- aria-hidden
- className="absolute top-0.5 right-0.5 size-1.5 rounded-full bg-primary ring-2 ring-background"
- />
- )}
- </Button>
- }
- />
- <TooltipContent side="bottom">{label}</TooltipContent>
- </Tooltip>
- );
-}
-
-/**
- * The panel's own switcher: one button per side, the active one toggling the
- * panel closed. It sits a row below the header band, pinned to the right edge,
- * and stays there whether the panel is open or closed, because the panel slides
- * out from under it.
- */
-export function RightPanelButtons({
- active,
- taskId,
- hasNewArtifacts,
- offerArtifactsTip = false,
- artifactCount,
-}: {
- active: RightPanelSide | null;
- taskId: string;
- /** Artifacts have arrived that this session's panel hasn't shown yet. */
- hasNewArtifacts: boolean;
- /** The turn that produced them has ended, so the tip can point at where they went. */
- offerArtifactsTip?: boolean;
- /** How many the session has, so each new one is a fresh chance to teach. */
- artifactCount?: number;
-}) {
- return (
- <TooltipProvider delay={400}>
- <div className="pointer-events-auto flex shrink-0 items-center gap-0.5">
- {SIDE_ORDER.map((side) =>
- side === "artifacts" ? (
- <TeachingTip
- key={side}
- id={ARTIFACTS_PANEL_TIP}
- open={offerArtifactsTip}
- // The mark stays up until the panel is opened, so `open` can hold
- // across several runs. The count is what separates them, and it
- // is why asking for more artifacts offers the tip again.
- moment={artifactCount}
- message="New artifacts show up here"
- >
- <SideButton
- side={side}
- active={active}
- taskId={taskId}
- marked={hasNewArtifacts}
- />
- </TeachingTip>
- ) : (
- <SideButton
- key={side}
- side={side}
- active={active}
- taskId={taskId}
- />
- ),
- )}
- </div>
- </TooltipProvider>
- );
-}
-
-/**
- * Whether a session has artifacts its panel hasn't shown yet. The first count a
- * session reports is taken as seen, so a session opened long after its run
- * doesn't announce work the reader already knows about; from there the mark
- * clears whenever the panel is on Artifacts.
- */
+/** Artifacts a session's panel hasn't shown yet. */
function useNewArtifacts(
taskId: string,
task: Task | null,
active: RightPanelSide | null,
): { hasNew: boolean; count: number } {
const count = useSessionArtifactCount(task);
- // The count covers the latest run only, so the baseline is keyed per run too.
- // A resume run replaces `latest_run` with a fresh, smaller manifest; a
- // per-task baseline would then hold the old run's higher total and swallow the
- // new run's first deliverables until they passed it.
+ // Keyed per run: a resume replaces `latest_run` with a smaller manifest, and a
+ // per-task baseline would swallow the new run's first deliverables.
const seenKey = `${taskId}:${task?.latest_run?.id ?? ""}`;
const seen = useRightPanelStore((s) => s.seenArtifactCountByKey[seenKey]);
const markArtifactsSeen = useRightPanelStore((s) => s.markArtifactsSeen);
@@ -224,8 +94,7 @@ function useNewArtifacts(
count,
seen,
isShowingArtifacts: active === "artifacts",
- // The count reads zero until the task resolves and a manifest source lands.
- // Not ready yet means don't take that zero as the seen baseline.
+ // The count reads zero until a manifest lands; don't bank that as seen.
ready: task !== null,
});
@@ -245,19 +114,91 @@ function ChangesPanelContent({ task }: { task: Task }) {
}
/**
- * The panel's title and contents fade with its slide, so the two read as one
- * movement: in over the slide's own duration, out quicker, so the panel is
- * already gone as the column finishes closing.
+ * Takes the panel out to the whole row and back. Active at full width however
+ * the panel got there - a drag to the far edge lands where the button does.
*/
-const PANEL_FADE_OUT_MS = 120;
+function ExpandButton({
+ active,
+ onToggle,
+}: {
+ active: boolean;
+ onToggle: () => void;
+}) {
+ const label = active ? "Shrink panel" : "Expand panel";
+ return (
+ <TooltipProvider delay={400}>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ variant="default"
+ size="icon-sm"
+ aria-label={label}
+ data-selected={active || undefined}
+ onClick={onToggle}
+ className="text-muted-foreground data-selected:bg-fill-selected data-selected:text-foreground"
+ >
+ <ArrowsHorizontalIcon size={16} />
+ </Button>
+ }
+ />
+ <TooltipContent side="bottom">{label}</TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ );
+}
+
+/** What the panel's title reads like. */
+const PANEL_TITLE_CLASS = "min-w-0 flex-1 truncate font-medium text-[13px]";
+
+/** Stops short of the corner the switcher floats over. */
+function PanelHeader({
+ title,
+ children,
+}: {
+ title: ReactNode;
+ children?: ReactNode;
+}) {
+ return (
+ <div
+ className="flex h-[32px] shrink-0 items-center gap-0.5 border-border border-b pl-3"
+ style={{ paddingRight: SWITCHER_WIDTH_PX }}
+ >
+ {title}
+ {children}
+ </div>
+ );
+}
/**
- * The side to draw, which outlasts the one that is open: a closing panel has to
- * keep its title and contents on screen to fade them out, then drop them. A
- * drag that is still held keeps them, since dragging back out brings the same
- * panel in and rebuilding it mid-drag would stutter.
+ * Memoized: the row's width is observed a level up, and without this every tick
+ * of that observer would re-render a mounted review page.
*/
-function useFadingSide(
+const PanelContent = memo(function PanelContent({
+ task,
+ side,
+}: {
+ task: Task | null;
+ side: RightPanelSide;
+}) {
+ return (
+ <div className="flex min-h-0 flex-1 flex-col overflow-hidden">
+ {task &&
+ (side === "changes" ? (
+ <ChangesPanelContent task={task} />
+ ) : (
+ <ActivityPanelBody task={task} tab={side} canOpenInPlace />
+ ))}
+ </div>
+ );
+});
+
+/**
+ * The side to draw, which outlasts the one that is open: a closing panel needs
+ * its contents on screen to slide them out. A held drag keeps them, since
+ * dragging back out brings the same panel in.
+ */
+function useDrawnSide(
active: RightPanelSide | null,
held: boolean,
): RightPanelSide | null {
@@ -269,31 +210,22 @@ function useFadingSide(
return;
}
if (held) return;
- const timer = setTimeout(() => setDrawn(null), PANEL_FADE_OUT_MS);
+ const timer = setTimeout(() => setDrawn(null), SLIDE_MS);
return () => clearTimeout(timer);
}, [active, held]);
return drawn;
}
-/**
- * Every side the panel shows belongs to a session, so the column keeps to a
- * session's own page and nothing below this runs anywhere else.
- */
+/** Every side belongs to a session, so nothing below this runs elsewhere. */
export function RightPanel() {
const taskId = useParams({ strict: false }).taskId;
- // Keyed by session: the panel holds per-session state (which side is drawn,
- // which comment request it has taken), and carrying that across a navigation
- // draws the previous session's panel over the new one for a frame.
+ // Keyed by session: carrying per-session state across a navigation draws the
+ // previous session's panel over the new one for a frame.
return taskId ? <SessionRightPanel key={taskId} taskId={taskId} /> : null;
}
-/**
- * The right panel column: a push column beside the content, one panel at a
- * time, shared resizable width. Its switcher is pinned to the top right of the
- * column and outlives any one panel, so the panel opens and closes beneath a
- * row of buttons that never move.
- */
+/** One panel at a time, under a switcher that outlives any one of them. */
function SessionRightPanel({ taskId }: { taskId: string }) {
const task = useRightPanelTask(taskId);
const active = useActiveSide(taskId);
@@ -302,81 +234,76 @@ function SessionRightPanel({ taskId }: { taskId: string }) {
task,
active,
);
- // Only once the agent has stopped: a tip that lands mid-turn points at a
- // list that is still filling.
+ // A tip that lands mid-turn points at a list that is still filling.
const isWorking = useSessionIsWorking(task);
useCommentFocusRequest(taskId, () => openRightPanelSide("comments", taskId));
const width = useRightPanelStore((s) => s.width);
const setWidth = useRightPanelStore((s) => s.setWidth);
const isResizing = useRightPanelStore((s) => s.isResizing);
- const setIsResizing = useRightPanelStore((s) => s.setIsResizing);
+ const setExpandedForKey = useRightPanelStore((s) => s.setExpandedForKey);
+ const wantsExpanded = useRightPanelStore(
+ (s) => s.expandedByKey[taskId] ?? false,
+ );
+ const panelRef = useRef<HTMLDivElement>(null);
+ const rowWidth = useParentWidth(panelRef);
const open = active != null;
- const drawn = useFadingSide(active, isResizing);
+ // A closed panel has nothing to expand, so the row waits for it to open again.
+ const expanded = open && wantsExpanded;
+ const drawn = useDrawnSide(active, isResizing);
- useEffect(() => preloadReviewPages(), []);
+ const geometry = resolvePanelGeometry({
+ storedWidth: width,
+ rowWidth,
+ open,
+ expanded,
+ });
+ const uncover = useCallback(() => {
+ setExpandedForKey(taskId, false);
+ setWidth(geometry.uncoveredWidth);
+ }, [geometry.uncoveredWidth, setExpandedForKey, setWidth, taskId]);
- // Dragging the handle past the panel's floor closes it, and dragging back out
- // while still holding brings it in again. The drag holds the closing panel's
- // contents, so `drawn` is the side to put back; the fallback only stands in
- // for a reopen that starts from no panel at all.
- const setOpen = useCallback(
- (next: boolean) =>
- openRightPanelSide(
- next ? (drawn ?? DEFAULT_RIGHT_PANEL_SIDE) : null,
- taskId,
- ),
- [drawn, taskId],
- );
+ useEffect(() => preloadReviewPages(), []);
return (
<>
- <ResizableSidebar
+ <RightPanelSurface
+ panelRef={panelRef}
open={open}
+ expanded={expanded}
width={width}
- setWidth={setWidth}
+ geometry={geometry}
isResizing={isResizing}
- setIsResizing={setIsResizing}
- side="right"
- minWidth={RIGHT_PANEL_MIN_WIDTH}
- setOpen={setOpen}
+ onUncover={uncover}
>
- <div
- className="flex h-full min-h-0 flex-col bg-background transition-opacity ease-out motion-reduce:transition-none"
- style={{
- opacity: open ? 1 : 0,
- transitionDuration: open
- ? `${SLIDE_MS}ms`
- : `${PANEL_FADE_OUT_MS}ms`,
- }}
- >
- {drawn && (
- <>
- <div
- className="flex h-[32px] shrink-0 items-center border-border border-b pl-3"
- style={{ paddingRight: SWITCHER_WIDTH_PX }}
- >
- <span className="min-w-0 truncate font-medium text-[13px]">
- {SIDES[drawn].label}
- </span>
- </div>
- <div className="flex min-h-0 flex-1 flex-col overflow-hidden">
- {task &&
- (drawn === "changes" ? (
- <ChangesPanelContent task={task} />
- ) : (
- <ActivityPanelBody task={task} tab={drawn} canOpenInPlace />
- ))}
- </div>
- </>
- )}
- </div>
- </ResizableSidebar>
- {/* Outside the sliding column, so the buttons hold their place while the
- panel comes and goes under them. It has to outrank the panel's closed
- layer, which sweeps across this corner at z-50 on the way out; the
- row's own `isolate` keeps that rank from reaching the app's overlays. */}
+ {drawn && (
+ <>
+ <PanelHeader
+ title={
+ <span className={PANEL_TITLE_CLASS}>{SIDES[drawn].label}</span>
+ }
+ >
+ <ExpandButton
+ active={geometry.atFullWidth}
+ onToggle={() =>
+ geometry.atFullWidth
+ ? uncover()
+ : setExpandedForKey(taskId, true)
+ }
+ />
+ </PanelHeader>
+ <PanelContent task={task} side={drawn} />
+ <PanelResizeHandle
+ taskId={taskId}
+ panelRef={panelRef}
+ rowWidth={rowWidth}
+ />
+ </>
+ )}
+ </RightPanelSurface>
+ {/* Outside the panel, so the buttons hold their place while it slides.
+ The row's `isolate` keeps this rank off the app's overlays. */}
<div
className="pointer-events-none absolute top-0 right-0 z-60 flex h-[32px] items-center justify-end pr-2"
style={{ width: SWITCHER_WIDTH_PX }}
diff --git a/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.stories.tsx b/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.stories.tsx
index 69221b684bce..8f354d7bcf54 100644
--- a/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.stories.tsx
+++ b/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.stories.tsx
@@ -1,4 +1,4 @@
-import { RightPanelButtons } from "@posthog/ui/features/navigation/components/RightPanel";
+import { RightPanelButtons } from "@posthog/ui/features/navigation/components/RightPanelButtons";
import type { Meta, StoryObj } from "@storybook/react-vite";
const meta: Meta<typeof RightPanelButtons> = {
diff --git a/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.tsx b/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.tsx
new file mode 100644
index 000000000000..0659f2451a57
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/navigation/components/RightPanelButtons.tsx
@@ -0,0 +1,116 @@
+import {
+ Button,
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@posthog/quill";
+import {
+ openRightPanelSide,
+ SIDE_ORDER,
+ SIDES,
+} from "@posthog/ui/features/navigation/rightPanelSide";
+import type { RightPanelSide } from "@posthog/ui/features/navigation/rightPanelStore";
+import { TIP_KEYS } from "@posthog/ui/features/settings/tipKeys";
+import { TeachingTip } from "@posthog/ui/primitives/TeachingTip";
+
+/** The one lesson this switcher teaches: where a run's deliverables land. */
+const ARTIFACTS_PANEL_TIP = TIP_KEYS.sessionArtifactsLocation;
+
+/** One side's button: opens that panel, or closes it when it is the one open. */
+function SideButton({
+ side,
+ active,
+ taskId,
+ marked = false,
+}: {
+ side: RightPanelSide;
+ active: RightPanelSide | null;
+ taskId: string;
+ /** Something has arrived on this side that the panel hasn't shown yet. */
+ marked?: boolean;
+}) {
+ const { label, Icon } = SIDES[side];
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <Button
+ variant="default"
+ size="icon-sm"
+ aria-label={marked ? `${label} (new)` : label}
+ data-selected={active === side || undefined}
+ onClick={() =>
+ openRightPanelSide(active === side ? null : side, taskId)
+ }
+ className="relative text-muted-foreground data-selected:bg-fill-selected data-selected:text-foreground"
+ >
+ <Icon size={16} />
+ {marked && (
+ // Ringed so the dot reads where it overlaps the icon's strokes.
+ <span
+ aria-hidden
+ className="absolute top-0.5 right-0.5 size-1.5 rounded-full bg-primary ring-2 ring-background"
+ />
+ )}
+ </Button>
+ }
+ />
+ <TooltipContent side="bottom">{label}</TooltipContent>
+ </Tooltip>
+ );
+}
+
+/**
+ * One button per side, the active one toggling the panel closed. Pinned to the
+ * row's top right, so the panel comes and goes underneath it.
+ */
+export function RightPanelButtons({
+ active,
+ taskId,
+ hasNewArtifacts,
+ offerArtifactsTip = false,
+ artifactCount,
+}: {
+ active: RightPanelSide | null;
+ taskId: string;
+ /** Artifacts have arrived that this session's panel hasn't shown yet. */
+ hasNewArtifacts: boolean;
+ /** The turn that produced them has ended, so the tip can point at where they went. */
+ offerArtifactsTip?: boolean;
+ /** How many the session has, so each new one is a fresh chance to teach. */
+ artifactCount?: number;
+}) {
+ return (
+ <TooltipProvider delay={400}>
+ <div className="pointer-events-auto flex shrink-0 items-center gap-0.5">
+ {SIDE_ORDER.map((side) =>
+ side === "artifacts" ? (
+ <TeachingTip
+ key={side}
+ id={ARTIFACTS_PANEL_TIP}
+ open={offerArtifactsTip}
+ // `open` can hold across runs; the count is what separates them.
+ moment={artifactCount}
+ message="New artifacts show up here"
+ >
+ <SideButton
+ side={side}
+ active={active}
+ taskId={taskId}
+ marked={hasNewArtifacts}
+ />
+ </TeachingTip>
+ ) : (
+ <SideButton
+ key={side}
+ side={side}
+ active={active}
+ taskId={taskId}
+ />
+ ),
+ )}
+ </div>
+ </TooltipProvider>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/navigation/components/RightPanelSurface.stories.tsx b/products/desktop/packages/ui/src/features/navigation/components/RightPanelSurface.stories.tsx
new file mode 100644
index 000000000000..82be2f57f62b
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/navigation/components/RightPanelSurface.stories.tsx
@@ -0,0 +1,86 @@
+import { RightPanelSurface } from "@posthog/ui/features/navigation/components/RightPanelSurface";
+import { resolvePanelGeometry } from "@posthog/ui/features/navigation/rightPanelGeometry";
+import type { Meta, StoryObj } from "@storybook/react-vite";
+import { useRef, useState } from "react";
+
+/**
+ * The panel's two layers over a stand-in content pane. What these stories are
+ * for is where the pane stops moving: below the push share the pane gives way,
+ * and above it the pane is parked, the panel covers it, and what is left of it
+ * dims. Clicking the dimmed pane hands it back.
+ */
+/** The stories render at this width, so the geometry has a row to measure against. */
+const ROW_WIDTH = 1200;
+
+const meta: Meta<typeof RightPanelSurface> = {
+ title: "Navigation/RightPanelSurface",
+ component: RightPanelSurface,
+ parameters: { layout: "fullscreen" },
+ args: {
+ open: true,
+ expanded: false,
+ width: 340,
+ isResizing: false,
+ children: (
+ <div className="flex h-[32px] shrink-0 items-center border-border border-b pl-3 font-medium text-[13px]">
+ Changes
+ </div>
+ ),
+ },
+ render: (args) => {
+ const Demo = () => {
+ const panelRef = useRef<HTMLDivElement>(null);
+ const [width, setWidth] = useState(args.width);
+ const [expanded, setExpanded] = useState(args.expanded);
+ const geometry = resolvePanelGeometry({
+ storedWidth: width,
+ rowWidth: ROW_WIDTH,
+ open: args.open,
+ expanded,
+ });
+ return (
+ <div className="relative isolate flex h-screen overflow-hidden">
+ <div className="isolate min-w-0 flex-1 bg-fill-hover p-3 text-[13px]">
+ The content pane, which the panel pushes over until it stops.
+ </div>
+ <RightPanelSurface
+ {...args}
+ panelRef={panelRef}
+ width={width}
+ expanded={expanded}
+ geometry={geometry}
+ onUncover={() => {
+ setExpanded(false);
+ setWidth(geometry.uncoveredWidth);
+ }}
+ />
+ </div>
+ );
+ };
+ return <Demo />;
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof RightPanelSurface>;
+
+/** Under the push share: the pane gives up exactly the panel's width. */
+export const Pushing: Story = {};
+
+/** Over it: the pane is parked and the panel widens across it. */
+export const Covering: Story = {
+ args: { width: 900 },
+};
+
+export const Expanded: Story = {
+ args: { expanded: true },
+};
+
+/** Dragged to the ceiling rather than expanded: the same full width. */
+export const DraggedToFull: Story = {
+ args: { width: 1150 },
+};
+
+export const Closed: Story = {
+ args: { open: false },
+};
diff --git a/products/desktop/packages/ui/src/features/navigation/components/RightPanelSurface.tsx b/products/desktop/packages/ui/src/features/navigation/components/RightPanelSurface.tsx
new file mode 100644
index 000000000000..086efc93f67e
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/navigation/components/RightPanelSurface.tsx
@@ -0,0 +1,84 @@
+import {
+ type PanelGeometry,
+ PUSH_MAX_CSS,
+ ROW_CEILING_CSS,
+} from "@posthog/ui/features/navigation/rightPanelGeometry";
+import type { ReactNode, RefObject } from "react";
+
+/** How long the panel takes to slide in, widen, or go away. */
+export const SLIDE_MS = 200;
+
+/**
+ * The panel's two layers. The spacer pushes the pane over and stops at its share
+ * of the row; the panel is laid over the row's right edge at whatever width it
+ * has, so past that point it widens across a pane that no longer reflows.
+ * Expanding is then a wider panel over a parked pane, not a relayout.
+ *
+ * Both belong to the content row, which is what keeps the nav uncovered.
+ */
+export function RightPanelSurface({
+ panelRef,
+ open,
+ expanded,
+ width,
+ geometry,
+ isResizing,
+ onUncover,
+ children,
+}: {
+ panelRef: RefObject<HTMLDivElement | null>;
+ open: boolean;
+ /** Taking the whole row, rather than the width it was dragged to. */
+ expanded: boolean;
+ width: number;
+ geometry: PanelGeometry;
+ isResizing: boolean;
+ /** The reader clicked the covered pane, asking for it back. */
+ onUncover?: () => void;
+ children?: ReactNode;
+}) {
+ // A drag has to keep up with the pointer frame for frame, not ease toward it.
+ const slide = isResizing ? "0ms" : `${SLIDE_MS}ms`;
+
+ return (
+ <>
+ {/* Stops at the panel's push share; past that the pane holds still. */}
+ <div
+ className="h-full shrink-0 transition-[width] ease-out motion-reduce:transition-none"
+ style={{
+ width: open ? `min(${width}px, ${PUSH_MAX_CSS})` : "0px",
+ transitionDuration: slide,
+ }}
+ />
+ {/* A covered pane is a remnant, not somewhere to work, so it steps back;
+ clicking it asks for the pane back. Out of the tab order - the header's
+ own button goes to the same place. */}
+ <button
+ type="button"
+ aria-hidden
+ tabIndex={-1}
+ onClick={() => onUncover?.()}
+ className="absolute inset-0 z-30 cursor-default border-0 bg-[rgba(0,0,0,0.2)] p-0 transition-opacity duration-200 ease-out motion-reduce:transition-none"
+ style={{
+ opacity: geometry.covering ? 1 : 0,
+ pointerEvents: geometry.covering ? "auto" : "none",
+ }}
+ />
+ <div
+ ref={panelRef}
+ className="absolute inset-y-0 right-0 z-40 flex min-w-0 flex-col border-gray-6 border-l bg-background transition-[width,transform] ease-out motion-reduce:transition-none"
+ style={{
+ width: expanded ? "100%" : `${width}px`,
+ // One ceiling for both widths, so a width stored on a wider window
+ // lands where expanding would.
+ maxWidth: ROW_CEILING_CSS,
+ transform: open ? "translateX(0)" : "translateX(100%)",
+ pointerEvents: open ? undefined : "none",
+ transitionDuration: slide,
+ }}
+ >
+ {children}
+ </div>
+ </>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelGeometry.test.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelGeometry.test.ts
new file mode 100644
index 000000000000..ff9def935088
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelGeometry.test.ts
@@ -0,0 +1,202 @@
+import { describe, expect, it } from "vitest";
+import {
+ type PanelDrag,
+ resolvePanelDrag,
+ resolvePanelGeometry,
+ resolvePanelWidth,
+} from "./rightPanelGeometry";
+
+describe("resolvePanelWidth", () => {
+ it.each<{
+ name: string;
+ stored: number;
+ rowWidth: number;
+ expected: number;
+ }>([
+ {
+ name: "a dragged width is kept as it is",
+ stored: 900,
+ rowWidth: 1600,
+ expected: 900,
+ },
+ {
+ name: "a drag to the row's far edge stops short of covering it",
+ stored: 1600,
+ rowWidth: 1600,
+ expected: 1550,
+ },
+ {
+ name: "a width dragged out on a wider window still fits this row",
+ stored: 2400,
+ rowWidth: 1600,
+ expected: 1550,
+ },
+ {
+ name: "a width dragged in past the panel's floor is held at it",
+ stored: 120,
+ rowWidth: 1600,
+ expected: 280,
+ },
+ {
+ name: "a row with less room than the floor gives what it has",
+ stored: 120,
+ rowWidth: 200,
+ expected: 150,
+ },
+ ])("$name", ({ stored, rowWidth, expected }) => {
+ expect(resolvePanelWidth(stored, rowWidth)).toBe(expected);
+ });
+});
+
+describe("resolvePanelDrag", () => {
+ // A 1600px row: the panel's ceiling is 1550, its floor 280, and the drag
+ // closes below 140 / reopens at 156.
+ const rowWidth = 1600;
+
+ it.each<{
+ name: string;
+ pointer: number;
+ open: boolean;
+ expanded: boolean;
+ expected: PanelDrag;
+ }>([
+ {
+ name: "dragging an open panel sets the width the pointer asks for",
+ pointer: 700,
+ open: true,
+ expanded: false,
+ expected: { action: "resize", width: 700 },
+ },
+ {
+ name: "dragging an open panel past its floor closes it",
+ pointer: 100,
+ open: true,
+ expanded: false,
+ expected: { action: "close" },
+ },
+ {
+ name: "dragging back out while still held brings it in again",
+ pointer: 200,
+ open: false,
+ expanded: false,
+ expected: { action: "reopen", width: 280 },
+ },
+ {
+ name: "a closed panel between the two lines stays closed",
+ pointer: 150,
+ open: false,
+ expanded: false,
+ expected: { action: "hold" },
+ },
+ {
+ name: "dragging an expanded panel in takes it off the full row",
+ pointer: 900,
+ open: true,
+ expanded: true,
+ expected: { action: "collapse", width: 900 },
+ },
+ {
+ name: "dragging an expanded panel out asks for room it hasn't got",
+ pointer: 1900,
+ open: true,
+ expanded: true,
+ expected: { action: "hold" },
+ },
+ {
+ name: "an expanded panel dragged past its floor collapses on the way",
+ pointer: 100,
+ open: true,
+ expanded: true,
+ expected: { action: "collapse", width: 280 },
+ },
+ ])("$name", ({ pointer, open, expanded, expected }) => {
+ expect(resolvePanelDrag({ pointer, rowWidth, open, expanded })).toEqual(
+ expected,
+ );
+ });
+});
+
+describe("resolvePanelGeometry", () => {
+ // A 1600px row: the panel covers past 800 and is at full width from 1550.
+ const rowWidth = 1600;
+
+ it.each<{
+ name: string;
+ storedWidth: number;
+ open?: boolean;
+ expanded?: boolean;
+ rowWidth?: number;
+ covering: boolean;
+ atFullWidth: boolean;
+ }>([
+ {
+ name: "a narrow panel pushes the pane and covers nothing",
+ storedWidth: 340,
+ covering: false,
+ atFullWidth: false,
+ },
+ {
+ name: "a panel past the push share covers the pane",
+ storedWidth: 900,
+ covering: true,
+ atFullWidth: false,
+ },
+ {
+ name: "a panel dragged to the ceiling is at full width",
+ storedWidth: 1550,
+ covering: true,
+ atFullWidth: true,
+ },
+ {
+ name: "an expanded panel is covering and full however wide it was left",
+ storedWidth: 340,
+ expanded: true,
+ covering: true,
+ atFullWidth: true,
+ },
+ {
+ name: "a closed panel sits nowhere",
+ storedWidth: 1550,
+ open: false,
+ covering: false,
+ atFullWidth: false,
+ },
+ {
+ name: "an unmeasured row can't say where the panel sits",
+ storedWidth: 1550,
+ rowWidth: 0,
+ covering: false,
+ atFullWidth: false,
+ },
+ ])(
+ "$name",
+ ({
+ storedWidth,
+ open = true,
+ expanded = false,
+ covering,
+ atFullWidth,
+ ...rest
+ }) => {
+ expect(
+ resolvePanelGeometry({
+ storedWidth,
+ rowWidth: rest.rowWidth ?? rowWidth,
+ open,
+ expanded,
+ }),
+ ).toMatchObject({ covering, atFullWidth });
+ },
+ );
+
+ it("hands back the width that stops short of covering", () => {
+ expect(
+ resolvePanelGeometry({
+ storedWidth: 900,
+ rowWidth,
+ open: true,
+ expanded: false,
+ }).uncoveredWidth,
+ ).toBe(800);
+ });
+});
diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelGeometry.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelGeometry.ts
new file mode 100644
index 000000000000..773f344dc559
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelGeometry.ts
@@ -0,0 +1,112 @@
+export const RIGHT_PANEL_MIN_WIDTH = 280;
+export const RIGHT_PANEL_DEFAULT_WIDTH = 340;
+
+/**
+ * The most of its row the panel pushes the pane out of before it covers it
+ * instead. Past this the pane no longer reflows, which is what makes widening
+ * the panel cheap.
+ */
+const PUSH_MAX_SHARE = 0.5;
+
+/** What the panel always leaves of the row, so there is pane left to click. */
+const ROW_INSET_PX = 50;
+
+/** Drag past half the floor to close; back out past this to reopen. The gap stops jitter. */
+const DRAG_CLOSE_AT = RIGHT_PANEL_MIN_WIDTH * 0.5;
+const DRAG_REOPEN_AT = DRAG_CLOSE_AT + 16;
+
+/** The spacer's CSS width, as a share of the row it sits in. */
+export const PUSH_MAX_CSS = `${PUSH_MAX_SHARE * 100}%`;
+
+/** The panel's CSS ceiling, as an inset off the row's far edge. */
+export const ROW_CEILING_CSS = `calc(100% - ${ROW_INSET_PX}px)`;
+
+/** Widest the panel may be drawn in a row this wide. */
+export function panelCeiling(rowWidth: number): number {
+ return Math.max(0, rowWidth - ROW_INSET_PX);
+}
+
+/** A dragged width held to the panel's floor and the row's ceiling. */
+export function resolvePanelWidth(stored: number, rowWidth: number): number {
+ const ceiling = panelCeiling(rowWidth);
+ return Math.max(
+ Math.min(RIGHT_PANEL_MIN_WIDTH, ceiling),
+ Math.min(stored, ceiling),
+ );
+}
+
+export interface PanelGeometry {
+ /** Over the pane rather than beside it. */
+ covering: boolean;
+ /** As wide as the row allows, however it got there. */
+ atFullWidth: boolean;
+ /** Widest the panel gets while still pushing rather than covering. */
+ uncoveredWidth: number;
+}
+
+/** Where the panel sits in its row. An unmeasured row can't say, so it says nothing. */
+export function resolvePanelGeometry({
+ storedWidth,
+ rowWidth,
+ open,
+ expanded,
+}: {
+ storedWidth: number;
+ rowWidth: number;
+ open: boolean;
+ expanded: boolean;
+}): PanelGeometry {
+ if (!open || rowWidth <= 0) {
+ return { covering: false, atFullWidth: false, uncoveredWidth: 0 };
+ }
+ const uncoveredWidth = rowWidth * PUSH_MAX_SHARE;
+ return {
+ uncoveredWidth,
+ covering: expanded || storedWidth > uncoveredWidth,
+ atFullWidth: expanded || storedWidth >= panelCeiling(rowWidth),
+ };
+}
+
+/** What a drag is asking of the panel. */
+export type PanelDrag =
+ | { action: "resize"; width: number }
+ /** Out of the full row and back to a width of its own, mid-drag. */
+ | { action: "collapse"; width: number }
+ | { action: "close" }
+ | { action: "reopen"; width: number }
+ /** Nowhere the panel has an answer for. */
+ | { action: "hold" };
+
+/**
+ * What the pointer's distance from the row's right edge means. At full width
+ * there is nothing wider to ask for, so dragging out holds and dragging in is
+ * how expanding comes undone.
+ */
+export function resolvePanelDrag({
+ pointer,
+ rowWidth,
+ open,
+ expanded,
+}: {
+ /** The pointer's distance from the row's right edge. */
+ pointer: number;
+ rowWidth: number;
+ open: boolean;
+ expanded: boolean;
+}): PanelDrag {
+ const width = resolvePanelWidth(pointer, rowWidth);
+
+ if (expanded) {
+ return width >= panelCeiling(rowWidth)
+ ? { action: "hold" }
+ : { action: "collapse", width };
+ }
+ if (open) {
+ return pointer < DRAG_CLOSE_AT
+ ? { action: "close" }
+ : { action: "resize", width };
+ }
+ return pointer >= DRAG_REOPEN_AT
+ ? { action: "reopen", width }
+ : { action: "hold" };
+}
diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts
index 8e6231d60a29..42348798e738 100644
--- a/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts
+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelSide.ts
@@ -1,3 +1,10 @@
+import {
+ ChatCircleIcon,
+ GitDiffIcon,
+ type Icon,
+ PackageIcon,
+ PulseIcon,
+} from "@phosphor-icons/react";
import { useReviewNavigationStore } from "@posthog/ui/features/code-review/reviewNavigationStore";
import {
DEFAULT_RIGHT_PANEL_SIDE,
@@ -7,10 +14,8 @@ import {
} from "@posthog/ui/features/navigation/rightPanelStore";
/**
- * Put a session's right panel on a side, or close it with `null`. Changes rides
- * the review store so the command menu, PR links, and diff toggles that already
- * open review all land on the same panel, and so that picking another panel
- * closes what they opened.
+ * Changes rides the review store, so every entry point into a review lands on
+ * the same panel and picking another panel closes what they opened.
*/
export function openRightPanelSide(
side: RightPanelSide | null,
@@ -41,14 +46,14 @@ export function toggleRightPanel(taskId: string): void {
}
/**
- * How much of the content row's right edge the panel's switcher is sitting on.
- * Chrome that pins itself to that edge (the panel tree's tab strip and its
- * split and close controls) reads this and stops short, so the switcher can
- * float over the content pane without taking a column of its own or swallowing
- * the clicks meant for what is under it.
+ * How much of the row's right edge the switcher sits on. Chrome pinned to that
+ * edge reads this and stops short, so the switcher can float over the pane.
*/
export const CONTENT_CHROME_RIGHT_VAR = "--content-chrome-right";
+/** Room for one button per side at icon-sm, kept clear by pane and header alike. */
+export const SWITCHER_WIDTH_PX = 112;
+
/** Whether this session's panel is open, for chrome that has to make room. */
export function useRightPanelOpen(taskId: string | undefined): boolean {
const stored = useRightPanelStore((s) =>
@@ -67,3 +72,18 @@ export function useRightPanelOpen(taskId: string | undefined): boolean {
}) != null
);
}
+
+/** The panels the right column can show, in the order the switcher lists them. */
+export const SIDES: Record<RightPanelSide, { label: string; Icon: Icon }> = {
+ timeline: { label: "Timeline", Icon: PulseIcon },
+ artifacts: { label: "Artifacts", Icon: PackageIcon },
+ comments: { label: "Comments", Icon: ChatCircleIcon },
+ changes: { label: "Changes", Icon: GitDiffIcon },
+};
+
+export const SIDE_ORDER: readonly RightPanelSide[] = [
+ "timeline",
+ "artifacts",
+ "comments",
+ "changes",
+];
diff --git a/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts b/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts
index 40f35c1334b6..ae9b023d3194 100644
--- a/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts
+++ b/products/desktop/packages/ui/src/features/navigation/rightPanelStore.ts
@@ -1,59 +1,48 @@
+import {
+ RIGHT_PANEL_DEFAULT_WIDTH,
+ RIGHT_PANEL_MIN_WIDTH,
+} from "@posthog/ui/features/navigation/rightPanelGeometry";
import { electronStorage } from "@posthog/ui/shell/rendererStorage";
import { create } from "zustand";
import { persist } from "zustand/middleware";
-/**
- * Which panel the right column shows. `changes` is also opened from elsewhere,
- * through reviewNavigationStore.
- */
+/** `changes` is also opened from elsewhere, through reviewNavigationStore. */
export type RightPanelSide = "timeline" | "artifacts" | "comments" | "changes";
/** 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;
-const RIGHT_PANEL_DEFAULT_WIDTH = 340;
-
interface RightPanelStore {
width: number;
isResizing: boolean;
/**
- * 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 falls back to
- * `closedByDefault`. Not persisted, because this is within-run memory.
+ * The panel each session has open. `null` is one someone closed; missing is a
+ * session nobody has touched. Within-run memory, so not persisted.
*/
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.
+ * Whether untouched sessions open with the panel away. Persisted, unlike
+ * `sideByKey`: putting the panel away is a standing preference.
*/
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
- * session nobody has drawn yet, which takes whatever it already has as seen:
- * opening an old session is not news. Not persisted, for the same reason
- * `sideByKey` isn't - this is within-run memory.
+ * Artifacts a session had when its panel last showed them, so newer ones can
+ * be marked. Missing means take the current count as seen.
*/
seenArtifactCountByKey: Record<string, number | undefined>;
+ /** Which sessions have their panel out to the whole row. Within-run memory. */
+ expandedByKey: Record<string, boolean | undefined>;
setWidth: (width: number) => void;
setIsResizing: (isResizing: boolean) => void;
setSideForKey: (key: string, side: RightPanelSide | null) => void;
+ setExpandedForKey: (key: string, expanded: boolean) => void;
markArtifactsSeen: (key: string, count: number) => void;
}
/**
- * Which panel a session shows, given what it was left on. An open review mode
- * 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
- * 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.
+ * An open review wins - every entry point into one (command menu, PR links,
+ * diff toggles) expects Changes to appear. Then an explicit choice, then the
+ * default unless the panel was last put away.
*/
export function resolveRightPanelSide({
stored,
@@ -65,28 +54,17 @@ export function resolveRightPanelSide({
isReviewOpen: boolean;
}): RightPanelSide | null {
if (isReviewOpen) return "changes";
- // The review mode has the last word on Changes in both directions. Whoever
- // closes a review closes it from wherever they are (the footer's diff chip,
- // the review shortcut) without touching the panel's own memory, and a panel
- // that kept showing Changes there would draw its title over a review that
- // has dropped its queries.
+ // Review closes from elsewhere (the footer's diff chip, the shortcut) without
+ // touching the panel's memory, so Changes must not outlive it.
if (stored === "changes") return null;
if (stored !== undefined) return stored;
return closedByDefault ? null : DEFAULT_RIGHT_PANEL_SIDE;
}
/**
- * What a session's switcher does with the artifact count it just read: whether
- * to take this count as seen, and whether to mark the button.
- *
- * A session nobody has drawn yet (`seen` undefined) takes its whole count as
- * seen, so opening a run that finished last week doesn't announce its files as
- * new. A panel already showing artifacts keeps up with them, so the mark can
- * never appear behind an open list.
- *
- * Until `ready`, the count has no manifest source behind it and reads as zero.
- * Taking that zero as seen would make the real files look new the moment they
- * load, so an unready count is neither taken as seen nor allowed to mark.
+ * An undrawn session takes its whole count as seen, so an old run doesn't
+ * announce its files as new. Until `ready` the count reads zero with no source
+ * behind it, which must not become the baseline.
*/
export function resolveArtifactMark({
count,
@@ -114,18 +92,21 @@ export const useRightPanelStore = create<RightPanelStore>()(
sideByKey: {},
closedByDefault: false,
seenArtifactCountByKey: {},
+ expandedByKey: {},
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 },
- // 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.
+ // Opening a review is not a vote on the panel, so it leaves the
+ // preference where it was.
closedByDefault: side === "changes" ? state.closedByDefault : !side,
})),
+ setExpandedForKey: (key, expanded) =>
+ set((state) => ({
+ expandedByKey: { ...state.expandedByKey, [key]: expanded },
+ })),
markArtifactsSeen: (key, count) =>
set((state) =>
state.seenArtifactCountByKey[key] === count
@@ -140,9 +121,7 @@ export const useRightPanelStore = create<RightPanelStore>()(
}),
{
name: "right-panel",
- // A resize drag calls setWidth per pointer event, and this backend
- // coalesces the burst behind its debounce instead of writing
- // synchronously on each one, the way every other panel store does.
+ // Coalesces the per-pointer-event setWidth burst behind its debounce.
storage: electronStorage,
partialize: (state) => ({
width: state.width,
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/NavResizeTooltip.tsx b/products/desktop/packages/ui/src/features/sidebar/components/NavResizeTooltip.tsx
new file mode 100644
index 000000000000..81737192f5d2
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/sidebar/components/NavResizeTooltip.tsx
@@ -0,0 +1,21 @@
+import { Kbd } from "@posthog/quill";
+import {
+ formatHotkey,
+ SHORTCUTS,
+} from "@posthog/ui/features/command/keyboard-shortcuts";
+
+/**
+ * Someone reaching for the nav's edge is often after the room, not the width, so
+ * the grip's tooltip offers the shorter way to the same thing.
+ */
+export function NavResizeTooltip() {
+ return (
+ <>
+ Resize
+ <span className="flex items-center gap-1 text-background/70">
+ <Kbd>{formatHotkey(SHORTCUTS.TOGGLE_LEFT_SIDEBAR)}</Kbd>
+ to toggle
+ </span>
+ </>
+ );
+}
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/Sidebar.tsx b/products/desktop/packages/ui/src/features/sidebar/components/Sidebar.tsx
index 7d1f2277cdcd..fb6a801310d0 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/Sidebar.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/Sidebar.tsx
@@ -1,3 +1,4 @@
+import { NavResizeTooltip } from "@posthog/ui/features/sidebar/components/NavResizeTooltip";
import { useSidebarStore } from "@posthog/ui/features/sidebar/sidebarStore";
import { ResizableSidebar } from "@posthog/ui/primitives/ResizableSidebar";
import type React from "react";
@@ -19,6 +20,7 @@ export const Sidebar: React.FC<{ children: React.ReactNode }> = ({
isResizing={isResizing}
setIsResizing={setIsResizing}
side="left"
+ resizeTooltip={<NavResizeTooltip />}
>
{children}
</ResizableSidebar>
diff --git a/products/desktop/packages/ui/src/primitives/ResizableSidebar.tsx b/products/desktop/packages/ui/src/primitives/ResizableSidebar.tsx
index e31a3bf24356..9b434802579d 100644
--- a/products/desktop/packages/ui/src/primitives/ResizableSidebar.tsx
+++ b/products/desktop/packages/ui/src/primitives/ResizableSidebar.tsx
@@ -1,5 +1,6 @@
import { SIDEBAR_MIN_WIDTH } from "@posthog/ui/features/sidebar/constants";
import { PEEK_CLOSE_MARGIN } from "@posthog/ui/primitives/hooks/useSidebarEdgeHoverPeek";
+import { ResizeHandle } from "@posthog/ui/primitives/ResizeHandle";
import React from "react";
// Linear-style drag-to-close: dragging the handle clamps at SIDEBAR_MIN_WIDTH,
@@ -36,6 +37,9 @@ interface ResizableSidebarProps {
onPeekEnter?: () => void;
onPeekLeave?: () => void;
onPeekDismiss?: () => void;
+ // What the resize grip says once the pointer has rested on it. Defaults to
+ // the bare "Resize"; a panel with a shortcut of its own passes that too.
+ resizeTooltip?: React.ReactNode;
}
export const ResizableSidebar: React.FC<ResizableSidebarProps> = ({
@@ -53,6 +57,7 @@ export const ResizableSidebar: React.FC<ResizableSidebarProps> = ({
onPeekEnter,
onPeekLeave,
onPeekDismiss,
+ resizeTooltip = "Resize",
}) => {
// Whether the active drag started on the docked sidebar or the floating
// (peek) one — dragging back out must restore the same mode it closed from.
@@ -73,8 +78,7 @@ export const ResizableSidebar: React.FC<ResizableSidebarProps> = ({
const boxRef = React.useRef<HTMLDivElement | null>(null);
const anchorRef = React.useRef(0);
- const handleMouseDown = (e: React.MouseEvent) => {
- e.preventDefault();
+ const handleDragStart = () => {
dragOriginRef.current = open ? "docked" : "overlay";
dragStartWidthRef.current = width;
dragEndedClosedRef.current = false;
@@ -86,117 +90,58 @@ export const ResizableSidebar: React.FC<ResizableSidebarProps> = ({
: side === "left"
? 0
: window.innerWidth;
- setIsResizing(true);
- document.body.style.cursor = "col-resize";
- document.body.style.userSelect = "none";
};
- // If the component unmounts mid-drag (e.g. a route swap while holding the
- // handle), no mouseup will ever fire — reset the drag's global side effects
- // or the app is left with a col-resize cursor, text selection disabled, and
- // a stuck isResizing that makes the next mount resize on bare mousemove.
- const unmountResetRef = React.useRef({ isResizing, setIsResizing });
- unmountResetRef.current = { isResizing, setIsResizing };
- React.useEffect(
- () => () => {
- const { isResizing: active, setIsResizing: reset } =
- unmountResetRef.current;
- if (active) {
- reset(false);
- document.body.style.cursor = "";
- document.body.style.userSelect = "";
- }
- },
- [],
- );
-
- React.useEffect(() => {
- const handleMouseMove = (e: MouseEvent) => {
- if (!isResizing) return;
-
- // Distance from the panel's own anchored edge, regardless of side, which
- // is the width the pointer is asking for.
- const pointer =
- side === "left"
- ? e.clientX - anchorRef.current
- : anchorRef.current - e.clientX;
- const maxWidth = window.innerWidth * 0.5;
- const clamped = Math.max(minWidth, Math.min(maxWidth, pointer));
-
- if (open) {
- if (pointer < DRAG_COLLAPSE_AT && setOpen) {
- setOpen(false);
- dragEndedClosedRef.current = true;
- return;
- }
- setWidth(clamped);
+ const pointerWidth = (e: MouseEvent) =>
+ side === "left"
+ ? e.clientX - anchorRef.current
+ : anchorRef.current - e.clientX;
+
+ const handleDrag = (e: MouseEvent) => {
+ const pointer = pointerWidth(e);
+ const clamped = Math.max(
+ minWidth,
+ Math.min(window.innerWidth * 0.5, pointer),
+ );
+
+ if (open) {
+ if (pointer < DRAG_COLLAPSE_AT && setOpen) {
+ setOpen(false);
+ dragEndedClosedRef.current = true;
return;
}
-
- if (peek) {
- if (pointer < DRAG_COLLAPSE_AT) {
- onPeekDismiss?.();
- dragEndedClosedRef.current = true;
- return;
- }
- setWidth(clamped);
+ setWidth(clamped);
+ return;
+ }
+
+ if (peek) {
+ if (pointer < DRAG_COLLAPSE_AT) {
+ onPeekDismiss?.();
+ dragEndedClosedRef.current = true;
return;
}
+ setWidth(clamped);
+ return;
+ }
+
+ // Closed mid-drag and still holding: dragging back out pops it open in
+ // whichever mode the drag started from.
+ if (pointer >= DRAG_REOPEN_AT) {
+ if (dragOriginRef.current === "docked" && setOpen) setOpen(true);
+ else onPeekEnter?.();
+ dragEndedClosedRef.current = false;
+ setWidth(clamped);
+ }
+ };
- // Closed mid-drag and still holding: dragging back out pops it open in
- // whichever mode the drag started from.
- if (pointer >= DRAG_REOPEN_AT) {
- if (dragOriginRef.current === "docked" && setOpen) {
- setOpen(true);
- } else {
- onPeekEnter?.();
- }
- dragEndedClosedRef.current = false;
- setWidth(clamped);
- }
- };
-
- const handleMouseUp = (e: MouseEvent) => {
- if (!isResizing) return;
- setIsResizing(false);
- document.body.style.cursor = "";
- document.body.style.userSelect = "";
- // Drag ended closed (drag-to-close or peek dismiss): the collapse walk
- // clamped the store width to min on the way down — restore the pre-drag
- // width so the next open comes back at the user's chosen size.
- if (dragEndedClosedRef.current) {
- setWidth(dragStartWidthRef.current);
- }
- if (!open && peek) {
- const pointer =
- side === "left"
- ? e.clientX - anchorRef.current
- : anchorRef.current - e.clientX;
- if (pointer > width + PEEK_CLOSE_MARGIN) onPeekLeave?.();
- }
- };
-
- document.addEventListener("mousemove", handleMouseMove);
- document.addEventListener("mouseup", handleMouseUp);
-
- return () => {
- document.removeEventListener("mousemove", handleMouseMove);
- document.removeEventListener("mouseup", handleMouseUp);
- };
- }, [
- setWidth,
- isResizing,
- setIsResizing,
- side,
- minWidth,
- open,
- peek,
- width,
- setOpen,
- onPeekEnter,
- onPeekLeave,
- onPeekDismiss,
- ]);
+ const handleDragEnd = (e: MouseEvent) => {
+ // The collapse walk clamped the stored width to min on the way down.
+ if (dragEndedClosedRef.current) setWidth(dragStartWidthRef.current);
+ // Released well clear of a floating panel: the peek has been left behind.
+ if (!open && peek && pointerWidth(e) > width + PEEK_CLOSE_MARGIN) {
+ onPeekLeave?.();
+ }
+ };
const isLeft = side === "left";
// Closed = overlay mode: the box collapses to 0 width but the panel stays
@@ -279,45 +224,22 @@ export const ResizableSidebar: React.FC<ResizableSidebarProps> = ({
}
>
{children}
- {/* Resize handle lives inside the panel so it rides along in both the
- docked and floating states. */}
- {(open || overlayVisible) && (
- <button
- type="button"
- aria-label={`Resize ${side} sidebar`}
- // Mouse/drag-only affordance: there is no keyboard resize model,
- // so keep it out of the tab order rather than expose a focusable
- // control that announces a resize action and does nothing.
- tabIndex={-1}
- onMouseDown={handleMouseDown}
- className={`no-drag group absolute top-0 bottom-0 flex w-2 cursor-col-resize justify-center border-0 bg-transparent p-0 ${
- handleArmed || isResizing ? "" : "pointer-events-none"
- }`}
- style={{
- left: isLeft ? undefined : -5,
- right: isLeft ? -5 : undefined,
- zIndex: 100,
- }}
- >
- <span
- className={`h-full w-px transition-colors duration-150 ease-out ${
- isResizing
- ? "bg-primary"
- : handleArmed
- ? "bg-transparent delay-100 group-hover:bg-primary"
- : "bg-transparent"
- }`}
- />
- </button>
+ {/* Rides along in both the docked and floating states, and stays
+ mounted through a drag that closes the panel - it owns the gesture's
+ listeners, so unmounting it mid-drag would strand them. */}
+ {(open || overlayVisible || isResizing) && (
+ <ResizeHandle
+ edge={isLeft ? "right" : "left"}
+ tooltip={resizeTooltip}
+ isResizing={isResizing}
+ setIsResizing={setIsResizing}
+ armed={handleArmed}
+ onDragStart={handleDragStart}
+ onDrag={handleDrag}
+ onDragEnd={handleDragEnd}
+ />
)}
</div>
- {/* Full-screen shield while dragging: keeps the col-resize cursor no
- matter what the pointer crosses (content sets its own cursors, and
- webview tabs would swallow the drag entirely). Outside the panel so
- the panel's pointer-events:none while drag-closed can't disable it. */}
- {isResizing && (
- <div className="fixed inset-0 z-[200] cursor-col-resize" />
- )}
</div>
);
};
diff --git a/products/desktop/packages/ui/src/primitives/ResizeHandle.stories.tsx b/products/desktop/packages/ui/src/primitives/ResizeHandle.stories.tsx
new file mode 100644
index 000000000000..5743cc5e5e51
--- /dev/null
+++ b/products/desktop/packages/ui/src/primitives/ResizeHandle.stories.tsx
@@ -0,0 +1,72 @@
+import { Kbd } from "@posthog/quill";
+import { ResizeHandle } from "@posthog/ui/primitives/ResizeHandle";
+import type { Meta, StoryObj } from "@storybook/react-vite";
+import { useRef, useState } from "react";
+
+/**
+ * The grab strip a resizable panel is dragged by. Rest the pointer on the
+ * hairline for a second to see what it says, and drag it to see the cursor hold
+ * across the whole window.
+ */
+const meta: Meta<typeof ResizeHandle> = {
+ title: "Primitives/ResizeHandle",
+ component: ResizeHandle,
+ parameters: { layout: "fullscreen" },
+ args: { edge: "left", tooltip: "Resize", isResizing: false },
+ render: (args) => {
+ const Demo = () => {
+ const [width, setWidth] = useState(340);
+ const [isResizing, setIsResizing] = useState(false);
+ const boxRef = useRef<HTMLDivElement>(null);
+ const rightRef = useRef(0);
+ return (
+ // A transform, like every real caller has: it makes this the containing
+ // block for a fixed shield, which is why the shield is portaled out.
+ <div className="flex h-screen" style={{ transform: "translateX(0)" }}>
+ <div className="flex-1 bg-fill-hover p-3 text-[13px]">
+ Drag the grip. The cursor holds across this pane too.
+ </div>
+ <div
+ ref={boxRef}
+ className="relative border-border border-l bg-background p-3 text-[13px]"
+ style={{ width }}
+ >
+ {width}px
+ <ResizeHandle
+ {...args}
+ isResizing={isResizing}
+ setIsResizing={setIsResizing}
+ onDragStart={() => {
+ rightRef.current =
+ boxRef.current?.getBoundingClientRect().right ?? 0;
+ }}
+ onDrag={(event) =>
+ setWidth(Math.max(120, rightRef.current - event.clientX))
+ }
+ />
+ </div>
+ </div>
+ );
+ };
+ return <Demo />;
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof ResizeHandle>;
+
+export const Resting: Story = {};
+
+export const WithShortcut: Story = {
+ args: {
+ tooltip: (
+ <>
+ Resize
+ <span className="flex items-center gap-1 text-background/70">
+ <Kbd>⌘B</Kbd>
+ to toggle
+ </span>
+ </>
+ ),
+ },
+};
diff --git a/products/desktop/packages/ui/src/primitives/ResizeHandle.tsx b/products/desktop/packages/ui/src/primitives/ResizeHandle.tsx
new file mode 100644
index 000000000000..e993a9fd0f53
--- /dev/null
+++ b/products/desktop/packages/ui/src/primitives/ResizeHandle.tsx
@@ -0,0 +1,139 @@
+import { Tooltip } from "@base-ui/react/tooltip";
+import React from "react";
+import { createPortal } from "react-dom";
+
+/** Long: a grip is a target people cross on the way elsewhere. */
+const TOOLTIP_DELAY_MS = 1000;
+
+function setDragCursor(dragging: boolean): void {
+ document.body.style.cursor = dragging ? "col-resize" : "";
+ document.body.style.userSelect = dragging ? "none" : "";
+}
+
+/**
+ * The grab strip a resizable panel is dragged by, and the whole gesture behind
+ * it: the hit area, the hairline, the window-wide cursor shield, and the
+ * mousemove/mouseup lifecycle. Callers supply only what a width means to them.
+ */
+export function ResizeHandle({
+ edge,
+ tooltip,
+ isResizing,
+ setIsResizing,
+ armed = true,
+ onDragStart,
+ onDrag,
+ onDragEnd,
+}: {
+ /** Which edge of its container the grip straddles. The tooltip opens that way. */
+ edge: "left" | "right";
+ /** Shown once the pointer rests on the grip, and follows it up and down. */
+ tooltip?: React.ReactNode;
+ isResizing: boolean;
+ setIsResizing: (isResizing: boolean) => void;
+ /**
+ * False parks the grip. A panel sliding under a stationary pointer leaves a
+ * hover the browser never recomputes, lighting the hairline for nothing.
+ */
+ armed?: boolean;
+ /** Capture whatever the drag measures from. */
+ onDragStart?: () => void;
+ onDrag: (event: MouseEvent) => void;
+ onDragEnd?: (event: MouseEvent) => void;
+}) {
+ const handlers = React.useRef({ onDrag, onDragEnd, setIsResizing });
+ React.useEffect(() => {
+ handlers.current = { onDrag, onDragEnd, setIsResizing };
+ });
+
+ React.useEffect(() => {
+ if (!isResizing) return;
+
+ const move = (event: MouseEvent) => handlers.current.onDrag(event);
+ const up = (event: MouseEvent) => {
+ handlers.current.setIsResizing(false);
+ setDragCursor(false);
+ handlers.current.onDragEnd?.(event);
+ };
+
+ document.addEventListener("mousemove", move);
+ document.addEventListener("mouseup", up);
+ return () => {
+ document.removeEventListener("mousemove", move);
+ document.removeEventListener("mouseup", up);
+ // Unmounting mid-drag means no mouseup ever lands, which would strand the
+ // cursor and a stuck isResizing. Redundant when the drag ended normally.
+ setDragCursor(false);
+ handlers.current.setIsResizing(false);
+ };
+ }, [isResizing]);
+
+ const grip = (
+ <button
+ type="button"
+ aria-label="Resize"
+ // Mouse-only: there is no keyboard resize model to expose a control for.
+ tabIndex={-1}
+ onMouseDown={(event) => {
+ event.preventDefault();
+ onDragStart?.();
+ setIsResizing(true);
+ setDragCursor(true);
+ }}
+ className={`no-drag group absolute inset-y-0 z-100 flex w-3 cursor-col-resize justify-center border-0 bg-transparent p-0 ${
+ edge === "left" ? "-left-1.5" : "-right-1.5"
+ } ${armed || isResizing ? "" : "pointer-events-none"}`}
+ >
+ <span
+ className={`h-full w-px transition-colors duration-150 ease-out ${
+ isResizing
+ ? "bg-primary"
+ : armed
+ ? "bg-transparent delay-100 group-hover:bg-primary"
+ : "bg-transparent"
+ }`}
+ />
+ </button>
+ );
+
+ return (
+ <>
+ {tooltip ? (
+ // Its own provider: a grip is not part of the group that skips its
+ // delay once one tooltip has opened.
+ <Tooltip.Provider delay={TOOLTIP_DELAY_MS}>
+ <Tooltip.Root disabled={isResizing} trackCursorAxis="y">
+ <Tooltip.Trigger render={grip} />
+ <Tooltip.Portal>
+ <Tooltip.Positioner
+ data-quill
+ data-quill-portal="tooltip"
+ side={edge}
+ sideOffset={8}
+ className="isolate"
+ >
+ {/* Uniform padding over quill's 6px/12px split, and a line
+ height that hugs the text: a kbd chip fills its line box,
+ so leading above a bare line reads as a lopsided box. */}
+ <Tooltip.Popup className="quill-tooltip__content flex flex-col items-start gap-1 p-2 text-left leading-tight">
+ {tooltip}
+ </Tooltip.Popup>
+ </Tooltip.Positioner>
+ </Tooltip.Portal>
+ </Tooltip.Root>
+ </Tooltip.Provider>
+ ) : (
+ grip
+ )}
+ {/* Portaled to the body: every caller sits inside a transformed panel,
+ which would otherwise be the containing block for a fixed shield and
+ confine it there. pointer-events-auto because a drag-closed panel
+ turns its own off, and a shield that is no hit target gives no cursor. */}
+ {isResizing &&
+ createPortal(
+ <div className="pointer-events-auto fixed inset-0 z-[200] cursor-col-resize" />,
+ document.body,
+ )}
+ </>
+ );
+}
diff --git a/products/desktop/packages/ui/src/primitives/hooks/useObservedWidth.ts b/products/desktop/packages/ui/src/primitives/hooks/useObservedWidth.ts
new file mode 100644
index 000000000000..d469856f8ebd
--- /dev/null
+++ b/products/desktop/packages/ui/src/primitives/hooks/useObservedWidth.ts
@@ -0,0 +1,50 @@
+import { type RefObject, useEffect, useState } from "react";
+
+function observeWidth(
+ element: Element,
+ onWidth: (width: number) => void,
+): () => void {
+ const observer = new ResizeObserver(([entry]) => {
+ onWidth(entry?.contentRect.width ?? element.getBoundingClientRect().width);
+ });
+ observer.observe(element);
+ return () => observer.disconnect();
+}
+
+/**
+ * How wide an element's parent is. For a layer positioned against its parent
+ * rather than laid out in it, which cannot read that width from its own box.
+ * Zero until the first measurement.
+ */
+export function useParentWidth(ref: RefObject<HTMLElement | null>): number {
+ const [width, setWidth] = useState(0);
+
+ useEffect(() => {
+ const parent = ref.current?.parentElement;
+ return parent ? observeWidth(parent, setWidth) : undefined;
+ }, [ref]);
+
+ return width;
+}
+
+/**
+ * What a container query asks, in the form needed when the answer decides
+ * whether to *mount* something: a subtree hidden by a query still renders and
+ * still runs its queries. Returns a boolean so the caller doesn't re-render per
+ * pixel. False until the first measurement.
+ */
+export function useIsWiderThan(
+ ref: RefObject<HTMLElement | null>,
+ minWidth: number,
+): boolean {
+ const [wide, setWide] = useState(false);
+
+ useEffect(() => {
+ const element = ref.current;
+ return element
+ ? observeWidth(element, (width) => setWide(width >= minWidth))
+ : undefined;
+ }, [ref, minWidth]);
+
+ return wide;
+}
diff --git a/products/desktop/packages/ui/src/styles/globals.css b/products/desktop/packages/ui/src/styles/globals.css
index c31187652a34..e5dd1f418023 100644
--- a/products/desktop/packages/ui/src/styles/globals.css
+++ b/products/desktop/packages/ui/src/styles/globals.css
@@ -1274,12 +1274,22 @@ body.ph-window-blurred .app-fade-in {
--terminal-selection-fg: #e6e6e6;
}
-/* Buttons and menu items should have pointer cursor */
-button,
-[type="button"],
-[role="button"],
-[role="menuitem"] {
- cursor: pointer;
+/*
+ * Buttons and menu items should have pointer cursor.
+ *
+ * Layered, because unlayered declarations outrank every `@layer` - this rule
+ * used to beat any `cursor-*` utility written on a button, so a resize grip
+ * asking for `col-resize` and a disabled button asking for `not-allowed` both
+ * silently got `pointer` instead. In `base` it does what a reset should: set
+ * the default, and lose to anything that names a cursor of its own.
+ */
+@layer base {
+ button,
+ [type="button"],
+ [role="button"],
+ [role="menuitem"] {
+ cursor: pointer;
+ }
}
.quill-button.quill-button--variant-outline:hover {
@@ -1444,6 +1454,16 @@ button,
opacity: 1;
}
+/*
+ * @posthog/quill Drawer — the right panel expands into one, and its width is
+ * whatever the reader drags it to (an inline style on the popup). Quill's right
+ * drawer is a sheet: 75% of the window capped at 24rem, with its children in a
+ * centered 32rem column. Both caps have to come off for a panel that is expanded
+ * precisely to get more room, and the content column has to fill the popup's
+ * flex column instead of sitting in the middle of it. Unlayered, because those
+ * caps are utility classes on the elements themselves, and a rule inside
+ * @layer components would lose to them.
+ */
/*
* @posthog/quill Tabs — quill paints an active trigger `var(--background)` with
* `!important`, and `!important` inverts cascade-layer order, so no utility