fix(build-tools): keep toolbar actions reachable in narrow panes (#4558)

The Maven and Gradle toolbars used one fixed row, which clipped actions in narrow panes. Narrow panes keep reload or cancel, run and execute visible and group the rest in More Actions; widening the pane restores the full toolbar, keeping the offline and skip-tests toggle states.
This commit is contained in:
l0ng-ai
2026-11-20 01:06:13 +08:00
committed by GitHub
parent f9455549a7
commit d5f29ea256
3 changed files with 193 additions and 31 deletions
+99
View File
@@ -0,0 +1,99 @@
import type { Page } from "@playwright/test";
import type { BuildModel, BuildTool } from "../src/platform/ipc";
import { expect, stubDesktop, test } from "./fixtures";
const model: BuildModel = {
maven: {
projects: [
{
pom: "pom.xml",
dir: "",
groupId: "com.example",
artifactId: "orders",
version: "1.0.0",
packaging: "jar",
displayName: "Orders service",
parent: null,
modules: [],
aggregated: false,
plugins: [],
dependencies: [],
profiles: [],
javaVersion: 21,
command: "mvn",
options: [],
env: {},
},
],
profiles: [],
syncedAt: 1,
stale: false,
syncError: null,
},
gradle: [
{
dir: "",
command: "gradle",
env: {},
javaVersion: 21,
syncedAt: 1,
stale: false,
syncError: null,
projects: [{ path: ":", name: "orders", dir: "", buildFile: "build.gradle", tasks: [] }],
},
],
};
async function showTool(page: Page, tool: BuildTool) {
await stubDesktop(page);
await page.evaluate(
async ({ tool, model }) => {
window.__ipc.handlers.build_model = () => model;
window.__ipc.handlers.run_configs = () => [];
const buildStore = "/src/features/build-tools/store.ts";
await (await import(/* @vite-ignore */ buildStore)).loadModel();
const layout = "/src/workbench/toolwindows/store.ts";
const { setToolWindowSize, showToolWindow } = await import(/* @vite-ignore */ layout);
showToolWindow(tool, true);
setToolWindowSize("right", 190);
},
{ tool, model },
);
}
async function setWidth(page: Page, width: number) {
await page.evaluate(async (px) => {
const layout = "/src/workbench/toolwindows/store.ts";
(await import(/* @vite-ignore */ layout)).setToolWindowSize("right", px);
}, width);
}
for (const tool of ["maven", "gradle"] as const) {
const name = tool === "maven" ? "Maven" : "Gradle";
test(`${name} keeps its toolbar actions reachable as the pane resizes`, async ({ workbench: page }) => {
await showTool(page, tool);
const toolbar = page.getByRole("toolbar", { name: `${name} actions` });
const more = toolbar.getByRole("button", { name: "More Actions", exact: true });
const menu = page.getByRole("menu", { name: "More Actions", exact: true });
const skipTests = "Toggle 'Skip Tests' Mode";
await expect(toolbar.getByRole("button", { name: `Reload All ${name} Projects` })).toBeVisible();
await expect(toolbar.getByRole("button", { name: new RegExp(`Execute ${name}`) })).toBeVisible();
await expect(page.getByRole("tree", { name: `${name} projects` })).toBeVisible();
expect(await toolbar.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await more.click();
await expect(menu.getByRole("menuitem", { name: "Analyze Dependencies…" })).toBeVisible();
await expect(menu.getByRole("menuitem", { name: "Expand All" })).toBeVisible();
await menu.getByRole("menuitemcheckbox", { name: skipTests, checked: false }).click();
await expect(menu).toBeHidden();
await more.click();
await expect(menu.getByRole("menuitemcheckbox", { name: skipTests, checked: true })).toBeVisible();
await setWidth(page, 360);
await expect(menu).toBeHidden();
await expect(more).toBeHidden();
await expect(toolbar.getByRole("button", { name: skipTests, pressed: true })).toBeVisible();
await expect(toolbar.getByRole("button", { name: "Collapse All" })).toBeVisible();
await setWidth(page, 190);
await expect(more).toBeVisible();
await expect(menu).toBeHidden();
});
}
+91 -31
View File
@@ -1,6 +1,6 @@
/** The Maven and Gradle tool windows: toolbar, status banner and the project tree. */
import { writeClipboardText } from "@/platform/clipboard";
import { useCallback, useEffect, useMemo, useState, type MouseEvent } from "react";
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from "react";
import clsx from "clsx";
import type { BuildTool, GradleModel, MavenModel, RunConfig } from "@/platform/ipc";
import { downloadJdkActions } from "@/platform/jdk";
@@ -12,6 +12,7 @@ import {
EmptyState,
Icon,
IconButton,
Menu,
Spinner,
Tree,
showContextMenu,
@@ -125,25 +126,99 @@ function nodeProject(n: BuildNode): string | undefined {
return undefined;
}
type ToolbarItem = Extract<MenuItem, { kind: "action" }> & { icon: string };
function toolbarButton({ action, icon, checked, label }: ToolbarItem) {
return <IconButton key={action} action={action} icon={icon} title={label} size="small" pressed={checked} />;
}
function MoreActions({ items }: { items: MenuItem[] }) {
const anchor = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false);
return (
<>
<IconButton
ref={anchor}
className={styles.toolbarMore}
icon="more"
title="More Actions"
size="small"
aria-haspopup="menu"
aria-expanded={open}
onClick={() => setOpen((value) => !value)}
/>
<Menu
anchor={anchor}
open={open}
onClose={() => setOpen(false)}
placement="bottom-end"
aria-label={tx("More Actions")}
items={items}
/>
</>
);
}
// Small buttons, separators, gaps and padding in the full toolbar.
const FULL_TOOLBAR_WIDTH: Record<BuildTool, number> = { maven: 274, gradle: 230 };
function Toolbar({ tool, selection }: { tool: BuildTool; selection: BuildNode[] }) {
const toolbar = useRef<HTMLDivElement>(null);
const [compact, setCompact] = useState(false);
const syncing = useBuild((s) => !!s.syncing[tool]);
const settings = useBuild((s) => s.settings);
const settings = useBuild((s) => s.settings[tool]);
const model = useBuild((s) => s.model);
useLayoutEffect(() => {
const node = toolbar.current;
if (!node) return;
const measure = () => {
if (node.clientWidth > 0) setCompact(node.clientWidth < FULL_TOOLBAR_WIDTH[tool]);
};
measure();
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(measure);
observer.observe(node);
return () => observer.disconnect();
}, [tool]);
const config = model && nodeConfig(selection.filter(isRunnable), model);
const runSelected = () => {
if (config) runConfig(config, "run");
};
const maven = tool === "maven";
const projectActions: ToolbarItem[] = [
...(maven ? [{ kind: "action" as const, action: "maven.generateSources", icon: "folder-generated-source" }] : []),
{ kind: "action", action: maven ? "maven.addProjects" : "gradle.linkProjects", icon: "plus" },
];
const buildActions: ToolbarItem[] = [
{ kind: "action", action: `${tool}.toggleOffline`, icon: "build-offline", checked: settings.offline },
{ kind: "action", action: `${tool}.analyzeDependencies`, icon: "build-dependencies" },
{ kind: "action", action: `${tool}.toggleSkipTests`, icon: "skip-tests", checked: settings.skipTests },
];
const treeActions: ToolbarItem[] = [
{ kind: "action", action: `${tool}.expandAll`, icon: "expand-all" },
{ kind: "action", action: `${tool}.collapseAll`, icon: "collapse-all" },
...(maven
? [{ kind: "action" as const, action: "maven.settings", icon: "settings", label: "Maven Settings…" }]
: []),
];
return (
<div className={styles.toolbar} role="toolbar" aria-label={maven ? "Maven actions" : "Gradle actions"}>
<div
ref={toolbar}
className={styles.toolbar}
role="toolbar"
aria-label={maven ? "Maven actions" : "Gradle actions"}
>
{syncing ? (
<IconButton icon="stop" size="small" iconSize={16} action={`${tool}.cancelReload`} />
) : (
<IconButton icon="refresh" size="small" iconSize={16} action={`${tool}.reload`} />
)}
{maven && <IconButton icon="folder-generated-source" size="small" iconSize={16} action="maven.generateSources" />}
<IconButton icon="plus" size="small" iconSize={16} action={maven ? "maven.addProjects" : "gradle.linkProjects"} />
<span className={styles.sep} />
{!compact && (
<>
{projectActions.map(toolbarButton)}
<span className={styles.sep} />
</>
)}
<IconButton
icon="run"
size="small"
@@ -158,31 +233,16 @@ function Toolbar({ tool, selection }: { tool: BuildTool; selection: BuildNode[]
iconSize={16}
action={maven ? "maven.executeGoal" : "gradle.executeTask"}
/>
<IconButton
icon="build-offline"
size="small"
iconSize={16}
action={`${tool}.toggleOffline`}
pressed={maven ? settings.maven.offline : settings.gradle.offline}
/>
<IconButton
icon="build-dependencies"
size="small"
iconSize={16}
action={maven ? "maven.analyzeDependencies" : "gradle.analyzeDependencies"}
/>
<IconButton
icon="skip-tests"
size="small"
iconSize={16}
action={`${tool}.toggleSkipTests`}
pressed={maven ? settings.maven.skipTests : settings.gradle.skipTests}
/>
<span className={styles.sep} />
<IconButton icon="expand-all" size="small" iconSize={16} action={`${tool}.expandAll`} />
<IconButton icon="collapse-all" size="small" iconSize={16} action={`${tool}.collapseAll`} />
{maven && (
<IconButton icon="settings" size="small" iconSize={16} action="maven.settings" title="Maven Settings…" />
{compact ? (
<MoreActions
items={[...projectActions, { kind: "separator" }, ...buildActions, { kind: "separator" }, ...treeActions]}
/>
) : (
<>
{buildActions.map(toolbarButton)}
<span className={styles.sep} />
{treeActions.map(toolbarButton)}
</>
)}
</div>
);
@@ -12,6 +12,9 @@
gap: var(--space-0-5);
padding: 0 6px;
}
.toolbarMore {
margin-left: auto;
}
.sep {
width: 1px;
height: 16px;