mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(vcs): keep clone fields usable in narrow dialogs (#4618)
Clone dialog fields stay usable and inside the dialog in narrow windows. Verified with e2e cloneLayout, vcs vitest and typecheck.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
||||
|
||||
const REPO = "https://example.test/team/billing-service.git";
|
||||
|
||||
test("Clone Repository keeps URL, directory, and depth usable when the dialog narrows", async ({ workbench: page }) => {
|
||||
await stubDesktop(page);
|
||||
await page.setViewportSize({ width: 440, height: 620 });
|
||||
await page.evaluate(async (repo) => {
|
||||
window.__ipc.handlers["plugin:dialog|open"] = () => "/dev/workspaces";
|
||||
window.__ipc.handlers.vcs_clone = () => new Promise(() => {});
|
||||
const contributionsPath = "/src/workbench/contributions.ts";
|
||||
const { registerCloneSource } = await import(/* @vite-ignore */ contributionsPath);
|
||||
registerCloneSource({ id: "team", label: "Team repositories", icon: "branch", component: () => null });
|
||||
const actionsPath = "/src/platform/actions.ts";
|
||||
const { executeAction } = await import(/* @vite-ignore */ actionsPath);
|
||||
await executeAction("vcs.clone", repo);
|
||||
}, REPO);
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Clone Repository" });
|
||||
const sources = dialog.getByRole("complementary", { name: "Clone source" });
|
||||
const url = dialog.getByRole("textbox", { name: "URL:" });
|
||||
await expect(url).toHaveValue(REPO);
|
||||
await expect.poll(async () => (await url.boundingBox())!.width).toBeGreaterThan(180);
|
||||
|
||||
const form = dialog.locator("form");
|
||||
const position = () =>
|
||||
form.evaluate((el) => {
|
||||
const source = el.parentElement!.querySelector("aside")!.getBoundingClientRect();
|
||||
const body = el.getBoundingClientRect();
|
||||
return { below: body.top >= source.bottom, beside: body.left >= source.right };
|
||||
});
|
||||
await expect.poll(async () => (await position()).below).toBe(true);
|
||||
expect(await form.evaluate((el) => el.scrollWidth === el.clientWidth)).toBe(true);
|
||||
|
||||
await dialog.getByRole("button", { name: "Browse…" }).click();
|
||||
const directory = dialog.getByRole("textbox", { name: "Directory:" });
|
||||
await expect(directory).toHaveValue("/dev/workspaces/billing-service");
|
||||
|
||||
const shallow = dialog.getByRole("checkbox", { name: /^Shallow clone/ });
|
||||
const depth = dialog.getByRole("spinbutton", { name: "Clone depth" });
|
||||
await expect(depth).toBeDisabled();
|
||||
await shallow.check();
|
||||
await depth.fill("0");
|
||||
const clone = dialog.getByRole("button", { name: "Clone", exact: true });
|
||||
await expect(clone).toBeDisabled();
|
||||
await depth.fill("3");
|
||||
|
||||
await page.setViewportSize({ width: 1050, height: 750 });
|
||||
await expect.poll(async () => (await position()).beside).toBe(true);
|
||||
await sources.getByRole("button", { name: "Team repositories" }).click();
|
||||
await expect(url).toBeHidden();
|
||||
await sources.getByRole("button", { name: "Repository URL" }).click();
|
||||
await expect(url).toHaveValue(REPO);
|
||||
await expect(directory).toHaveValue("/dev/workspaces/billing-service");
|
||||
await expect(depth).toHaveValue("3");
|
||||
|
||||
await page.setViewportSize({ width: 440, height: 620 });
|
||||
await clone.click();
|
||||
await expect
|
||||
.poll(() => ipcCalls(page, "vcs_clone"))
|
||||
.toEqual([expect.objectContaining({ url: REPO, dest: "/dev/workspaces/billing-service", depth: 3 })]);
|
||||
});
|
||||
@@ -25,52 +25,61 @@
|
||||
display: flex;
|
||||
}
|
||||
.sidebar {
|
||||
flex: 0 0 224px;
|
||||
padding: 8px 0;
|
||||
flex: 0 0 200px;
|
||||
padding: var(--space-2) 0;
|
||||
border-right: 1px solid var(--border);
|
||||
background: color-mix(in srgb, var(--bg-dialog, var(--bg-elev)) 96%, var(--fg-strong));
|
||||
overflow: auto;
|
||||
}
|
||||
.sourceItem {
|
||||
min-height: 44px;
|
||||
min-height: var(--h-row);
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 9px 14px;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-1) var(--space-3);
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--fg-strong);
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: default;
|
||||
}
|
||||
.sourceItem[data-selected] {
|
||||
background: var(--bg-tree-selected);
|
||||
}
|
||||
.sourceName {
|
||||
font-weight: 600;
|
||||
line-height: 22px;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
font-weight: 500;
|
||||
font-size: var(--fs-ui);
|
||||
line-height: 1.4;
|
||||
}
|
||||
.form {
|
||||
--clone-label-width: 112px;
|
||||
--clone-field-gap: var(--space-3);
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-4);
|
||||
padding: 28px 24px;
|
||||
gap: var(--space-3);
|
||||
overflow: auto;
|
||||
padding: var(--space-4);
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
.versionRow,
|
||||
.fieldRow {
|
||||
display: grid;
|
||||
grid-template-columns: 112px minmax(0, 1fr);
|
||||
grid-template-columns: var(--clone-label-width) minmax(0, 1fr);
|
||||
align-items: center;
|
||||
gap: 10px var(--space-3);
|
||||
gap: var(--clone-field-gap);
|
||||
}
|
||||
.versionRow {
|
||||
grid-template-columns: 112px 138px minmax(0, 1fr);
|
||||
}
|
||||
.versionRow > label,
|
||||
.fieldRow > label {
|
||||
color: var(--fg-strong);
|
||||
text-align: right;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.versionSelect {
|
||||
width: 138px;
|
||||
width: min(138px, 100%);
|
||||
}
|
||||
.comboField {
|
||||
min-width: 0;
|
||||
@@ -89,7 +98,7 @@
|
||||
.fieldInput {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
padding: 0 8px;
|
||||
padding-inline: var(--space-2);
|
||||
background: transparent;
|
||||
}
|
||||
.fieldButton {
|
||||
@@ -101,16 +110,27 @@
|
||||
.shallowRow {
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding-left: 124px;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
.shallowRow,
|
||||
.feedback {
|
||||
padding-inline-start: calc(var(--clone-label-width) + var(--clone-field-gap));
|
||||
}
|
||||
.depthGroup {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.depthInput {
|
||||
width: 84px;
|
||||
}
|
||||
.feedback {
|
||||
min-width: 0;
|
||||
padding-left: 124px;
|
||||
}
|
||||
.progress {
|
||||
display: flex;
|
||||
@@ -127,44 +147,38 @@
|
||||
color: var(--fg-subtle);
|
||||
font-size: var(--fs-small);
|
||||
line-height: 1.5;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.error {
|
||||
color: var(--danger);
|
||||
font-size: var(--fs-small);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.sidebar {
|
||||
flex-basis: 172px;
|
||||
}
|
||||
.form {
|
||||
padding-inline: 16px;
|
||||
}
|
||||
.versionRow,
|
||||
.fieldRow {
|
||||
grid-template-columns: 86px minmax(0, 1fr);
|
||||
}
|
||||
.versionRow {
|
||||
grid-template-columns: 86px 118px minmax(0, 1fr);
|
||||
}
|
||||
.versionSelect {
|
||||
width: 118px;
|
||||
}
|
||||
.shallowRow,
|
||||
.feedback {
|
||||
padding-left: 98px;
|
||||
}
|
||||
.layout[data-compact] {
|
||||
flex-direction: column;
|
||||
}
|
||||
.sidebar .sourceItem {
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background: none;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: default;
|
||||
.layout[data-compact] .sidebar {
|
||||
flex: 0 1 auto;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-content: flex-start;
|
||||
gap: var(--space-1);
|
||||
max-height: min(120px, 32%);
|
||||
padding: var(--space-1);
|
||||
border-right: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.sidebar .sourceItem[data-selected] {
|
||||
background: var(--bg-tree-selected);
|
||||
.layout[data-compact] .sourceItem {
|
||||
width: auto;
|
||||
max-width: 100%;
|
||||
border-radius: var(--radius-row);
|
||||
}
|
||||
.layout[data-compact] .form {
|
||||
--clone-label-width: 104px;
|
||||
}
|
||||
.layout[data-compact] .shallowRow {
|
||||
padding-inline-start: 0;
|
||||
}
|
||||
.sidebar .sourceItem:focus-visible {
|
||||
outline: 2px solid var(--focus-ring);
|
||||
|
||||
+33
-17
@@ -130,6 +130,8 @@ function CloneDialog({ onClose, initialUrl }: { onClose: () => void; initialUrl:
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const request = useRef<number | null>(null);
|
||||
const urlField = useRef<HTMLDivElement>(null);
|
||||
const layout = useRef<HTMLDivElement>(null);
|
||||
const [compact, setCompact] = useState(false);
|
||||
const [recentUrls] = useState(readRecentUrls);
|
||||
const sources = cloneSourceList(useCloneSources((s) => s.sources));
|
||||
const source = sources.find((s) => s.id === sourceId);
|
||||
@@ -142,6 +144,17 @@ function CloneDialog({ onClose, initialUrl }: { onClose: () => void; initialUrl:
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const el = layout.current;
|
||||
if (!el || typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(([entry]) => {
|
||||
const width = entry?.contentRect.width;
|
||||
if (width) setCompact(width < 580);
|
||||
});
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
const dir = customDir ?? joinPath(parent, cloneDirName(url));
|
||||
const depth = shallow ? parseCloneDepth(depthInput) : null;
|
||||
const invalid = validateClone(url, dir) ?? (shallow && depth === null ? "Enter a positive number of commits" : null);
|
||||
@@ -231,7 +244,7 @@ function CloneDialog({ onClose, initialUrl }: { onClose: () => void; initialUrl:
|
||||
{ label: "Cancel", role: "cancel", onClick: cancel },
|
||||
]}
|
||||
>
|
||||
<div className={styles.layout}>
|
||||
<div ref={layout} className={styles.layout} data-compact={compact || undefined}>
|
||||
<aside className={styles.sidebar} aria-label={tx("Clone source")}>
|
||||
{[{ id: "url", label: "Repository URL", icon: "branch" }, ...sources].map((s) => (
|
||||
<button
|
||||
@@ -243,7 +256,7 @@ function CloneDialog({ onClose, initialUrl }: { onClose: () => void; initialUrl:
|
||||
disabled={busy}
|
||||
onClick={() => setSourceId(s.id)}
|
||||
>
|
||||
<Icon name={s.icon} size={22} />
|
||||
<Icon name={s.icon} size={16} />
|
||||
<span className={styles.sourceName}>
|
||||
<T>{s.label}</T>
|
||||
</span>
|
||||
@@ -264,11 +277,12 @@ function CloneDialog({ onClose, initialUrl }: { onClose: () => void; initialUrl:
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className={styles.versionRow}>
|
||||
<label id="vcs-clone-version-label">
|
||||
<div className={styles.fieldRow}>
|
||||
<label htmlFor="vcs-clone-version">
|
||||
<T>Version control:</T>
|
||||
</label>
|
||||
<Select
|
||||
id="vcs-clone-version"
|
||||
aria-label="Version control"
|
||||
className={styles.versionSelect}
|
||||
value="git"
|
||||
@@ -337,19 +351,21 @@ function CloneDialog({ onClose, initialUrl }: { onClose: () => void; initialUrl:
|
||||
onChange={setShallow}
|
||||
label={<T>Shallow clone with a history truncated to</T>}
|
||||
/>
|
||||
<Input
|
||||
aria-label="Clone depth"
|
||||
className={styles.depthInput}
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min={1}
|
||||
step={1}
|
||||
value={depthInput}
|
||||
disabled={busy || !shallow}
|
||||
invalid={shallow && depth === null}
|
||||
onChange={(e) => setDepthInput(e.target.value)}
|
||||
/>
|
||||
<T>commits</T>
|
||||
<div className={styles.depthGroup}>
|
||||
<Input
|
||||
aria-label="Clone depth"
|
||||
className={styles.depthInput}
|
||||
type="number"
|
||||
inputMode="numeric"
|
||||
min={1}
|
||||
step={1}
|
||||
value={depthInput}
|
||||
disabled={busy || !shallow}
|
||||
invalid={shallow && depth === null}
|
||||
onChange={(e) => setDepthInput(e.target.value)}
|
||||
/>
|
||||
<T>commits</T>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={styles.feedback}>
|
||||
|
||||
Reference in New Issue
Block a user