Give the Stash dialog room for branch names and messages (#4623)

Stash dialog gives branch names and the message field room. Verified with e2e stashDialogLayout, vcs vitest and typecheck.
This commit is contained in:
l0ng-ai
2026-11-20 08:22:35 +08:00
committed by GitHub
parent 610fe23f88
commit f29903b698
3 changed files with 128 additions and 16 deletions
+60
View File
@@ -0,0 +1,60 @@
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("Stash wraps the current branch and accepts a multiline message in a narrow window", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 380, height: 590 });
await stubDesktop(page);
const root = "/dev/settlement-engine";
const head = "release/QuarterlyInternationalSettlementReconciliationAndAuthorizationForMerchantOperations";
await page.evaluate(
async ({ root, head }) => {
const branch = { head, headCommit: "c1", upstream: null, ahead: 0, behind: 0, operation: null };
const h = window.__ipc.handlers;
h.vcs_branch_info = () => branch;
h.vcs_roots = () => [{ root, ...branch }];
h.vcs_status = () => [];
h.vcs_stashes = () => [];
h.vcs_stash_push = () => null;
const storeModule = "/src/features/vcs/store.ts";
const { useVcs } = await import(/* @vite-ignore */ storeModule);
useVcs.setState({ available: true, root, repo: root, roots: [root], branch });
const contextModule = "/src/platform/context.ts";
const { setContext } = await import(/* @vite-ignore */ contextModule);
setContext("vcsAvailable", true);
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("vcs.stash");
},
{ root, head },
);
const dialog = page.getByRole("dialog", { name: "Stash", exact: true });
await expect(dialog.getByText(`Current branch: ${head}`)).toBeVisible();
const body = dialog.locator("[data-dialog-body]");
expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0);
const message = dialog.getByRole("textbox", { name: "Message", exact: true });
await expect(message).toBeFocused();
await message.fill("Set aside settlement work");
await message.press("End");
await message.press("Enter");
await expect(message).toHaveValue("Set aside settlement work\n");
await message.pressSequentially("Continue after the release.");
expect(await ipcCalls(page, "vcs_stash_push")).toEqual([]);
await dialog.getByRole("checkbox", { name: "Keep index" }).check();
await dialog.getByRole("checkbox", { name: "Include untracked files" }).check();
await message.press("Control+Enter");
await expect(dialog).toBeHidden();
await expect
.poll(() => ipcCalls(page, "vcs_stash_push"))
.toEqual([
{
repo: root,
message: "Set aside settlement work\nContinue after the release.",
keepIndex: true,
includeUntracked: true,
paths: null,
},
]);
});
+30 -16
View File
@@ -1,5 +1,5 @@
/** Local change operations: commit, rollback, add, stash. */
import { useEffect, useState } from "react";
import { useEffect, useId, useState } from "react";
import type { FileStatus, Stash } from "@/bindings";
import { call, commands } from "@/platform/ipc";
import { Checkbox, Dialog, Icon, IconButton, Input, T, fileIconName } from "@/ui";
@@ -367,7 +367,9 @@ function StashDialog({
const [message, setMessage] = useState("");
const [keepIndex, setKeepIndex] = useState(false);
const [includeUntracked, setIncludeUntracked] = useState(false);
const showRepo = useVcs((s) => pickRepo && s.roots.length > 1);
const branch = useBranchInfo(repo)?.head ?? null;
const messageId = useId();
const submit = () => onDone({ repo, message: message.trim(), keepIndex, includeUntracked });
return (
<Dialog
@@ -381,26 +383,38 @@ function StashDialog({
]}
>
<form
className={styles.form}
className={`${styles.form} ${styles.stashForm}`}
onSubmit={(e) => {
e.preventDefault();
submit();
}}
>
{pickRepo && <RepoPicker repo={repo} onChange={setRepo} />}
{branch && <div className={styles.hint}>{tx`Current branch: ${branch}`}</div>}
<label className={styles.fieldLabel}>
<T>Message:</T>
</label>
<Input
data-autofocus
aria-label="Message"
placeholder="WIP"
value={message}
onChange={(e) => setMessage(e.target.value)}
/>
<Checkbox checked={keepIndex} onChange={setKeepIndex} label="Keep index" />
<Checkbox checked={includeUntracked} onChange={setIncludeUntracked} label="Include untracked files" />
{showRepo && (
<div className={styles.stashRepo}>
<T>Repository:</T>
<RepoPicker repo={repo} onChange={setRepo} />
</div>
)}
{branch && <div className={styles.stashBranch}>{tx`Current branch: ${branch}`}</div>}
<div className={styles.stashMessage}>
<label htmlFor={messageId}>
<T>Message:</T>
</label>
<textarea
id={messageId}
className={styles.textarea}
data-autofocus
aria-label={tx("Message")}
placeholder={tx("WIP")}
rows={3}
value={message}
onChange={(e) => setMessage(e.target.value)}
/>
</div>
<div className={styles.stashOptions}>
<Checkbox checked={keepIndex} onChange={setKeepIndex} label="Keep index" />
<Checkbox checked={includeUntracked} onChange={setIncludeUntracked} label="Include untracked files" />
</div>
</form>
</Dialog>
);
+38
View File
@@ -402,6 +402,44 @@
outline: none;
border-color: var(--focus-ring);
}
.stashForm {
gap: var(--space-3);
padding: var(--space-4);
font-size: var(--fs-ui);
}
.stashRepo {
display: flex;
align-items: center;
gap: var(--space-2);
color: var(--fg-secondary);
}
.stashRepo > button {
flex: 1;
}
.stashBranch {
color: var(--fg-secondary);
line-height: 1.5;
overflow-wrap: anywhere;
}
.stashMessage {
display: flex;
flex-direction: column;
gap: var(--space-1-5);
}
.stashMessage > label {
color: var(--fg-strong);
font-weight: 600;
}
.stashMessage > textarea {
min-width: 0;
padding: var(--space-2);
line-height: 1.5;
}
.stashOptions {
display: flex;
flex-wrap: wrap;
gap: var(--space-2) var(--space-4);
}
/* Interactive rebase dialog. */
.rebaseList {
max-height: 360px;