From e3a1af2ed3b03134f57a44e7ca7f9873e0142168 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Wed, 11 Nov 2026 17:06:45 +0800 Subject: [PATCH] fix(webui): add a close control to the expanded context panel (#6629) --- webui/browser/context-graph.spec.ts | 9 +++++++++ webui/src/components/thread/ComposerUsagePopover.tsx | 2 +- webui/src/components/thread/ContextGraphScene.tsx | 12 ++++++++---- webui/src/components/thread/ContextInspector.tsx | 8 ++++---- webui/src/tests/composer-usage-popover.test.tsx | 10 ++++++++++ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/webui/browser/context-graph.spec.ts b/webui/browser/context-graph.spec.ts index dd167c8fc..8d4aa202e 100644 --- a/webui/browser/context-graph.spec.ts +++ b/webui/browser/context-graph.spec.ts @@ -53,6 +53,15 @@ test("graph keyboard controls, pointer hit targets, pixels and replay agree", as await expect(page.getByRole("progressbar")).toHaveAttribute("aria-valuenow", "20"); }); +test("closes the context sidebar from its own control", async ({ page }) => { + await page.goto("/browser/context-graph.html?single&drawer"); + await page.getByTestId("composer-context-usage").click(); + const sidebar = page.getByTestId("context-sidebar"); + await expect(sidebar).toBeVisible(); + await sidebar.getByRole("button", { name: "Close" }).click(); + await expect(sidebar).toHaveCount(0); +}); + test.describe("touch graph", () => { test.use({ viewport: { width: 390, height: 740 }, hasTouch: true }); test("recovers batched drawer visibility, replays and opens a file by touch", async ({ page }) => { diff --git a/webui/src/components/thread/ComposerUsagePopover.tsx b/webui/src/components/thread/ComposerUsagePopover.tsx index 686d0c5c0..b33a3e6b3 100644 --- a/webui/src/components/thread/ComposerUsagePopover.tsx +++ b/webui/src/components/thread/ComposerUsagePopover.tsx @@ -176,7 +176,7 @@ export function ComposerUsagePopover({ }; const inspector = { setOpen(false); onOpenFile(path); } : undefined} />; + onClose={narrow ? undefined : close} onOpenFile={onOpenFile ? (path) => { setOpen(false); onOpenFile(path); } : undefined} />; const onPanelKeyDown = (event: KeyboardEvent) => { if (event.key === "Escape" && !event.defaultPrevented) { event.preventDefault(); close(); } }; diff --git a/webui/src/components/thread/ContextGraphScene.tsx b/webui/src/components/thread/ContextGraphScene.tsx index 7a282ca58..fe2b35a42 100644 --- a/webui/src/components/thread/ContextGraphScene.tsx +++ b/webui/src/components/thread/ContextGraphScene.tsx @@ -1,6 +1,6 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import { useReducedMotion } from "motion/react"; -import { Maximize2, Minimize2 } from "lucide-react"; +import { Maximize2, Minimize2, X } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Popover, PopoverAnchor, PopoverContent } from "@/components/ui/popover"; import { cn } from "@/lib/utils"; @@ -12,8 +12,8 @@ import { paintGraph, readGraphPalette, type GraphPalette } from "./graph-canvas" const surface = "context-inspector-surface select-none rounded-[20px] bg-card"; -export const ContextGraphScene = memo(function ContextGraphScene({ graph, epoch, expanded, onExpand, onOpenFile, onReady, sidebar = false }: { - graph: ContextGraph; epoch?: string; expanded: boolean; onExpand?: () => void; onOpenFile?: (path: string) => void; onReady?: (graph: ContextGraph) => void; sidebar?: boolean; +export const ContextGraphScene = memo(function ContextGraphScene({ graph, epoch, expanded, onExpand, onClose, onOpenFile, onReady, sidebar = false }: { + graph: ContextGraph; epoch?: string; expanded: boolean; onExpand?: () => void; onClose?: () => void; onOpenFile?: (path: string) => void; onReady?: (graph: ContextGraph) => void; sidebar?: boolean; }) { const { t } = useTranslation(); const container = useRef(null); @@ -222,7 +222,7 @@ export const ContextGraphScene = memo(function ContextGraphScene({ graph, epoch, onBlur={() => { focused.current = null; setHovered(null); schedule(); }} onClick={() => setActive((path) => path === node.path ? null : node.path)}>{node.name})} ), [graph.nodes, active, schedule]); - return
{ if (!(e.target instanceof Node) || !e.currentTarget.contains(e.target)) return; if (e.button !== 0 || !e.isPrimary || (e.target instanceof Element && e.target.closest("button"))) return; @@ -273,6 +273,10 @@ export const ContextGraphScene = memo(function ContextGraphScene({ graph, epoch, interacted.current = false; setView({ k, x: size.width / 2 - (left + right) / 2 * k, y: (size.height + 22) / 2 - (top + bottom) / 2 * k }); }}> + {onClose && } {onExpand &&