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; }) { const { t } = useTranslation(); const coarsePointer = useMediaQuery("(pointer: coarse)"); const [open, setOpen] = useState(false); + const [hintOpen, setHintOpen] = useState(false); + const [hint, setHint] = useState(null); + const [hintPosition, setHintPosition] = useState<{ side: "top" | "bottom"; sideOffset: number }>({ side: "bottom", sideOffset: 8 }); + const triggerRef = useRef(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 ( - - - - - + + setHintOpen(hintEnabled && next)}> + + + + + + {description} + + { 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(null); return
-
+
- +

{scope.project_path} ยท {t("thread.composer.workspace.full")}: {t(scope.access_mode === "full" ? "settings.values.on" : "settings.values.off")}

;