Make Inspections panes fit narrow settings windows (#4629)

Inspections settings panes resize and fit narrow settings windows. Verified with e2e inspectionsLayout/settingsFormLayout, full vitest and typecheck.
This commit is contained in:
l0ng-ai
2026-11-20 08:26:21 +08:00
committed by GitHub
parent 42fd0fa8e0
commit bbedf7e1f6
5 changed files with 200 additions and 74 deletions
+52
View File
@@ -0,0 +1,52 @@
import { expect, test } from "./fixtures";
test("Inspections keeps the selected rule and its controls usable as the pane changes width", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 620, height: 720 });
await page.keyboard.press("Meta+,");
const dialog = page.getByRole("dialog", { name: "Settings", exact: true });
await expect(dialog).toBeVisible();
await page.evaluate(async () => {
const path = "/src/features/settings/model/staging.ts";
(await import(/* @vite-ignore */ path)).selectPage("editor.inspections");
});
const search = dialog.getByRole("textbox", { name: "Search inspections" });
await search.fill("typo");
const tree = dialog.getByRole("tree", { name: "Inspections" });
const typo = tree.getByRole("treeitem", { name: /Typo/ });
await typo.click();
const body = dialog.locator("[class*='pageBody']");
await expect.poll(() => body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
const resize = dialog.getByRole("separator", { name: "Resize inspection panes" });
const details = dialog.getByRole("region", { name: "Inspection details" });
await expect(resize).toHaveAttribute("aria-orientation", "horizontal");
await expect(details.getByRole("heading", { name: "Typo" })).toBeVisible();
const narrowTree = await tree.boundingBox();
const narrowDetails = await details.boundingBox();
expect(narrowDetails!.y).toBeGreaterThan(narrowTree!.y + narrowTree!.height);
await expect(details.getByRole("separator", { name: "Resize inspection description" })).toHaveAttribute(
"aria-orientation",
"horizontal",
);
const severity = details.getByRole("button", { name: "Severity" });
const severityBox = await severity.boundingBox();
expect(severityBox!.y + severityBox!.height).toBeLessThan(narrowDetails!.y + narrowDetails!.height);
await severity.click();
await page.getByRole("option", { name: "Warning", exact: true }).click();
const code = details.getByRole("checkbox", { name: "Process code" });
await code.uncheck();
await expect(severity).toHaveText("Warning");
await page.setViewportSize({ width: 1040, height: 740 });
await expect(resize).toHaveAttribute("aria-orientation", "vertical");
const width = (await tree.boundingBox())!.width;
await resize.press("ArrowRight");
await expect.poll(async () => (await tree.boundingBox())!.width).toBeGreaterThan(width + 5);
await expect(typo).toHaveAttribute("aria-selected", "true");
await expect(severity).toHaveText("Warning");
await expect(code).not.toBeChecked();
});
@@ -2,21 +2,30 @@
display: flex;
flex-direction: column;
height: 100%;
min-width: 0;
min-height: 420px;
}
.profileRow {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
gap: var(--space-1) var(--space-3);
min-height: 30px;
margin-bottom: 8px;
margin-bottom: var(--space-2);
}
.profileSelect {
min-width: 220px;
.profileControls {
display: flex;
align-items: center;
gap: var(--space-2);
max-width: 100%;
min-width: 0;
}
.profileRow > span {
.profileControls > span {
flex: none;
white-space: nowrap;
}
.profileControls > .profileSelect {
width: 220px;
min-width: 0;
}
.toolbar {
display: flex;
@@ -26,24 +35,19 @@
}
.search {
flex: 1;
min-width: 0;
max-width: 320px;
margin-right: 4px;
margin-right: var(--space-1);
}
.split {
flex: 1;
min-width: 520px;
min-height: 0;
display: flex;
gap: var(--space-3);
min-width: 0;
}
.treeWrap {
flex: 3;
min-width: 0;
display: flex;
flex-direction: column;
border-radius: var(--radius-small);
box-shadow: inset 0 0 0 1px var(--border);
padding: 2px 0;
padding: var(--space-0-5) 0;
}
.empty {
padding: 8px 12px;
@@ -80,13 +84,20 @@
flex: none;
}
.details {
flex: 2;
flex: 1;
min-width: 0;
min-height: 0;
display: flex;
flex-direction: column;
gap: 10px;
padding: 2px 4px;
overflow: auto;
gap: var(--space-2);
padding: var(--space-3);
}
.detailTitle {
margin: 0;
color: var(--fg-strong);
font-size: var(--fs-ui);
font-weight: 600;
overflow-wrap: anywhere;
}
.description {
margin: 0;
@@ -95,19 +106,34 @@
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.severityRow {
.descriptionPane,
.optionsPane {
min-height: 0;
overflow: auto;
}
.descriptionPane {
padding-bottom: var(--space-2);
}
.optionsPane {
display: flex;
flex-direction: column;
gap: var(--space-2);
padding-top: var(--space-2);
}
.severityRow {
flex: none;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--space-2);
padding-top: 10px;
border-top: 1px solid var(--border);
}
.options {
flex: none;
display: flex;
flex-direction: column;
gap: var(--space-1-5);
margin: 0;
padding: 10px 0 0;
padding: var(--space-2) 0 0;
border: none;
border-top: 1px solid var(--border);
min-width: 0;
@@ -115,11 +141,12 @@
.options legend {
float: left;
width: 100%;
padding: 0 0 4px;
padding: 0 0 var(--space-1);
color: var(--fg-muted);
}
.levelSelect {
min-width: 160px;
width: 160px;
max-width: 100%;
}
.profileLevel {
color: var(--fg-subtle);
@@ -5,7 +5,7 @@
* chosen one is in effect for the project (editor highlighting, Problems,
* Inspect Code).
*/
import { useEffect, useId, useMemo, useRef, useState, type MouseEvent } from "react";
import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from "react";
import clsx from "clsx";
import {
BUILTIN_INSPECTIONS,
@@ -34,6 +34,9 @@ import {
Input,
SearchField,
Select,
SplitGroup,
SplitHandle,
SplitPanel,
T,
Tree,
showContextMenu,
@@ -92,6 +95,19 @@ function expandableKeys(nodes: readonly InspectionNode[], out = new Set<string>(
}
export function InspectionsPage() {
const pageRef = useRef<HTMLDivElement>(null);
const [stacked, setStacked] = useState(false);
useLayoutEffect(() => {
const page = pageRef.current;
if (!page) return;
const measure = () => setStacked(page.clientWidth < 560);
measure();
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(measure);
observer.observe(page);
return () => observer.disconnect();
}, []);
const hasProject = useProject((s) => !!s.project);
const newProjects = useSettingsDialog((s) => s.newProjects);
const projectAvailable = hasProject && !newProjects;
@@ -223,20 +239,22 @@ export function InspectionsPage() {
};
return (
<div className={styles.page}>
<div ref={pageRef} className={styles.page}>
<div className={styles.profileRow}>
<span>
<T>Profile:</T>
</span>
<Select
className={styles.profileSelect}
aria-label="Inspection profile"
value={profileId}
options={profileOptions}
onChange={(v) => setChosen(v)}
disabled={profileOptions.length < 2}
/>
<IconButton icon="settings" title="Profile Actions" onClick={gearMenu} />
<div className={styles.profileControls}>
<span>
<T>Profile:</T>
</span>
<Select
className={styles.profileSelect}
aria-label="Inspection profile"
value={profileId}
options={profileOptions}
onChange={(v) => setChosen(v)}
disabled={profileOptions.length < 2}
/>
<IconButton icon="settings" title="Profile Actions" onClick={gearMenu} />
</div>
<span className={styles.profileLevel}>
<T>{location.level === "project" ? "Stored in Project" : "Stored in IDE"}</T>
</span>
@@ -265,8 +283,16 @@ export function InspectionsPage() {
/>
</div>
<div className={styles.split}>
<div
<SplitGroup
id="inspection-panes"
className={styles.split}
orientation={stacked ? "vertical" : "horizontal"}
storageKey="openidea.settings.inspections.layout"
>
<SplitPanel
id="inspection-tree"
defaultSize="50%"
minSize="35%"
className={styles.treeWrap}
onKeyDown={(e) => {
// Space toggles the selected inspection, as in IDEA.
@@ -309,9 +335,12 @@ export function InspectionsPage() {
</div>
}
/>
</div>
<Details node={selected} overrides={overrides} onChange={setOverrides} />
</div>
</SplitPanel>
<SplitHandle aria-label={tx("Resize inspection panes")} />
<SplitPanel id="inspection-details" defaultSize="50%" minSize="35%">
<Details node={selected} overrides={overrides} onChange={setOverrides} />
</SplitPanel>
</SplitGroup>
{nameDialog && (
<ProfileNameDialog
@@ -435,38 +464,50 @@ function Details({
overrides: ProfileOverrides;
onChange: (o: ProfileOverrides) => void;
}) {
if (!node) {
return (
<div className={styles.details}>
<p className={styles.description}>
<T>Select an inspection to see its description and change its severity.</T>
</p>
</div>
);
}
const id = node.id;
const id = node?.id;
const description = (
<p className={styles.description}>
<T>{node?.description ?? "Select an inspection to see its description and change its severity."}</T>
</p>
);
return (
<div className={styles.details}>
<p className={styles.description}>
<T>{node.description}</T>
</p>
{id && (
<div className={styles.severityRow}>
<span>
<T>Severity:</T>
</span>
<Select
className={styles.levelSelect}
aria-label="Severity"
value={overrides[id]?.severity ?? AS_REPORTED}
options={LEVEL_OPTIONS}
disabled={!isEnabled(overrides, id)}
onChange={(v) => onChange(setLevel(overrides, id, v === AS_REPORTED ? undefined : (v as InspectionLevel)))}
/>
</div>
<section className={styles.details} aria-label={tx("Inspection details")}>
{node && (
<h3 className={styles.detailTitle}>
<T>{node.name}</T>
</h3>
)}
{id && <InspectionOptions id={id} overrides={overrides} onChange={onChange} />}
</div>
{id ? (
<SplitGroup id="inspection-rule" className={styles.split} orientation="vertical">
<SplitPanel id="inspection-description" defaultSize="45%" minSize="25%">
<div className={styles.descriptionPane}>{description}</div>
</SplitPanel>
<SplitHandle aria-label={tx("Resize inspection description")} />
<SplitPanel id="inspection-options" defaultSize="55%" minSize="25%">
<div className={styles.optionsPane}>
<div className={styles.severityRow}>
<span>
<T>Severity:</T>
</span>
<Select
className={styles.levelSelect}
aria-label="Severity"
value={overrides[id]?.severity ?? AS_REPORTED}
options={LEVEL_OPTIONS}
disabled={!isEnabled(overrides, id)}
onChange={(v) =>
onChange(setLevel(overrides, id, v === AS_REPORTED ? undefined : (v as InspectionLevel)))
}
/>
</div>
<InspectionOptions id={id} overrides={overrides} onChange={onChange} />
</div>
</SplitPanel>
</SplitGroup>
) : (
<div className={styles.descriptionPane}>{description}</div>
)}
</section>
);
}
+3
View File
@@ -1,4 +1,7 @@
{
"Inspection details": "Inspection details",
"Resize inspection panes": "Resize inspection panes",
"Resize inspection description": "Resize inspection description",
"Table actions": "Table actions",
"Table pages": "Table pages",
"Problems actions": "Problems actions",
+3
View File
@@ -1,4 +1,7 @@
{
"Inspection details": "检查详情",
"Resize inspection panes": "调整检查窗格大小",
"Resize inspection description": "调整检查说明窗格大小",
"Table actions": "表数据操作",
"Table pages": "表数据分页",
"Problems actions": "问题操作",