mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Keep Extract Interface members readable in short windows (#4720)
The Extract Interface dialog keeps its member table readable in short windows: the table takes the remaining height with a Member header and scrolls, while the name and package fields stay in view.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import type { ExtractInterfaceInfo } from "../src/bindings";
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
const info: ExtractInterfaceInfo = {
|
||||
className: "InvoiceService",
|
||||
packages: [
|
||||
{ displayName: "com.example.billing", path: "/dev/acme-api", isParentOfSelectedFile: true },
|
||||
{ displayName: "com.example.billing.api", path: "/dev/acme-api/api" },
|
||||
].map((entry) => JSON.stringify(entry)),
|
||||
members: Array.from({ length: 24 }, (_, i) => ({
|
||||
name: `prepareInvoiceForInternationalSettlement${i + 1}`,
|
||||
parameters: ["BigDecimal", "Map<String, BigDecimal>", "LocalDate", "boolean"],
|
||||
typeName: "SettlementInvoice",
|
||||
handleIdentifier: `method-${i + 1}`,
|
||||
})),
|
||||
};
|
||||
|
||||
test("keeps the interface fields, members and actions usable in a short window", async ({ workbench: page }) => {
|
||||
await page.setViewportSize({ width: 470, height: 410 });
|
||||
await page.evaluate(async () => {
|
||||
const workbench = "/src/workbench/contributions.ts";
|
||||
const { editorService } = await import(/* @vite-ignore */ workbench);
|
||||
await editorService().openFile("/dev/acme-api/InvoiceService.java", { focus: true });
|
||||
});
|
||||
const editor = page.locator(".cm-editor .cm-content");
|
||||
await expect(editor).toBeVisible();
|
||||
await stubDesktop(page);
|
||||
await editor.focus();
|
||||
await page.evaluate(async (info) => {
|
||||
window.__ipc.handlers.lsp_extract_interface_info = () => info;
|
||||
const actions = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ actions);
|
||||
await executeAction("refactor.extractInterface");
|
||||
}, info);
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Extract Interface" });
|
||||
const table = dialog.getByRole("table", { name: "Members to Form Interface" });
|
||||
await expect(table.getByRole("row")).toHaveCount(25);
|
||||
const source = dialog.getByRole("textbox", { name: "Extract interface from:", exact: true });
|
||||
const name = dialog.getByRole("textbox", { name: "Interface name:", exact: true });
|
||||
await expect(source).toHaveAttribute("readonly", "");
|
||||
await expect(source).toHaveValue("InvoiceService");
|
||||
await expect(name).toBeFocused();
|
||||
await expect(source).toBeInViewport({ ratio: 1 });
|
||||
await name.fill("SettlementInvoicing");
|
||||
|
||||
const body = dialog.locator("[data-dialog-body]");
|
||||
const refactor = dialog.getByRole("button", { name: "Refactor", exact: true });
|
||||
await expect(refactor).toBeDisabled();
|
||||
const last = table.getByRole("checkbox", { name: /^prepareInvoiceForInternationalSettlement24\(/ });
|
||||
await last.scrollIntoViewIfNeeded();
|
||||
await expect(last).toBeInViewport({ ratio: 1 });
|
||||
await expect(table.getByRole("columnheader", { name: "Member" })).toBeInViewport({ ratio: 1 });
|
||||
await expect.poll(() => table.evaluate((el) => el.scrollTop)).toBeGreaterThan(100);
|
||||
expect(await table.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
await last.check();
|
||||
await expect(refactor).toBeEnabled();
|
||||
expect(await body.evaluate((el) => el.scrollHeight - el.clientHeight)).toBeLessThanOrEqual(1);
|
||||
await expect(refactor).toBeInViewport({ ratio: 1 });
|
||||
await expect(dialog.getByRole("button", { name: "Preview", exact: true })).toBeInViewport({ ratio: 1 });
|
||||
await dialog.getByRole("button", { name: "Cancel", exact: true }).click();
|
||||
await expect(dialog).toBeHidden();
|
||||
await expect(editor).toBeFocused();
|
||||
});
|
||||
@@ -1,7 +1,10 @@
|
||||
.dialog [data-dialog-body] {
|
||||
.dialog {
|
||||
height: 520px;
|
||||
}
|
||||
|
||||
.dialog > [data-dialog-body] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.body {
|
||||
@@ -9,8 +12,8 @@
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-3);
|
||||
padding: 14px;
|
||||
gap: var(--space-1-5);
|
||||
padding: var(--space-2) var(--space-4);
|
||||
font-size: var(--fs-ui);
|
||||
color: var(--fg);
|
||||
}
|
||||
@@ -19,43 +22,55 @@
|
||||
flex: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1-5);
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.source {
|
||||
font-family: var(--font-mono);
|
||||
color: var(--fg-muted);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.memberTitle {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.memberTitle::after {
|
||||
content: "";
|
||||
flex: 1;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: calc(var(--h-list-row) * 3);
|
||||
overflow: auto;
|
||||
scrollbar-gutter: stable;
|
||||
scroll-padding-top: var(--h-list-row);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
border-radius: var(--radius-small);
|
||||
}
|
||||
|
||||
.head,
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: 0 8px;
|
||||
padding: 0 var(--space-2);
|
||||
min-height: var(--h-list-row);
|
||||
}
|
||||
|
||||
.head {
|
||||
color: var(--fg-muted);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
background: var(--bg-popup);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.rows {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
.head .member {
|
||||
color: var(--fg-muted);
|
||||
}
|
||||
|
||||
.row:hover {
|
||||
@@ -63,11 +78,21 @@
|
||||
}
|
||||
|
||||
.member {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.memberLabel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.memberLabel > svg {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-family: var(--font-mono);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/** IDEA's Extract Interface dialog for Java classes (`extractInterface.ts`). */
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Checkbox, Dialog, Input, Select, Spinner, T } from "@/ui";
|
||||
import { Checkbox, Dialog, Icon, Input, Select, Spinner, T } from "@/ui";
|
||||
import { useTx } from "@/platform/i18n";
|
||||
import {
|
||||
extractInterface,
|
||||
@@ -74,8 +73,8 @@ function ExtractInterfaceDialogInner({ request }: { request: InterfaceRequest })
|
||||
title="Extract Interface"
|
||||
className={styles.dialog}
|
||||
width={560}
|
||||
minWidth={350}
|
||||
minHeight={360}
|
||||
maxHeight={600}
|
||||
resizable="both"
|
||||
buttons={[
|
||||
{ label: "Preview", role: "extra", disabled: !ready, onClick: () => void submit(true) },
|
||||
@@ -92,13 +91,13 @@ function ExtractInterfaceDialogInner({ request }: { request: InterfaceRequest })
|
||||
}
|
||||
>
|
||||
<div className={styles.body}>
|
||||
<div className={styles.field}>
|
||||
<label className={styles.field}>
|
||||
<T>Extract interface from:</T>
|
||||
<span className={styles.source}>{info.className}</span>
|
||||
</div>
|
||||
<Input className={styles.source} mono readOnly value={info.className} />
|
||||
</label>
|
||||
<label className={styles.field}>
|
||||
<T>Interface name:</T>
|
||||
<Input mono autoFocus value={name} onChange={(e) => setName(e.target.value)} />
|
||||
<Input mono data-autofocus="" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</label>
|
||||
<label className={styles.field}>
|
||||
<T>Package for new interface:</T>
|
||||
@@ -109,27 +108,42 @@ function ExtractInterfaceDialogInner({ request }: { request: InterfaceRequest })
|
||||
onChange={setPkg}
|
||||
/>
|
||||
</label>
|
||||
<div className={styles.memberTitle}>
|
||||
<T>Members to Form Interface</T>
|
||||
</div>
|
||||
<div className={styles.table} role="table" aria-label={tx("Members to Form Interface")}>
|
||||
<div className={styles.head} role="row">
|
||||
<Checkbox
|
||||
checked={allChecked}
|
||||
indeterminate={checked.size > 0 && !allChecked}
|
||||
onChange={(on) => setChecked(on ? new Set(info.members.map((m) => m.handleIdentifier)) : new Set())}
|
||||
label={<T>Members to Form Interface</T>}
|
||||
/>
|
||||
<div role="columnheader">
|
||||
<Checkbox
|
||||
className={styles.member}
|
||||
checked={allChecked}
|
||||
indeterminate={checked.size > 0 && !allChecked}
|
||||
onChange={(on) => setChecked(on ? new Set(info.members.map((m) => m.handleIdentifier)) : new Set())}
|
||||
aria-label="Select All"
|
||||
label={<T>Member</T>}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.rows}>
|
||||
{info.members.map((m) => (
|
||||
{info.members.map((m) => {
|
||||
const label = memberLabel(m);
|
||||
return (
|
||||
<div key={m.handleIdentifier} className={styles.row} role="row">
|
||||
<Checkbox
|
||||
className={styles.member}
|
||||
checked={checked.has(m.handleIdentifier)}
|
||||
onChange={(on) => toggle(m.handleIdentifier, on)}
|
||||
label={<span className={styles.label}>{memberLabel(m)}</span>}
|
||||
/>
|
||||
<div role="cell">
|
||||
<Checkbox
|
||||
className={styles.member}
|
||||
checked={checked.has(m.handleIdentifier)}
|
||||
onChange={(on) => toggle(m.handleIdentifier, on)}
|
||||
label={
|
||||
<span className={styles.memberLabel} title={label}>
|
||||
<Icon name={m.parameters ? "method" : "field"} size={16} />
|
||||
<span className={styles.label}>{label}</span>
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
{(error ?? (trimmed && problem)) && (
|
||||
<span className={styles.error} role="alert">
|
||||
|
||||
@@ -2255,6 +2255,7 @@
|
||||
"Interface name:": "Interface name:",
|
||||
"Package for new interface:": "Package for new interface:",
|
||||
"Members to Form Interface": "Members to Form Interface",
|
||||
"Member": "Member",
|
||||
"No interface name specified": "No interface name specified",
|
||||
"Interface name is not a valid identifier": "Interface name is not a valid identifier",
|
||||
"Interface name should differ from the class name": "Interface name should differ from the class name",
|
||||
|
||||
Reference in New Issue
Block a user