feat(webui): add a compact composer workspace toolbar (#6256)

* feat(webui): add a compact composer workspace toolbar

* refactor(webui): simplify composer workspace access control

* feat(webui): add a draggable workspace access capsule

* refactor(webui): simplify composer permission controls

* fix(webui): align mobile workspace permissions and stabilize CI test
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-23 21:09:21 +08:00
1 parent 0254bf1217
commit cf0a0276a7
34 files changed
+528 -267

No files matched your search

+4 -1
View File
@@ -33,6 +33,7 @@ import { HistoryHydrationFixture } from "./history-hydration-fixture";
import { IdleCompactionFixture, installIdleCompactionApi } from "./idle-compaction-fixture";
import { FileEditPathFixture } from "./file-edit-path-fixture";
import { QueuedGuidanceFixture } from "./queued-guidance-fixture";
import { WorkspaceAlignmentFixture } from "./workspace-alignment-fixture";
const history: UIMessage[] = [
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
@@ -184,7 +185,9 @@ if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi()
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
await initializeI18n();
createRoot(document.getElementById("root")!).render(<TooltipProvider>
{parameters.get("case") === "queued-guidance"
{parameters.get("case") === "workspace-alignment"
? <WorkspaceAlignmentFixture parameters={parameters} />
: parameters.get("case") === "queued-guidance"
? <QueuedGuidanceFixture />
: parameters.get("case") === "file-edit-path"
? <FileEditPathFixture />
+5 -2
View File
@@ -1,4 +1,6 @@
import { useState } from "react";
import { ThreadShell } from "@/components/thread/ThreadShell";
import type { WorkspaceScopePayload } from "@/lib/types";
import { StartupSkeleton } from "@/components/StartupSkeleton";
import { settings } from "@/dev/gallery/settings";
import "@/components/startup-skeleton.css";
@@ -7,6 +9,7 @@ const noop = () => {};
export function NewChatSkeletonFixture() {
const params = new URLSearchParams(location.search);
const [workspaceScope, setWorkspaceScope] = useState<WorkspaceScopePayload>({ project_path: "/workspace", access_mode: "full" });
const sidebarExpanded = !params.has("collapsed");
const sidebarWidth = Number(params.get("sidebarWidth") ?? 272);
const dark = params.has("dark");
@@ -17,9 +20,9 @@ export function NewChatSkeletonFixture() {
<main className="thread-workspace relative flex min-w-0 flex-1 flex-col overflow-hidden">
<ThreadShell session={null} title="nanobot" onToggleSidebar={noop} theme={dark ? "dark" : "light"}
hideSidebarToggleForHostChrome onTemporaryChatEnabledChange={noop} settingsSnapshot={settings}
workspaceScope={{ project_path: "/workspace", access_mode: "full" }}
workspaceScope={workspaceScope}
workspaceDefaultScope={{ project_path: "/workspace", access_mode: "full" }}
workspaceControls={{ can_change_project: true, can_browse_directories: true }} onWorkspaceScopeChange={noop} />
workspaceControls={{ can_change_project: true, can_browse_directories: true }} onWorkspaceScopeChange={setWorkspaceScope} />
</main>
</>}
</div>;
+4 -3
View File
@@ -45,15 +45,16 @@ for (const c of cases) for (const locale of ["en", "zh-CN"]) {
input: await box(page.locator(".thread-composer-input")),
footer: await box(page.locator(".thread-composer-footer")),
greeting: await box(page.getByTestId("hero-greeting")),
workspaceRow: await page.locator(".thread-composer-workspace-row").isVisible()
? await box(page.locator(".thread-composer-workspace-row")) : null,
workspaceRow: await box(page.locator(".thread-composer-meta")),
workspaceControl: await box(page.locator(".thread-composer-workspace")),
};
await page.goto(`${url}&loading`);
sameBox(await box(page.locator(".startup-chat-header")), loaded.header);
sameBox(await box(page.locator(".startup-composer-surface")), loaded.composer);
sameBox(await box(page.locator(".startup-composer-input")), loaded.input);
sameBox(await box(page.locator(".startup-composer-footer")), loaded.footer);
if (loaded.workspaceRow) sameBox(await box(page.locator(".startup-workspace-row")), loaded.workspaceRow);
sameBox(await box(page.locator(".startup-workspace-row")), loaded.workspaceRow);
expect((await box(page.locator(".startup-workspace-row .startup-workspace"))).x).toBeCloseTo(loaded.workspaceControl.x, 1);
const controls = page.locator(".startup-header-menu:visible, .startup-header-actions > div");
await expect(controls).toHaveCount(loaded.controls.length);
for (let i = 0; i < loaded.controls.length; i++) sameBox(await box(controls.nth(i)), loaded.controls[i]);
+1 -1
View File
@@ -31,7 +31,7 @@ export function SkeletonFixture({ surface, loading }: { surface: string; loading
configured: true, ready: true, install_supported: true, status: "enabled", requires_restart: false,
};
return <main className="settings-grid mx-auto w-full max-w-4xl p-4" data-testid="skeleton-fixture">
{surface === "workspace" ? <WorkspaceProjectPicker isHero scope={{ project_path: "/srv/workspace", access_mode: "restricted" }}
{surface === "workspace" ? <WorkspaceProjectPicker scope={{ project_path: "/srv/workspace", access_mode: "restricted" }}
defaultScope={{ project_path: "/srv/workspace", access_mode: "restricted" }}
controls={{ can_change_project: true, can_browse_directories: true }}
onBrowseDirectories={(path, query, showHidden, allowPartial) => fetchWorkspaceDirectories("fixture", path, query, showHidden, allowPartial)}
@@ -0,0 +1,73 @@
import { expect, test, type Locator, type Page } from "@playwright/test";
test.use({ viewport: { width: 1280, height: 900 }, reducedMotion: "reduce" });
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
await page.goto("/browser/fixture.html?case=new-chat-skeleton");
await expect(page.locator(".thread-composer-access")).toBeVisible();
});
async function openWithKeyboard(page: Page, trigger: Locator) {
await page.getByRole("textbox", { name: "Message input" }).click();
await page.keyboard.press("Tab");
await expect(page.getByRole("button", { name: "Attach files" })).toBeFocused();
await page.keyboard.press("Tab");
await expect(trigger).toBeFocused();
await page.keyboard.press("Enter");
await expect(page.getByRole("menuitemradio", { name: "Default Permission" })).toBeFocused();
}
async function expectPointerDismissal(page: Page, trigger: Locator) {
await expect(page.getByRole("menu")).toHaveCount(0);
// Observe the first closed-menu paint, after FocusScope's unmount restoration.
await page.evaluate(() => new Promise(requestAnimationFrame));
await expect(trigger).not.toBeFocused();
expect(await trigger.evaluate(element => element.matches(":focus-visible"))).toBe(false);
await expect(page.getByRole("tooltip")).toHaveCount(0);
}
test("pointer selection does not refocus the trigger or reopen its tooltip", async ({ page }) => {
const trigger = page.locator(".thread-composer-access");
await trigger.click();
await page.getByRole("menuitemradio", { name: "Default Permission" }).click();
await expect(trigger).toHaveAccessibleName("Workspace access mode: Default Permission");
await expectPointerDismissal(page, trigger);
});
test("keyboard selection restores visible focus to the permission trigger", async ({ page }) => {
const trigger = page.locator(".thread-composer-access");
await openWithKeyboard(page, trigger);
await page.keyboard.press("Enter");
await expect(page.getByRole("menu")).toHaveCount(0);
await expect(trigger).toHaveAccessibleName("Workspace access mode: Default Permission");
await expect(trigger).toBeFocused();
expect(await trigger.evaluate(element => element.matches(":focus-visible"))).toBe(true);
});
test("Escape restores keyboard focus even after pointer entry", async ({ page }) => {
const trigger = page.locator(".thread-composer-access");
await trigger.click();
await expect(page.getByRole("menu")).toBeVisible();
await page.keyboard.press("Escape");
await expect(page.getByRole("menu")).toHaveCount(0);
await expect(trigger).toHaveAccessibleName("Workspace access mode: Full Access");
await expect(trigger).toBeFocused();
expect(await trigger.evaluate(element => element.matches(":focus-visible"))).toBe(true);
});
test("pointer selection after keyboard entry does not restore keyboard focus", async ({ page }) => {
const trigger = page.locator(".thread-composer-access");
await openWithKeyboard(page, trigger);
await page.getByRole("menuitemradio", { name: "Default Permission" }).click();
await expectPointerDismissal(page, trigger);
});
test("pointer dismissal outside a keyboard-opened menu does not refocus the trigger", async ({ page }) => {
const trigger = page.locator(".thread-composer-access");
await openWithKeyboard(page, trigger);
const greeting = (await page.getByTestId("hero-greeting").boundingBox())!;
await page.mouse.click(greeting.x + 8, greeting.y + 8);
await expectPointerDismissal(page, trigger);
});
@@ -0,0 +1,23 @@
import { useState } from "react";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
import type { WorkspaceScopePayload, WorkspacesPayload } from "@/lib/types";
const initialScope: WorkspaceScopePayload = { project_path: "/workspace", access_mode: "full" };
const catalog: WorkspacesPayload = {
schema_version: 1, default_access_mode: "full", default_scope: initialScope,
recent_projects: [], controls: { can_change_project: true },
};
export function WorkspaceAlignmentFixture({ parameters }: { parameters: URLSearchParams }) {
const [scope, setScope] = useState(initialScope);
return <main className="mx-auto w-full max-w-5xl px-4 pt-24" style={{ maxWidth: parameters.has("containerWidth") ? Number(parameters.get("containerWidth")) : undefined }}>
<ThreadComposer variant={parameters.get("composerVariant") === "thread" ? "thread" : "hero"}
onSend={() => {}} workspaceScope={scope} workspaceDefaultScope={initialScope}
contextUsage={parameters.has("usage") ? { contextTokens: 500, contextWindowTokens: 1000 } : null}
workspaceControls={catalog.controls} onWorkspaceScopeChange={setScope}
onLoadWorkspaceProjects={async () => catalog}
onResolveWorkspaceProject={async path => ({ path, name: "workspace" })}
onFavoriteWorkspaceProject={async () => []}
onBrowseWorkspaceDirectories={async path => ({ path, parent: null, entries: [], truncated: false, host: "fixture", platform: "Linux" })} />
</main>;
}
+101
View File
@@ -0,0 +1,101 @@
import { expect, test } from "@playwright/test";
const cases = [
{ name: "desktop", width: 1280, touch: false, extra: "" },
{ name: "tablet", width: 1280, touch: true, extra: "" },
{ name: "small desktop", width: 600, touch: false, extra: "" },
{ name: "phone", width: 390, touch: true, extra: "" },
{ name: "narrow desktop pane", width: 1024, touch: false, extra: "&containerWidth=480" },
];
for (const variant of ["hero", "thread"]) for (const c of cases) {
test.describe(`${variant} ${c.name}`, () => {
test.use({ viewport: { width: c.width, height: 900 }, hasTouch: c.touch, reducedMotion: "reduce" });
test("aligns the directory glyph with the attachment glyph", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
await page.goto(`/browser/fixture.html?case=workspace-alignment&composerVariant=${variant}${c.extra}`);
const attachment = page.getByRole("button", { name: "Attach files" }).locator("svg");
const workspace = page.getByRole("button", { name: "Switch directory" }).locator('[data-product-icon="workspace"]');
await expect(workspace).toBeVisible();
await page.evaluate(() => document.fonts.ready);
const attachmentBox = (await attachment.boundingBox())!;
const workspaceBox = (await workspace.boundingBox())!;
expect(workspaceBox.x).toBeCloseTo(attachmentBox.x, 1);
expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false);
});
});
}
for (const variant of ["hero", "thread"]) for (const width of [280, 320, 390, 600, 1024, 1280]) {
test.describe(`${variant} permission at ${width}px`, () => {
test.use({ viewport: { width, height: 900 }, hasTouch: width < 640, reducedMotion: "reduce" });
test("places mobile permission opposite the directory and preserves desktop placement", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
await page.goto(`/browser/fixture.html?case=workspace-alignment&composerVariant=${variant}${width === 1024 ? "&containerWidth=480" : ""}`);
const workspace = page.getByRole("button", { name: "Switch directory" });
const access = page.getByRole("button", { name: "Workspace access mode: Full Access" });
await expect(access).toBeVisible();
const surface = (await page.locator(".thread-composer-surface").boundingBox())!;
const accessBox = (await access.boundingBox())!;
if (width < 640) {
const workspaceBox = (await workspace.boundingBox())!;
expect(accessBox.y).toBeGreaterThanOrEqual(surface.y + surface.height);
expect(Math.abs(accessBox.y + accessBox.height / 2 - workspaceBox.y - workspaceBox.height / 2)).toBeLessThan(1);
expect(accessBox.x).toBeGreaterThan(workspaceBox.x + workspaceBox.width);
expect(surface.x + surface.width - accessBox.x - accessBox.width).toBeLessThan(16);
expect(await access.evaluate(element => !!element.closest(".thread-composer-meta"))).toBe(true);
} else {
expect(accessBox.y + accessBox.height).toBeLessThanOrEqual(surface.y + surface.height);
expect(await access.evaluate(element => !!element.closest(".thread-composer-footer-primary"))).toBe(true);
}
expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false);
await access.click();
await page.getByRole("menuitemradio", { name: "Default Permission" }).click();
await expect(page.getByRole("button", { name: "Workspace access mode: Default Permission" })).toBeVisible();
});
});
}
for (const variant of ["hero", "thread"]) {
test.describe(`${variant} mobile permission with usage`, () => {
test.use({ viewport: { width: 320, height: 900 }, hasTouch: true, reducedMotion: "reduce" });
test("keeps access on the lower right when context usage appears", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
await page.goto(`/browser/fixture.html?case=workspace-alignment&composerVariant=${variant}&usage=1`);
const workspace = (await page.getByRole("button", { name: "Switch directory" }).boundingBox())!;
const access = (await page.getByRole("button", { name: "Workspace access mode: Full Access" }).boundingBox())!;
const usage = (await page.getByTestId("composer-context-usage").boundingBox())!;
expect(Math.abs(access.y - workspace.y)).toBeLessThan(1);
expect(usage.y + usage.height).toBeLessThanOrEqual(access.y);
expect(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)).toBe(false);
await page.getByTestId("composer-context-usage").focus();
await page.keyboard.press("Tab");
await expect(page.getByRole("button", { name: "Switch directory" })).toBeFocused();
await page.keyboard.press("Tab");
await expect(page.getByRole("button", { name: "Workspace access mode: Full Access" })).toBeFocused();
});
});
}
test.describe("permission across phone and desktop widths", () => {
test.use({ viewport: { width: 390, height: 900 }, hasTouch: true, reducedMotion: "reduce" });
test("keeps the draft and one usable permission trigger when the viewport changes", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
await page.route("**/api/commands", route => route.fulfill({ json: { commands: [] } }));
await page.goto("/browser/fixture.html?case=workspace-alignment&composerVariant=hero");
const input = page.getByRole("textbox", { name: "Message input" });
await input.fill("keep this draft");
for (const width of [1280, 320]) {
await page.setViewportSize({ width, height: 900 });
await expect(input).toHaveValue("keep this draft");
const access = page.getByRole("button", { name: "Workspace access mode: Full Access" });
await expect(access).toHaveCount(1);
await expect.poll(() => access.evaluate((element, mobile) => !!element.closest(mobile ? ".thread-composer-meta" : ".thread-composer-footer-primary"), width < 640)).toBe(true);
}
await page.getByRole("button", { name: "Workspace access mode: Full Access" }).click();
await expect(page.getByRole("menuitemradio", { name: "Default Permission" })).toBeVisible();
});
});