Skip to content

Your lightweight open-source personal agent.

fix(webui): keep permission hints outside locked-thread drafts

chengyongru0bd8456076d8
diff --git a/webui/browser/workspace-access-hint.spec.ts b/webui/browser/workspace-access-hint.spec.ts
index 424747b22..1a7422e02 100644
--- a/webui/browser/workspace-access-hint.spec.ts
+++ b/webui/browser/workspace-access-hint.spec.ts
@@ -6,10 +6,10 @@ test.beforeEach(async ({ page }) => {
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
});
-for (const width of [1280, 390]) for (const variant of ["hero", "thread"]) for (const permission of ["Full Access", "Default Permission"]) {
+for (const width of [1280, 390]) for (const variant of ["hero", "thread", "locked-thread"]) for (const permission of ["Full Access", "Default Permission"]) {
test(`${variant} ${permission} hint avoids short and multiline drafts at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
- await page.goto(`/browser/fixture.html?case=${variant === "hero" ? "new-chat-skeleton" : "mobile-chat-layout&project"}`);
+ await page.goto(`/browser/fixture.html?case=${variant === "hero" ? "new-chat-skeleton" : variant === "thread" ? "mobile-chat-layout&project" : "mobile-chat-layout&no-context"}`);
const input = page.getByRole("textbox", { name: "Message input" });
const access = page.locator(".thread-composer-access");
const hint = page.locator("[data-radix-popper-content-wrapper] > [data-state]");
@@ -28,6 +28,12 @@ for (const width of [1280, 390]) for (const variant of ["hero", "thread"]) for (
expect(bounds.y >= editor.y + editor.height || bounds.y + bounds.height <= editor.y).toBe(true);
expect(bounds.x).toBeGreaterThanOrEqual(0);
expect(bounds.x + bounds.width).toBeLessThanOrEqual(width);
+ expect(bounds.y).toBeGreaterThanOrEqual(0);
+ expect(bounds.y + bounds.height).toBeLessThanOrEqual(900);
+ if (await hint.getAttribute("data-side") === "top") {
+ const composer = (await page.locator(".thread-composer-form").boundingBox())!;
+ expect(bounds.y + bounds.height).toBeLessThanOrEqual(composer.y - 7);
+ }
if (trigger.y + trigger.height + bounds.height + 16 <= 900) {
expect(bounds.y).toBeGreaterThanOrEqual(trigger.y + trigger.height + 7);
}
@@ -36,3 +42,24 @@ for (const width of [1280, 390]) for (const variant of ["hero", "thread"]) for (
}
});
}
+
+
+test("a visible permission hint stays above the composer as a locked-thread draft grows", async ({ page }) => {
+ await page.setViewportSize({ width: 1280, height: 600 });
+ await page.goto("/browser/fixture.html?case=mobile-chat-layout&no-context");
+ const input = page.getByRole("textbox", { name: "Message input" });
+ const hint = page.locator("[data-radix-popper-content-wrapper] > [data-state]");
+ await input.fill("Keep this draft visible.");
+ await page.locator(".thread-composer-access").hover();
+ await expect(hint).toBeVisible();
+ await expect(hint).toHaveAttribute("data-side", "top");
+ await page.keyboard.insertText("\nKeep this draft visible.".repeat(12));
+ await expect(input).toHaveValue("Keep this draft visible." + "\nKeep this draft visible.".repeat(12));
+ await expect.poll(async () => {
+ const bounds = (await hint.boundingBox())!;
+ const composer = (await page.locator(".thread-composer-form").boundingBox())!;
+ return composer.y - bounds.y - bounds.height;
+ }).toBeGreaterThanOrEqual(7);
+ const bounds = (await hint.boundingBox())!;
+ expect(bounds.y).toBeGreaterThanOrEqual(0);
+});
diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx
index d2974386b..b87fe5267 100644
--- a/webui/src/components/thread/ThreadComposer.tsx
+++ b/webui/src/components/thread/ThreadComposer.tsx
@@ -2500,6 +2500,7 @@ export function ThreadComposer({
scope={workspaceScope}
disabled={interactionDisabled || workspaceScopeDisabled}
onChange={onWorkspaceScopeChange}
+ hintBoundaryRef={formRef}
/>
) : null;
const workspaceControl = showProjectPicker ? (
diff --git a/webui/src/components/thread/WorkspaceControls.tsx b/webui/src/components/thread/WorkspaceControls.tsx
index 20a3de7de..30785b17b 100644
--- a/webui/src/components/thread/WorkspaceControls.tsx
+++ b/webui/src/components/thread/WorkspaceControls.tsx
@@ -1,12 +1,12 @@
import { FullAccessIcon, RestrictedAccessIcon, WorkspaceIcon } from "@/components/icons/product-icons";
-import type { HTMLAttributes, ReactElement } from "react";
+import type { HTMLAttributes, ReactElement, RefObject } from "react";
import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { ArrowLeft, ArrowRight, Check, ChevronDown, ChevronRight, FolderSearch, History, Search, Star } from "lucide-react";
import { useTranslation } from "react-i18next";
import { ToggleButton } from "@/components/ui/toggle-button";
import { Button } from "@/components/ui/button";
import { floatingItemClassName, floatingItemFocusClassName } from "@/components/ui/floating-surface";
-import { HoverHint } from "@/components/ui/tooltip";
+import { HoverHint, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Input, SearchInput } from "@/components/ui/input";
import { Dialog, DialogContent, DialogTrigger, DialogTitle, DialogDescription } from "@/components/ui/dialog";
@@ -684,14 +684,21 @@ export function WorkspaceAccessMenu({
scope,
disabled,
onChange,
+ hintBoundaryRef,
}: {
scope: WorkspaceScopePayload;
disabled?: boolean;
onChange?: (scope: WorkspaceScopePayload) => void;
+ hintBoundaryRef: RefObject<HTMLElement>;
}) {
const { t } = useTranslation();
const coarsePointer = useMediaQuery("(pointer: coarse)");
const [open, setOpen] = useState(false);
+ const [hintOpen, setHintOpen] = useState(false);
+ const [hint, setHint] = useState<HTMLDivElement | null>(null);
+ const [hintPosition, setHintPosition] = useState<{ side: "top" | "bottom"; sideOffset: number }>({ side: "bottom", sideOffset: 8 });
+ const triggerRef = useRef<HTMLButtonElement>(null);
+ const hintEnabled = !open && !coarsePointer;
const restoreTriggerFocus = useRef(true);
const descriptionId = useId();
const isFull = scope.access_mode === "full";
@@ -701,25 +708,53 @@ export function WorkspaceAccessMenu({
const AccessIcon = isFull ? FullAccessIcon : RestrictedAccessIcon;
useEffect(() => { if (disabled || !onChange) setOpen(false); }, [disabled, onChange]);
+ useEffect(() => { if (!hintEnabled) setHintOpen(false); }, [hintEnabled]);
+ useLayoutEffect(() => {
+ const trigger = triggerRef.current;
+ const boundary = hintBoundaryRef.current;
+ if (!hint || !trigger || !boundary) return;
+ const placeHint = () => {
+ const triggerBounds = trigger.getBoundingClientRect();
+ const belowFits = triggerBounds.bottom + 8 + hint.offsetHeight <= window.innerHeight;
+ // A locked thread has no project row below the toolbar. Flip above the
+ // whole composer, not above the permission button into the draft.
+ const next = belowFits
+ ? { side: "bottom" as const, sideOffset: 8 }
+ : { side: "top" as const, sideOffset: triggerBounds.top - boundary.getBoundingClientRect().top + 8 };
+ setHintPosition(previous => previous.side === next.side && previous.sideOffset === next.sideOffset ? previous : next);
+ };
+ placeHint();
+ const observer = new ResizeObserver(placeHint);
+ observer.observe(hint);
+ observer.observe(boundary);
+ window.addEventListener("resize", placeHint);
+ return () => { observer.disconnect(); window.removeEventListener("resize", placeHint); };
+ }, [hint, hintBoundaryRef]);
return (
<DropdownMenu open={open} onOpenChange={setOpen}>
- <HoverHint enabled={!open && !coarsePointer} content={description} side="bottom" sideOffset={8}>
- <DropdownMenuTrigger asChild disabled={disabled || !onChange}>
- <button type="button" aria-label={accessAriaLabel} aria-describedby={descriptionId}
- onPointerDown={() => { restoreTriggerFocus.current = false; }}
- onKeyDown={() => { restoreTriggerFocus.current = true; }}
- className={cn(
- "thread-composer-access touch-target inline-flex h-8 min-w-0 max-w-full shrink items-center gap-1.5 rounded-md px-2 text-[12px] font-medium outline-none transition-colors motion-reduce:transition-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55",
- isFull ? "text-orange-600 hover:text-orange-700 dark:text-orange-300 dark:hover:text-orange-200" : "text-muted-foreground hover:text-foreground",
- )}>
- <AccessIcon className="h-3.5 w-3.5 shrink-0" />
- <span className="min-w-0 truncate">{label}</span>
- <ChevronDown className="h-3 w-3 shrink-0" aria-hidden />
- <span id={descriptionId} className="sr-only">{description}</span>
- </button>
- </DropdownMenuTrigger>
- </HoverHint>
+ <TooltipProvider>
+ <Tooltip open={hintEnabled && hintOpen} onOpenChange={next => setHintOpen(hintEnabled && next)}>
+ <TooltipTrigger asChild>
+ <DropdownMenuTrigger asChild disabled={disabled || !onChange}>
+ <button ref={triggerRef} type="button" aria-label={accessAriaLabel} aria-describedby={descriptionId}
+ onPointerDown={() => { restoreTriggerFocus.current = false; }}
+ onKeyDown={() => { restoreTriggerFocus.current = true; }}
+ className={cn(
+ "thread-composer-access touch-target inline-flex h-8 min-w-0 max-w-full shrink items-center gap-1.5 rounded-md px-2 text-[12px] font-medium outline-none transition-colors motion-reduce:transition-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-55",
+ isFull ? "text-orange-600 hover:text-orange-700 dark:text-orange-300 dark:hover:text-orange-200" : "text-muted-foreground hover:text-foreground",
+ )}>
+ <AccessIcon className="h-3.5 w-3.5 shrink-0" />
+ <span className="min-w-0 truncate">{label}</span>
+ <ChevronDown className="h-3 w-3 shrink-0" aria-hidden />
+ <span id={descriptionId} className="sr-only">{description}</span>
+ </button>
+ </DropdownMenuTrigger>
+ </TooltipTrigger>
+ <TooltipContent ref={setHint} side={hintPosition.side} sideOffset={hintPosition.sideOffset}
+ className="max-w-[min(28rem,calc(100vw-2rem))] whitespace-pre-wrap break-words">{description}</TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
<DropdownMenuContent side="top" align="start" sideOffset={8} aria-label={t("thread.composer.workspace.accessAria")}
onPointerDownCapture={() => { restoreTriggerFocus.current = false; }}
onKeyDownCapture={() => { restoreTriggerFocus.current = true; }}
diff --git a/webui/src/dev/gallery/conversation.tsx b/webui/src/dev/gallery/conversation.tsx
index 5f5d43edd..4a7f2d857 100644
--- a/webui/src/dev/gallery/conversation.tsx
+++ b/webui/src/dev/gallery/conversation.tsx
@@ -119,12 +119,13 @@ function WorkspacePreview() {
const { t: g } = useGalleryTranslation();
const [scope, setScope] = useState(projectScope);
const [mode, setMode] = useState<"ready" | "disabled">("ready");
+ const hintBoundaryRef = useRef<HTMLDivElement>(null);
return <div className="space-y-4">
<StatePicker label={g("previews.workspace.state")} value={mode} options={["ready", "disabled"]} onChange={setMode} />
- <div className="flex min-w-0 flex-wrap items-center gap-1">
+ <div ref={hintBoundaryRef} className="flex min-w-0 flex-wrap items-center gap-1">
<WorkspaceProjectPicker scope={scope} defaultScope={projectScope} controls={workspaceCatalog.controls}
disabled={mode === "disabled"} onLoadProjects={loadExampleProjects} onChange={setScope} />
- <WorkspaceAccessMenu scope={scope} disabled={mode === "disabled"} onChange={setScope} />
+ <WorkspaceAccessMenu scope={scope} disabled={mode === "disabled"} onChange={setScope} hintBoundaryRef={hintBoundaryRef} />
</div>
<p role="status" className="text-sm text-muted-foreground">{scope.project_path} · {t("thread.composer.workspace.full")}: {t(scope.access_mode === "full" ? "settings.values.on" : "settings.values.off")}</p>
</div>;