From f13d2b46cd49f989a8cb4015d2b97b850f4c79c9 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 16:07:25 +0800 Subject: [PATCH] Align the Scopes settings list and editor (#4731) Scopes settings place the scope list beside the Name and Pattern fields in wide windows and stack them in narrow ones. Scope names use the standard UI text size with the full name and pattern on hover, keyboard selection stays visible, and adding a scope selects its default name for editing. --- e2e/scopeSettingsLayout.spec.ts | 63 +++++++++++++++++++ src/features/settings/pages/Scopes.module.css | 35 +++++++++++ src/features/settings/pages/ScopesBody.tsx | 60 ++++++++++-------- 3 files changed, 131 insertions(+), 27 deletions(-) create mode 100644 e2e/scopeSettingsLayout.spec.ts diff --git a/e2e/scopeSettingsLayout.spec.ts b/e2e/scopeSettingsLayout.spec.ts new file mode 100644 index 000000000..af8328ea2 --- /dev/null +++ b/e2e/scopeSettingsLayout.spec.ts @@ -0,0 +1,63 @@ +import { expect, test } from "./fixtures"; + +test("keeps scope navigation and editing usable as Settings narrows", async ({ workbench: page }) => { + await page.setViewportSize({ width: 1180, height: 770 }); + await page.keyboard.press("Meta+,"); + const dialog = page.getByRole("dialog", { name: "Settings", exact: true }); + await expect(dialog).toBeVisible(); + const longName = "Shared API and generated deployment artifacts for regional settlement services"; + const longPattern = "file:services/settlement//*.ts && !file:*.test.ts"; + await page.evaluate( + async ({ longName, longPattern }) => { + const path = "/src/features/settings/model/staging.ts"; + const { selectPage, stage } = await import(/* @vite-ignore */ path); + stage("scopes", "project", "scopes", [ + { name: longName, pattern: longPattern }, + ...Array.from({ length: 23 }, (_, i) => ({ + name: `Settlement area ${i + 1}`, + pattern: `file:services/area-${i + 1}//*.ts`, + })), + ]); + selectPage("scopes"); + }, + { longName, longPattern }, + ); + const scopes = dialog.getByRole("listbox", { name: "Scopes", exact: true }); + const toolbar = dialog.getByRole("toolbar", { name: "Scopes actions" }); + const name = dialog.getByRole("textbox", { name: /^Name:?$/ }); + const pattern = dialog.getByRole("textbox", { name: /^Pattern:?$/ }); + await expect(name).toHaveValue(longName); + await expect(pattern).toHaveValue(longPattern); + expect((await name.boundingBox())!.x).toBeGreaterThan( + (await scopes.boundingBox())!.x + (await scopes.boundingBox())!.width, + ); + const first = scopes.getByRole("option", { name: longName, exact: true }); + await expect(first.getByTitle(new RegExp(longName))).toBeVisible(); + expect(await scopes.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); + + await scopes.focus(); + await page.keyboard.press("End"); + const last = scopes.getByRole("option", { name: "Settlement area 23", exact: true }); + await expect(last).toHaveAttribute("aria-selected", "true"); + await expect(last).toBeInViewport({ ratio: 1 }); + await expect(pattern).toHaveValue("file:services/area-23//*.ts"); + expect(await scopes.evaluate((el) => el.scrollTop)).toBeGreaterThan(100); + await expect(toolbar).toBeInViewport({ ratio: 1 }); + + await page.setViewportSize({ width: 650, height: 730 }); + const listBounds = (await scopes.boundingBox())!; + expect((await name.boundingBox())!.y).toBeGreaterThan(listBounds.y + listBounds.height); + await toolbar.getByRole("button", { name: "Add", exact: true }).click(); + await expect(name).toBeFocused(); + await expect(name).toHaveValue("Scope"); + expect(await name.evaluate((el: HTMLInputElement) => [el.selectionStart, el.selectionEnd])).toEqual([0, 5]); + const added = scopes.getByRole("option", { name: "Scope", exact: true }); + await expect(added).toHaveAttribute("aria-selected", "true"); + await expect(added).toBeInViewport({ ratio: 1 }); + await page.keyboard.type("Settlement exports"); + await pattern.fill("file:exports//*.csv"); + await expect(scopes.getByRole("option", { name: "Settlement exports", exact: true })).toHaveAttribute( + "aria-selected", + "true", + ); +}); diff --git a/src/features/settings/pages/Scopes.module.css b/src/features/settings/pages/Scopes.module.css index 8e474c111..576dbe392 100644 --- a/src/features/settings/pages/Scopes.module.css +++ b/src/features/settings/pages/Scopes.module.css @@ -26,3 +26,38 @@ border-radius: var(--radius-sm, 4px); background: none; } +.scopeLayout { + display: grid; + grid-template-columns: minmax(160px, 31%) minmax(0, 1fr); + gap: var(--space-4); + align-items: start; + font-size: var(--fs-ui); +} +.scopePane { + min-width: 0; + height: clamp(240px, 42vh, 360px); +} +.scopeList { + flex: 1; + min-height: 0; +} +.scopeName { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.scopeEmpty { + padding: var(--space-3); + color: var(--fg-muted); +} +.scopeInput { + width: 100%; +} +@container settings-content (max-width: 580px) { + .scopeLayout { + grid-template-columns: minmax(0, 1fr); + } + .scopePane { + height: clamp(148px, 28vh, 200px); + } +} diff --git a/src/features/settings/pages/ScopesBody.tsx b/src/features/settings/pages/ScopesBody.tsx index 9fe0f8556..10501acac 100644 --- a/src/features/settings/pages/ScopesBody.tsx +++ b/src/features/settings/pages/ScopesBody.tsx @@ -2,12 +2,12 @@ * Appearance & Behavior › Scopes (named file sets) and › File Colors (a background * colour per scope in the project view and on editor tabs). Both are project settings. */ -import { useId, useState } from "react"; +import { useId, useLayoutEffect, useRef, useState } from "react"; import clsx from "clsx"; import { FILE_COLOR_NAMES, fileColorCss, validateFileColors, type FileColorEntry } from "@/platform/fileColors"; import { tx } from "@/platform/i18n"; import { BUILTIN_SCOPES, scopeError, validateScopes, type NamedScope } from "@/platform/scopes"; -import { IconButton, Input, T, type SelectOption } from "@/ui"; +import { IconButton, Input, List, T, type SelectOption } from "@/ui"; import { ColorSwatches, Row, Section, Select } from "../components/Form"; import { useSetting } from "../components/context"; import styles from "./Workflow.module.css"; @@ -79,6 +79,14 @@ export function ScopesEditor() { const current = scopes[index]; const nameId = useId(); const patternId = useId(); + const nameInput = useRef(null); + const focusNewScope = useRef(false); + useLayoutEffect(() => { + if (!focusNewScope.current) return; + focusNewScope.current = false; + nameInput.current?.focus(); + nameInput.current?.select(); + }, [scopes.length]); const set = (next: NamedScope[]) => setRaw(next); const update = (patch: Partial) => set(scopes.map((s, i) => (i === index ? { ...s, ...patch } : s))); const error = current?.pattern.trim() ? scopeError(current.pattern) : null; @@ -86,13 +94,14 @@ export function ScopesEditor() { const nameClash = !!current && taken.filter((n) => n === current.name).length > 1; return ( -
-
+
+
{ + focusNewScope.current = true; set([...scopes, { name: freshName(taken), pattern: "" }]); setSelected(scopes.length); }} @@ -105,34 +114,32 @@ export function ScopesEditor() { } }} /> -
- {scopes.length === 0 && ( -
+ String(i)} + renderItem={({ name, pattern }) => ( + + {name} + + )} + empty={ +
No scopes. Click + to add one.
- )} - {scopes.map((s, i) => ( -
setSelected(i)} - > - {s.name} - - {s.pattern} - -
- ))} -
+ } + />
{current && (
- + update({ name: e.target.value })} @@ -141,7 +148,6 @@ export function ScopesEditor() { @@ -155,7 +161,7 @@ export function ScopesEditor() {