From d5f29ea2567d94cfc1eb463d757668ed36463e02 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Fri, 20 Nov 2026 01:06:13 +0800 Subject: [PATCH] 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. --- e2e/buildToolToolbar.spec.ts | 99 ++++++++++++++ src/features/build-tools/BuildToolView.tsx | 122 +++++++++++++----- .../build-tools/BuildTools.module.css | 3 + 3 files changed, 193 insertions(+), 31 deletions(-) create mode 100644 e2e/buildToolToolbar.spec.ts diff --git a/e2e/buildToolToolbar.spec.ts b/e2e/buildToolToolbar.spec.ts new file mode 100644 index 000000000..ffcc5be54 --- /dev/null +++ b/e2e/buildToolToolbar.spec.ts @@ -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(); + }); +} diff --git a/src/features/build-tools/BuildToolView.tsx b/src/features/build-tools/BuildToolView.tsx index fabf69c79..0a34bce6b 100644 --- a/src/features/build-tools/BuildToolView.tsx +++ b/src/features/build-tools/BuildToolView.tsx @@ -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 & { icon: string }; + +function toolbarButton({ action, icon, checked, label }: ToolbarItem) { + return ; +} + +function MoreActions({ items }: { items: MenuItem[] }) { + const anchor = useRef(null); + const [open, setOpen] = useState(false); + return ( + <> + setOpen((value) => !value)} + /> + 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 = { maven: 274, gradle: 230 }; + function Toolbar({ tool, selection }: { tool: BuildTool; selection: BuildNode[] }) { + const toolbar = useRef(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 ( -
+
{syncing ? ( ) : ( )} - {maven && } - - + {!compact && ( + <> + {projectActions.map(toolbarButton)} + + + )} - - - - - - - {maven && ( - + {compact ? ( + + ) : ( + <> + {buildActions.map(toolbarButton)} + + {treeActions.map(toolbarButton)} + )}
); diff --git a/src/features/build-tools/BuildTools.module.css b/src/features/build-tools/BuildTools.module.css index d064d29f4..3bd08d32d 100644 --- a/src/features/build-tools/BuildTools.module.css +++ b/src/features/build-tools/BuildTools.module.css @@ -12,6 +12,9 @@ gap: var(--space-0-5); padding: 0 6px; } +.toolbarMore { + margin-left: auto; +} .sep { width: 1px; height: 16px;