mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
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.
This commit is contained in:
@@ -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",
|
||||
);
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<HTMLInputElement>(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<NamedScope>) => 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 (
|
||||
<div className={styles.toolsLayout}>
|
||||
<div className={styles.tableBox}>
|
||||
<div className={own.scopeLayout}>
|
||||
<div className={clsx(styles.tableBox, own.scopePane)}>
|
||||
<ListToolbar
|
||||
label="Scopes actions"
|
||||
index={index}
|
||||
count={scopes.length}
|
||||
onAdd={() => {
|
||||
focusNewScope.current = true;
|
||||
set([...scopes, { name: freshName(taken), pattern: "" }]);
|
||||
setSelected(scopes.length);
|
||||
}}
|
||||
@@ -105,34 +114,32 @@ export function ScopesEditor() {
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<div className={styles.toolList} role="listbox" aria-label={tx("Scopes")}>
|
||||
{scopes.length === 0 && (
|
||||
<div className={clsx(styles.toolRow, styles.empty)}>
|
||||
<List
|
||||
aria-label={tx("Scopes")}
|
||||
className={own.scopeList}
|
||||
items={scopes}
|
||||
activeIndex={index}
|
||||
onActiveChange={setSelected}
|
||||
getKey={(_, i) => String(i)}
|
||||
renderItem={({ name, pattern }) => (
|
||||
<span className={own.scopeName} title={pattern ? `${name}\n${pattern}` : name}>
|
||||
{name}
|
||||
</span>
|
||||
)}
|
||||
empty={
|
||||
<div className={own.scopeEmpty}>
|
||||
<T>No scopes. Click + to add one.</T>
|
||||
</div>
|
||||
)}
|
||||
{scopes.map((s, i) => (
|
||||
<div
|
||||
key={i}
|
||||
role="option"
|
||||
aria-selected={i === index}
|
||||
className={clsx(styles.toolRow, i === index && styles.toolRowSelected)}
|
||||
onMouseDown={() => setSelected(i)}
|
||||
>
|
||||
<span className={styles.toolName}>{s.name}</span>
|
||||
<span className={styles.toolGroup} title={s.pattern}>
|
||||
{s.pattern}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{current && (
|
||||
<Section title="Scope">
|
||||
<Row label="Name" htmlFor={nameId} className={styles.alignedRow}>
|
||||
<Row label="Name" htmlFor={nameId}>
|
||||
<Input
|
||||
id={nameId}
|
||||
className={styles.wide}
|
||||
ref={nameInput}
|
||||
className={own.scopeInput}
|
||||
value={current.name}
|
||||
invalid={nameClash || !current.name.trim()}
|
||||
onChange={(e) => update({ name: e.target.value })}
|
||||
@@ -141,7 +148,6 @@ export function ScopesEditor() {
|
||||
<Row
|
||||
label="Pattern"
|
||||
htmlFor={patternId}
|
||||
className={styles.alignedRow}
|
||||
hint={
|
||||
error ? (
|
||||
<span className={own.error} role="alert">
|
||||
@@ -155,7 +161,7 @@ export function ScopesEditor() {
|
||||
<Input
|
||||
id={patternId}
|
||||
mono
|
||||
className={styles.wide}
|
||||
className={own.scopeInput}
|
||||
value={current.pattern}
|
||||
invalid={!!error}
|
||||
placeholder={PATTERN_EXAMPLE}
|
||||
|
||||
Reference in New Issue
Block a user