fix(webui): keep permission hints outside locked-thread drafts
This commit is contained in:
1 parent
2b7d686117
commit
0bd8456076
4 files changed
+86
-22
No files matched your search
@@ -6,10 +6,10 @@ test.beforeEach(async ({ page }) => {
|
|||||||
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
|
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 }) => {
|
test(`${variant} ${permission} hint avoids short and multiline drafts at ${width}px`, async ({ page }) => {
|
||||||
await page.setViewportSize({ width, height: 900 });
|
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 input = page.getByRole("textbox", { name: "Message input" });
|
||||||
const access = page.locator(".thread-composer-access");
|
const access = page.locator(".thread-composer-access");
|
||||||
const hint = page.locator("[data-radix-popper-content-wrapper] > [data-state]");
|
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.y >= editor.y + editor.height || bounds.y + bounds.height <= editor.y).toBe(true);
|
||||||
expect(bounds.x).toBeGreaterThanOrEqual(0);
|
expect(bounds.x).toBeGreaterThanOrEqual(0);
|
||||||
expect(bounds.x + bounds.width).toBeLessThanOrEqual(width);
|
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) {
|
if (trigger.y + trigger.height + bounds.height + 16 <= 900) {
|
||||||
expect(bounds.y).toBeGreaterThanOrEqual(trigger.y + trigger.height + 7);
|
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);
|
||||||
|
});
|
||||||
@@ -2500,6 +2500,7 @@ export function ThreadComposer({
|
|||||||
scope={workspaceScope}
|
scope={workspaceScope}
|
||||||
disabled={interactionDisabled || workspaceScopeDisabled}
|
disabled={interactionDisabled || workspaceScopeDisabled}
|
||||||
onChange={onWorkspaceScopeChange}
|
onChange={onWorkspaceScopeChange}
|
||||||
|
hintBoundaryRef={formRef}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
const workspaceControl = showProjectPicker ? (
|
const workspaceControl = showProjectPicker ? (
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { FullAccessIcon, RestrictedAccessIcon, WorkspaceIcon } from "@/components/icons/product-icons";
|
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 { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
||||||
import { ArrowLeft, ArrowRight, Check, ChevronDown, ChevronRight, FolderSearch, History, Search, Star } from "lucide-react";
|
import { ArrowLeft, ArrowRight, Check, ChevronDown, ChevronRight, FolderSearch, History, Search, Star } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ToggleButton } from "@/components/ui/toggle-button";
|
import { ToggleButton } from "@/components/ui/toggle-button";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { floatingItemClassName, floatingItemFocusClassName } from "@/components/ui/floating-surface";
|
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 { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||||
import { Input, SearchInput } from "@/components/ui/input";
|
import { Input, SearchInput } from "@/components/ui/input";
|
||||||
import { Dialog, DialogContent, DialogTrigger, DialogTitle, DialogDescription } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogTrigger, DialogTitle, DialogDescription } from "@/components/ui/dialog";
|
||||||
@@ -684,14 +684,21 @@ export function WorkspaceAccessMenu({
|
|||||||
scope,
|
scope,
|
||||||
disabled,
|
disabled,
|
||||||
onChange,
|
onChange,
|
||||||
|
hintBoundaryRef,
|
||||||
}: {
|
}: {
|
||||||
scope: WorkspaceScopePayload;
|
scope: WorkspaceScopePayload;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onChange?: (scope: WorkspaceScopePayload) => void;
|
onChange?: (scope: WorkspaceScopePayload) => void;
|
||||||
|
hintBoundaryRef: RefObject<HTMLElement>;
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const coarsePointer = useMediaQuery("(pointer: coarse)");
|
const coarsePointer = useMediaQuery("(pointer: coarse)");
|
||||||
const [open, setOpen] = useState(false);
|
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 restoreTriggerFocus = useRef(true);
|
||||||
const descriptionId = useId();
|
const descriptionId = useId();
|
||||||
const isFull = scope.access_mode === "full";
|
const isFull = scope.access_mode === "full";
|
||||||
@@ -701,25 +708,53 @@ export function WorkspaceAccessMenu({
|
|||||||
const AccessIcon = isFull ? FullAccessIcon : RestrictedAccessIcon;
|
const AccessIcon = isFull ? FullAccessIcon : RestrictedAccessIcon;
|
||||||
|
|
||||||
useEffect(() => { if (disabled || !onChange) setOpen(false); }, [disabled, onChange]);
|
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 (
|
return (
|
||||||
<DropdownMenu open={open} onOpenChange={setOpen}>
|
<DropdownMenu open={open} onOpenChange={setOpen}>
|
||||||
<HoverHint enabled={!open && !coarsePointer} content={description} side="bottom" sideOffset={8}>
|
<TooltipProvider>
|
||||||
<DropdownMenuTrigger asChild disabled={disabled || !onChange}>
|
<Tooltip open={hintEnabled && hintOpen} onOpenChange={next => setHintOpen(hintEnabled && next)}>
|
||||||
<button type="button" aria-label={accessAriaLabel} aria-describedby={descriptionId}
|
<TooltipTrigger asChild>
|
||||||
onPointerDown={() => { restoreTriggerFocus.current = false; }}
|
<DropdownMenuTrigger asChild disabled={disabled || !onChange}>
|
||||||
onKeyDown={() => { restoreTriggerFocus.current = true; }}
|
<button ref={triggerRef} type="button" aria-label={accessAriaLabel} aria-describedby={descriptionId}
|
||||||
className={cn(
|
onPointerDown={() => { restoreTriggerFocus.current = false; }}
|
||||||
"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",
|
onKeyDown={() => { restoreTriggerFocus.current = true; }}
|
||||||
isFull ? "text-orange-600 hover:text-orange-700 dark:text-orange-300 dark:hover:text-orange-200" : "text-muted-foreground hover:text-foreground",
|
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",
|
||||||
<AccessIcon className="h-3.5 w-3.5 shrink-0" />
|
isFull ? "text-orange-600 hover:text-orange-700 dark:text-orange-300 dark:hover:text-orange-200" : "text-muted-foreground hover:text-foreground",
|
||||||
<span className="min-w-0 truncate">{label}</span>
|
)}>
|
||||||
<ChevronDown className="h-3 w-3 shrink-0" aria-hidden />
|
<AccessIcon className="h-3.5 w-3.5 shrink-0" />
|
||||||
<span id={descriptionId} className="sr-only">{description}</span>
|
<span className="min-w-0 truncate">{label}</span>
|
||||||
</button>
|
<ChevronDown className="h-3 w-3 shrink-0" aria-hidden />
|
||||||
</DropdownMenuTrigger>
|
<span id={descriptionId} className="sr-only">{description}</span>
|
||||||
</HoverHint>
|
</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")}
|
<DropdownMenuContent side="top" align="start" sideOffset={8} aria-label={t("thread.composer.workspace.accessAria")}
|
||||||
onPointerDownCapture={() => { restoreTriggerFocus.current = false; }}
|
onPointerDownCapture={() => { restoreTriggerFocus.current = false; }}
|
||||||
onKeyDownCapture={() => { restoreTriggerFocus.current = true; }}
|
onKeyDownCapture={() => { restoreTriggerFocus.current = true; }}
|
||||||
|
|||||||
@@ -119,12 +119,13 @@ function WorkspacePreview() {
|
|||||||
const { t: g } = useGalleryTranslation();
|
const { t: g } = useGalleryTranslation();
|
||||||
const [scope, setScope] = useState(projectScope);
|
const [scope, setScope] = useState(projectScope);
|
||||||
const [mode, setMode] = useState<"ready" | "disabled">("ready");
|
const [mode, setMode] = useState<"ready" | "disabled">("ready");
|
||||||
|
const hintBoundaryRef = useRef<HTMLDivElement>(null);
|
||||||
return <div className="space-y-4">
|
return <div className="space-y-4">
|
||||||
<StatePicker label={g("previews.workspace.state")} value={mode} options={["ready", "disabled"]} onChange={setMode} />
|
<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}
|
<WorkspaceProjectPicker scope={scope} defaultScope={projectScope} controls={workspaceCatalog.controls}
|
||||||
disabled={mode === "disabled"} onLoadProjects={loadExampleProjects} onChange={setScope} />
|
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>
|
</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>
|
<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>;
|
</div>;
|
||||||
|
|||||||
Reference in new issue
Block a user