Compare commits

...
3 changed files with 93 additions and 31 deletions

No files matched your search

+35 -2
View File
@@ -11,7 +11,7 @@ async function openNewBranchDialog(
page: Page,
from?: string,
mergeBase = "1111111",
blocked = false,
blocked: boolean | string = false,
withPrefix = false,
) {
await stubDesktop(page);
@@ -43,7 +43,10 @@ async function openNewBranchDialog(
];
h.vcs_create_branch = ({ options }) =>
blocked && (options as { mode?: string } | null)?.mode === "normal"
? { checkout: { kind: "localChanges", files: ["dirty.txt"] }, created: null }
? {
checkout: { kind: "localChanges", files: [typeof blocked === "string" ? blocked : "dirty.txt"] },
created: null,
}
: { checkout: { kind: "done" }, created: { tip: "2222222", previousTip: null } };
h.vcs_merge_base = () => mergeBase;
const vcsModule = "/src/features/vcs/store.ts";
@@ -151,6 +154,36 @@ for (const [button, mode] of [
});
}
test("local changes review keeps file names and checkout choices visible", async ({ workbench: page }) => {
await page.setViewportSize({ width: 1040, height: 740 });
const folder = "services/international-payments/regional-settlement/weekly-close/adjustments";
const path = `${folder}/ReceiptPolicy.ts`;
const { dialog, input } = await openNewBranchDialog(page, "2".repeat(40), "1111111", path);
await input.fill("topic");
await dialog.getByRole("button", { name: "Create", exact: true }).click();
const review = page.getByRole("dialog", { name: "Git Checkout Problem" });
const force = review.getByRole("button", { name: "Force Checkout", exact: true });
const smart = review.getByRole("button", { name: "Smart Checkout", exact: true });
const cancel = review.getByRole("button", { name: "Don't Checkout", exact: true });
await expect(force).toBeVisible();
expect((await force.boundingBox())!.x - (await review.boundingBox())!.x).toBeLessThan(24);
await page.setViewportSize({ width: 420, height: 480 });
const tree = review.getByRole("tree", { name: "Changed files" });
const row = tree.getByRole("treeitem", { name: `ReceiptPolicy.ts ${folder}`, exact: true });
await expect(row.getByTitle(path, { exact: true })).toBeVisible();
const file = row.getByText("ReceiptPolicy.ts", { exact: true });
await expect(file).toBeInViewport({ ratio: 1 });
expect(await file.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await expect(row.getByText(folder, { exact: true })).toHaveCSS("font-size", "12px");
const restoreHint = review.getByText(/Smart Checkout .* your changes and restores them/);
expect((await restoreHint.boundingBox())!.y).toBeLessThan((await tree.boundingBox())!.y);
for (const button of [force, smart, cancel]) await expect(button).toBeInViewport({ ratio: 1 });
await cancel.click();
await expect(review).toBeHidden();
expect(await ipcCalls(page, "vcs_create_branch")).toHaveLength(1);
});
test("pasted text has its spaces replaced", async ({ workbench: page }) => {
const { dialog, input } = await openNewBranchDialog(page);
await input.fill("");
@@ -13,7 +13,12 @@
font-size: var(--fs-ui);
}
.content p {
.intro {
display: grid;
gap: var(--space-1);
}
.intro p {
margin: 0;
}
@@ -21,7 +26,7 @@
display: flex;
flex: 1 1 230px;
flex-direction: column;
min-height: 0;
min-height: calc(2 * var(--h-row) + var(--h-control));
border: 1px solid var(--border);
border-radius: var(--radius-small);
overflow: hidden;
@@ -40,13 +45,32 @@
min-height: var(--h-row);
}
.path {
.nodeIcon {
flex: none;
}
.fileLabel {
display: flex;
flex: 1;
align-items: baseline;
gap: var(--space-1-5);
min-width: 0;
}
.fileName,
.directory {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.directory {
flex: 1;
color: var(--fg-subtle);
font-size: var(--fs-small);
}
.hint {
color: var(--fg-subtle);
}
+31 -26
View File
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useRef, useState } from "react";
import type { CheckoutOptions, FileStatus } from "@/bindings";
import { bindingsFor, normalizeBinding, registerKeyClaim, shortcutLabel } from "@/platform/keymap";
import { Dialog, Icon, IconButton, T, Tree, fileIconName, showContextMenu, type DialogButton } from "@/ui";
import { Button, Dialog, Icon, IconButton, T, Tree, fileIconName, showContextMenu, type DialogButton } from "@/ui";
import { showRollbackDialog } from "./changeOps";
import { isNestedRepoEntry } from "./submoduleRollback";
import { groupOf, isPartiallyStaged } from "./changes";
@@ -9,7 +9,7 @@ import { workingDiffData, withChain } from "./diffInput";
import { openDialog } from "./dialogs";
import { dirKeys, type FileTreeNode } from "./fileTree";
import { filesUnder } from "./logChanges";
import { baseName, effectiveKind, KIND_COLOR, rootOf } from "./model";
import { baseName, dirName, effectiveKind, KIND_COLOR, rootOf } from "./model";
import { repositoryPath } from "./repositoryPaths";
import { refreshNow, repoName, useVcs } from "./store";
import { useWorkflowSettings } from "@/platform/workflowSettings";
@@ -180,15 +180,6 @@ function LocalChangesReviewDialog({
},
{ label: text.cancel, role: "cancel", disabled: rollingBack },
];
if (operation === "checkout") {
buttons.splice(1, 0, {
label: "Force Checkout",
role: "extra",
title: "Discard local changes in affected repositories",
disabled: !blocked || rollingBack,
onClick: () => onDone({ mode: "force", files: visible }),
});
}
return (
<Dialog
open
@@ -201,11 +192,29 @@ function LocalChangesReviewDialog({
minHeight={300}
resizable="both"
buttons={buttons}
footerStart={
operation === "checkout" && (
<Button
title="Discard local changes in affected repositories"
disabled={!blocked || rollingBack}
onClick={() => onDone({ mode: "force", files: visible })}
>
Force Checkout
</Button>
)
}
>
<div ref={content} className={styles.content}>
<p>
<T>{blocked ? text.wouldOverwrite : text.cleared}</T>
</p>
<div className={styles.intro}>
<p>
<T>{blocked ? text.wouldOverwrite : text.cleared}</T>
</p>
{blocked && !reviewOnly && (
<p className={styles.hint}>
<T>{text[policy]}</T>
</p>
)}
</div>
<div className={styles.review}>
<div className={styles.toolbar}>
<IconButton
@@ -269,27 +278,23 @@ function LocalChangesReviewDialog({
className={styles.tree}
renderNode={(node) => {
const file = node.file;
const name = file ? baseName(node.name) : node.name;
const directory = file ? dirName(node.name) : "";
const kind = file?.status && effectiveKind(file.status);
return (
<>
<Icon name={file ? fileIconName(baseName(node.name)) : "folder"} size={16} />
<span
className={styles.path}
title={node.name}
style={{ color: kind ? KIND_COLOR[kind] : undefined }}
>
{node.name}
<Icon className={styles.nodeIcon} name={file ? fileIconName(name) : "folder"} size={16} />
<span className={styles.fileLabel} title={node.name}>
<span className={styles.fileName} style={{ color: kind ? KIND_COLOR[kind] : undefined }}>
{name}
</span>
{directory && <span className={styles.directory}>{directory}</span>}
</span>
</>
);
}}
/>
</div>
{blocked && !reviewOnly && (
<p className={styles.hint}>
<T>{text[policy]}</T>
</p>
)}
</div>
</Dialog>
);