fix(webui): keep MCP connection rows compact (NAN-321)

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-24 20:11:31 +08:00
1 parent 8af2d396ab
commit 60420b45c8
4 files changed
+123 -48

No files matched your search

@@ -0,0 +1,64 @@
import { expect, test, type Locator } from "@playwright/test";
async function rowGeometry(row: Locator) {
return row.evaluate((element) => {
const body = element.querySelector<HTMLButtonElement>("button")!;
const actions = body.nextElementSibling!;
const title = body.querySelector("h3")!;
const rowBox = element.getBoundingClientRect();
const bodyBox = body.getBoundingClientRect();
const actionsBox = actions.getBoundingClientRect();
return {
height: rowBox.height,
sameLine: Math.abs(bodyBox.y + bodyBox.height / 2 - actionsBox.y - actionsBox.height / 2) < 1,
noOverlap: bodyBox.right <= actionsBox.left,
titleFits: title.clientWidth >= title.scrollWidth,
noOverflow: element.scrollWidth <= element.clientWidth,
};
});
}
for (const width of [314, 390, 1280]) {
for (const locale of ["en", "zh-CN", "fr"] as const) {
test(`MCP connection controls stay on one row at ${width}px in ${locale}`, async ({ page }) => {
await page.setViewportSize({ width, height: 850 });
await page.addInitScript((language) => localStorage.setItem("nanobot.locale", language), locale);
await page.goto("/browser/fixture.html?case=apps&connection-layout");
const body = page.getByRole("button", { name: "Linear", exact: true });
const row = page.locator("article").filter({ has: body });
const initial = await rowGeometry(row);
await body.click();
const dialog = page.getByRole("dialog", { name: "Linear", exact: true });
await dialog.getByRole("tab").last().click();
await dialog.getByRole("button", { name: /^(Connect|连接|Connecter)$/ }).click();
await expect(dialog).not.toBeVisible();
const cancel = row.getByRole("button", { name: /^(Cancel|取消|Annuler)$/ });
await expect(cancel).toBeEnabled();
await expect(body).toHaveAccessibleDescription({ en: "Connecting…", "zh-CN": "正在连接…", fr: "Connexion…" }[locale]);
const connecting = await rowGeometry(row);
expect(connecting).toEqual({
height: initial.height, sameLine: true, noOverlap: true, titleFits: true, noOverflow: true,
});
expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true);
await body.focus();
await page.keyboard.press("Tab");
await expect(cancel).toBeFocused();
await page.keyboard.press("Enter");
await expect(cancel).not.toBeVisible();
expect(await rowGeometry(row)).toEqual(initial);
});
}
}
for (const width of [314, 1280]) {
test(`runtime MCP connection stays on one row at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 850 });
await page.goto("/browser/fixture.html?case=apps&connection-layout&runtime");
const body = page.getByRole("button", { name: "Linear", exact: true });
const row = page.locator("article").filter({ has: body });
await expect(row.getByRole("button", { name: "Remove", exact: true })).toBeEnabled();
expect(await rowGeometry(row)).toMatchObject({
sameLine: true, noOverlap: true, titleFits: true, noOverflow: true,
});
});
}
+29 -7
View File
@@ -153,8 +153,25 @@ const unbrandedPlugin: McpPresetInfo = {
function AppsFixture() {
const noop = () => {};
const managing = parameters.has("manage");
const connectionLayout = parameters.has("connection-layout");
const [connecting, setConnecting] = useState(false);
const [actions, setActions] = useState<unknown[]>([]);
const presets: McpPresetInfo[] = managing ? [{
const presets: McpPresetInfo[] = connectionLayout ? [
{
name: "linear", display_name: "Linear", category: "productivity", description: "Manage issues and projects",
docs_url: "", transport: "streamableHttp", auth: "oauth", requires: "Linear account", note: "",
install_supported: true, installed: parameters.has("runtime"), configured: parameters.has("runtime"),
available: true, status: parameters.has("runtime") ? "configured" : "not_installed",
required_fields: [], connection_summary: "", source: "preset",
brand_color: "#5E6AD2", runtime_status: parameters.has("runtime") ? "connecting" : undefined,
},
...["Notion", "GitHub", "Xmind"].map((name): McpPresetInfo => ({
name: name.toLowerCase(), display_name: name, category: "productivity", description: `Connect your ${name} workspace`,
docs_url: "", transport: "streamableHttp", auth: "oauth", requires: "", note: "",
install_supported: true, installed: false, configured: false, available: true,
status: "not_installed", required_fields: [], connection_summary: "", source: "preset",
})),
] : managing ? [{
name: "design", display_name: "Design MCP", category: "design", description: "Read design context",
docs_url: "", transport: "streamableHttp", auth: "oauth", requires: "", note: "",
install_supported: true, installed: false, configured: false, available: true,
@@ -164,19 +181,24 @@ function AppsFixture() {
{ ...unbrandedPlugin, name: "test-mcp", display_name: "Test MCP", source: "builtin", logo_url: "/missing-app-icon.svg" },
{ ...unbrandedPlugin, name: "brand-example", display_name: "Brand Example", source: "builtin", brand_color: "#5E6AD2" },
];
return <main className="mx-auto max-w-4xl p-6"><AppsCatalogSettings
return <main className="mx-auto max-w-4xl p-6" style={connectionLayout ? { maxWidth: 800 } : undefined}><AppsCatalogSettings
cliApps={{ apps: [], installed_count: 0 }}
mcpPresets={{ presets, installed_count: managing ? 0 : 3 }}
cliAppsLoading={false} mcpPresetsLoading={false} query="" filter={managing ? "mcp" : "ready"}
cliActionKey={null} mcpActionKey={null} mcpOAuthFlow={null} mcpOAuthPopupBlocked={false}
mcpPresets={{ presets, installed_count: connectionLayout ? Number(parameters.has("runtime")) : managing ? 0 : 3 }}
cliAppsLoading={false} mcpPresetsLoading={false} query="" filter={managing || connectionLayout ? "mcp" : "ready"}
cliActionKey={null} mcpActionKey={null}
mcpOAuthFlow={connecting ? { flow_id: "fixture", name: "linear", status: "authorization_required", expires_in: 300 } : null}
mcpOAuthPopupBlocked={false}
mcpOAuthCallbackUrl="" mcpOAuthCompleting={false} mcpOAuthCallbackError={null}
cliMessage={null} cliError={null} cliFocusName={null} mcpMessage={null} mcpError={null}
mcpFieldValues={{}} customMcpForm={DEFAULT_CUSTOM_MCP_FORM} mcpConfigImport=""
showBrandLogos={parameters.get("logos") !== "hidden"} requiresRestartPending={false}
onQueryChange={noop} onFilterChange={noop} onCliAction={noop}
onMcpAction={(action, name, values) => setActions((prev) => [...prev, { action, name, values }])}
onMcpOAuthConnect={(name, reset, values) => setActions((prev) => [...prev, { action: "oauth", name, reset, values }])}
onMcpOAuthCancel={noop} onMcpOAuthOpen={noop}
onMcpOAuthConnect={(name, reset, values) => {
setActions((prev) => [...prev, { action: "oauth", name, reset, values }]);
if (connectionLayout) setConnecting(true);
}}
onMcpOAuthCancel={() => setConnecting(false)} onMcpOAuthOpen={noop}
onMcpOAuthCallbackUrlChange={noop} onMcpOAuthComplete={noop} onDismissStatus={noop}
onBackToChat={noop} onMcpFieldChange={noop} onCustomMcpFormChange={noop}
onMcpConfigImportChange={noop} onSaveCustomMcp={noop} onImportMcpConfig={noop}
@@ -547,6 +547,7 @@ function McpAppsCatalogRow({
const tx = (key: string, fallback: string) => t(key, { defaultValue: fallback });
const [managementOpen, setManagementOpen] = useState(false);
const [managementTab, setManagementTab] = useState<McpManagementTab>("overview");
const connectionStatusId = useId();
useEffect(() => {
if (!openConnection) return;
setManagementTab("connection");
@@ -574,6 +575,7 @@ function McpAppsCatalogRow({
const runtimeConnected = !toggleable && preset.runtime_status === "connected";
const runtimeConnecting = !toggleable && preset.runtime_status === "connecting";
const runtimeFailed = !toggleable && preset.installed && preset.runtime_status === "failed";
const connecting = Boolean(oauthFlow) || (runtimeConnecting && configuredInstalled);
const statusLabel = toggleable
? tx("settings.nanobotFeatures.enabled", "Enabled")
: runtimeConnected
@@ -615,8 +617,9 @@ function McpAppsCatalogRow({
<button
type="button"
aria-label={preset.display_name}
aria-describedby={connecting ? connectionStatusId : undefined}
onClick={() => openManagement()}
className="flex min-w-0 flex-[1_1_8rem] items-center gap-3 rounded-control text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
className="flex min-w-0 flex-[1_1_6rem] items-center gap-3 rounded-control text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<McpPresetLogo preset={preset} showBrandLogos={showBrandLogos} />
<div className="min-w-0 flex-1">
@@ -631,18 +634,21 @@ function McpAppsCatalogRow({
) : null}
</div>
<p
id={connectionStatusId}
className={cn(
"mt-0.5 flex min-w-0 items-center gap-1.5 text-[12.5px] leading-5 text-muted-foreground",
runtimeFailed && "font-medium text-destructive",
!connecting && runtimeFailed && "font-medium text-destructive",
)}
>
{runtimeFailed ? (
{connecting ? (
<Loader2 className="h-3.5 w-3.5 shrink-0 animate-spin motion-reduce:animate-none" aria-hidden />
) : runtimeFailed ? (
<TriangleAlert className="h-3.5 w-3.5 shrink-0" aria-hidden />
) : null}
<span className="truncate">
{runtimeFailed ? failureLabel : detail}
{connecting ? tx("settings.mcp.connectingLabel", "Connecting…") : runtimeFailed ? failureLabel : detail}
</span>
{!runtimeFailed && agentPlugin && description && preset.requires ? (
{!connecting && !runtimeFailed && agentPlugin && description && preset.requires ? (
<span className="min-w-0 truncate">{preset.requires}</span>
) : null}
</p>
@@ -650,39 +656,22 @@ function McpAppsCatalogRow({
</button>
<div className="ml-auto flex shrink-0 items-center gap-1">
{oauthFlow ? (
<>
<AppsActionButton
ariaLabel={t("settings.mcp.connectingAccount", {
name: preset.display_name,
defaultValue: "Connecting {{name}}",
})}
visibleLabel={tx("settings.mcp.connectingLabel", "Connecting…")}
busy
/>
<AppsActionButton
ariaLabel={tx("settings.actions.cancel", "Cancel")}
visibleLabel={tx("settings.actions.cancel", "Cancel")}
tone="danger"
onClick={onOAuthCancel}
/>
</>
<AppsActionButton
ariaLabel={tx("settings.actions.cancel", "Cancel")}
visibleLabel={tx("settings.actions.cancel", "Cancel")}
tone="danger"
onClick={onOAuthCancel}
/>
) : runtimeConnecting && configuredInstalled ? (
<>
<AppsActionButton
ariaLabel={`${preset.display_name}: ${tx("settings.mcp.connectingLabel", "Connecting…")}`}
visibleLabel={tx("settings.mcp.connectingLabel", "Connecting…")}
busy
/>
<AppsActionButton
ariaLabel={tx("settings.mcp.remove", "Remove")}
busy={removeBusy}
disabled={busy && !removeBusy}
tone="danger"
onClick={() => onAction("remove", preset.name)}
>
<Trash2 className="h-4 w-4" aria-hidden />
</AppsActionButton>
</>
<AppsActionButton
ariaLabel={tx("settings.mcp.remove", "Remove")}
busy={removeBusy}
disabled={busy && !removeBusy}
tone="danger"
onClick={() => onAction("remove", preset.name)}
>
<Trash2 className="h-4 w-4" aria-hidden />
</AppsActionButton>
) : runtimeFailed ? (
<AppsActionButton
ariaLabel={t("settings.mcp.manageTitle", {
+4 -4
View File
@@ -276,7 +276,7 @@ describe("SettingsView Apps catalog", () => {
expect(screen.getByRole("status")).toHaveTextContent(
"Complete sign-in in the browser window.",
);
expect(screen.getByRole("button", { name: "Connecting Xmind" })).toHaveTextContent(
expect(screen.getByRole("button", { name: "Xmind" })).toHaveAccessibleDescription(
"Connecting…",
);
expect(screen.getByRole("button", { name: "Cancel" })).toBeInTheDocument();
@@ -426,8 +426,8 @@ describe("SettingsView Apps catalog", () => {
renderSettingsView({ initialSection: "apps" });
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
expect(await screen.findByRole("button", { name: "Xmind: Connecting…" }))
.toHaveTextContent("Connecting…");
expect(await screen.findByRole("button", { name: "Xmind" }))
.toHaveAccessibleDescription("Connecting…");
expect(await screen.findByRole(
"button",
{ name: "Manage Xmind" },
@@ -738,7 +738,7 @@ describe("SettingsView Apps catalog", () => {
await connectXmind();
const cancelButton = await screen.findByRole("button", { name: "Cancel" });
expect(screen.getByRole("button", { name: "Connecting Xmind" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Xmind" })).toHaveAccessibleDescription("Connecting…");
popup.closed = true;
fireEvent.click(cancelButton);