diff --git a/e2e/rollbackDialogLayout.spec.ts b/e2e/rollbackDialogLayout.spec.ts new file mode 100644 index 000000000..305462653 --- /dev/null +++ b/e2e/rollbackDialogLayout.spec.ts @@ -0,0 +1,74 @@ +import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; + +test("Rollback fits a short window and scopes its options to checked files", async ({ workbench: page }) => { + await page.setViewportSize({ width: 410, height: 330 }); + await stubDesktop(page); + const root = "/dev/settlement-engine"; + const added = `${root}/ledger/additional-settlement-schedule.txt`; + const deleted = `${root}/ledger/retired-settlement-routing.txt`; + const modified = Array.from({ length: 16 }, (_, i) => `${root}/ledger/merchant-settlement-batch-${i + 1}.txt`); + + await page.evaluate( + async ({ root, added, deleted, modified }) => { + const status = [ + { path: added, staged: "added", unstaged: null }, + { path: deleted, staged: "deleted", unstaged: null }, + ...modified.map((path) => ({ path, staged: null, unstaged: "modified" })), + ].map((file) => ({ ...file, relPath: file.path.slice(root.length + 1), renamedFrom: null })); + const branch = { head: "main", 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 = () => status; + h.vcs_unstage = () => null; + h.vcs_discard = () => 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, status }); + 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.rollback", [root]); + }, + { root, added, deleted, modified }, + ); + + const dialog = page.getByRole("dialog", { name: "Rollback Changes", exact: true }); + const tree = dialog.getByRole("tree", { name: "Files to roll back" }); + const body = dialog.locator("[data-dialog-body]"); + await expect(tree).toBeVisible(); + expect(await body.evaluate((el) => el.scrollHeight - el.clientHeight)).toBeLessThanOrEqual(1); + expect(await body.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0); + expect(await tree.evaluate((el) => el.scrollHeight > el.clientHeight)).toBe(true); + await expect(tree).toBeFocused(); + await expect(tree.getByTitle("ledger/additional-settlement-schedule.txt", { exact: true })).toBeVisible(); + + const status = dialog.getByRole("status"); + const deleteCopies = dialog.getByRole("checkbox", { name: "Delete local copies of added files" }); + const rollback = dialog.getByRole("button", { name: "Rollback", exact: true }); + await expect(status).toHaveText("1 added16 modified1 deleted"); + await expect(deleteCopies).toBeEnabled(); + await expect(deleteCopies).not.toBeChecked(); + await deleteCopies.check(); + await tree.getByRole("checkbox", { name: "Include additional-settlement-schedule.txt" }).uncheck(); + await expect(deleteCopies).toBeDisabled(); + await expect(status).toHaveText("16 modified1 deleted"); + + const rootCheckbox = tree.getByRole("checkbox", { name: "Include settlement-engine", exact: true }); + await expect(rootCheckbox).toHaveAttribute("aria-checked", "mixed"); + await rootCheckbox.click(); + await rootCheckbox.uncheck(); + await expect(rollback).toBeDisabled(); + await expect(status).toHaveText("No files selected"); + + await tree.getByRole("checkbox", { name: "Include merchant-settlement-batch-1.txt", exact: true }).check(); + await expect(status).toHaveText("1 modified"); + await expect(deleteCopies).toBeDisabled(); + await rollback.click(); + await expect(dialog).toBeHidden(); + await expect.poll(() => ipcCalls(page, "vcs_discard")).toEqual([{ paths: [modified[0]] }]); + expect(await ipcCalls(page, "vcs_unstage")).toEqual([]); +}); diff --git a/src/features/vcs/RollbackDialog.module.css b/src/features/vcs/RollbackDialog.module.css new file mode 100644 index 000000000..6b0cc971a --- /dev/null +++ b/src/features/vcs/RollbackDialog.module.css @@ -0,0 +1,46 @@ +.dialog [data-dialog-body] { + display: flex; + flex-direction: column; +} + +.content { + display: flex; + flex: 1; + flex-direction: column; + gap: var(--space-2); + min-height: 0; + padding: var(--space-2) var(--space-4) 0; + font-size: var(--fs-ui); +} + +.content .tree { + flex: 1 1 260px; + height: auto; + min-height: var(--h-row); + margin: 0; +} + +.summary { + display: flex; + flex-wrap: wrap; + gap: var(--space-1) var(--space-3); + color: var(--fg-subtle); +} + +.added { + color: var(--vcs-added); +} + +.modified { + color: var(--vcs-modified); +} + +.deleted { + color: var(--vcs-deleted); +} + +.warning { + margin: 0; + color: var(--fg-subtle); + font-size: var(--fs-small); +} diff --git a/src/features/vcs/changeOps.tsx b/src/features/vcs/changeOps.tsx index 6928a95a9..5d62aec55 100644 --- a/src/features/vcs/changeOps.tsx +++ b/src/features/vcs/changeOps.tsx @@ -19,6 +19,7 @@ import { showCompareRevisions } from "./operations"; import { FileChecklist } from "./shelf"; import { currentRepo, loadStashes, refreshNow, useVcs } from "./store"; import styles from "./common.module.css"; +import rollbackStyles from "./RollbackDialog.module.css"; import { tx } from "@/platform/i18n"; export function firstLine(message: string): string { @@ -219,9 +220,14 @@ export function showRollbackDialog(files: FileStatus[]) { function RollbackDialog({ files, onClose }: { files: FileStatus[]; onClose: () => void }) { const [selected, setSelected] = useState(() => new Set(files.map((f) => f.path))); const [deleteAdded, setDeleteAdded] = useState(false); - const hasAdded = files.some((f) => f.staged === "added"); + const chosen = files.filter((f) => selected.has(f.path)); + const counts = { added: 0, modified: 0, deleted: 0 }; + for (const file of chosen) { + const kind = effectiveKind(file); + counts[kind === "added" || kind === "deleted" ? kind : "modified"]++; + } + const { added, modified, deleted } = counts; const run = async () => { - const chosen = files.filter((f) => selected.has(f.path)); onClose(); if (!chosen.length) return; await saveAll(); @@ -240,24 +246,40 @@ function RollbackDialog({ files, onClose }: { files: FileStatus[]; onClose: () = open title="Rollback Changes" onClose={onClose} - width={520} - footerStart={ - hasAdded && ( - - ) - } + className={rollbackStyles.dialog} + width={540} + minWidth={320} + minHeight={240} + resizable="both" buttons={[ - { label: "Rollback", role: "default", autoFocus: true, disabled: !selected.size, onClick: () => void run() }, - { label: "Cancel", role: "cancel" }, + { label: "Rollback", role: "default", disabled: !chosen.length, onClick: () => void run() }, + { label: "Close", role: "cancel" }, ]} > -
- {files.length === 1 - ? tx`${selected.size} of ${files.length} file will be reverted to their last committed state. Uncommitted changes are lost.` - : tx`${selected.size} of ${files.length} files will be reverted to their last committed state. Uncommitted changes are lost.`} +
+ +
+ {!chosen.length && No files selected} + {added > 0 && {tx`${added} added`}} + {modified > 0 && {tx`${modified} modified`}} + {deleted > 0 && {tx`${deleted} deleted`}} +
+ 0 && deleteAdded} + disabled={!added} + onChange={setDeleteAdded} + label="Delete local copies of added files" + /> +

+ Rollback discards uncommitted changes in the selected files. +

- -
); } diff --git a/src/features/vcs/shelf.tsx b/src/features/vcs/shelf.tsx index 67ddb6d00..283984fe8 100644 --- a/src/features/vcs/shelf.tsx +++ b/src/features/vcs/shelf.tsx @@ -5,6 +5,7 @@ */ import { writeClipboardText } from "@/platform/clipboard"; import { useEffect, useLayoutEffect, useMemo, useRef, useState, type MouseEvent } from "react"; +import clsx from "clsx"; import { create } from "zustand"; import type { ApplyOutcome, @@ -184,6 +185,7 @@ function ChangeChecklist({ selected, onChange, label, + className, }: { files: readonly F[]; keyOf: (f: F) => string; @@ -195,6 +197,7 @@ function ChangeChecklist({ selected: ReadonlySet; onChange: (next: Set) => void; label: string; + className?: string; }) { const tree: FileTreeNode[] = [ { key: "r:", name: rootName, file: null, children: buildFileTree(files, relPath), count: files.length }, @@ -211,7 +214,7 @@ function ChangeChecklist({ onChange(next); }; return ( -
+
> roots={tree} getKey={(n) => n.key} @@ -226,6 +229,7 @@ function ChangeChecklist({ renderNode={(n) => { const below = filesBelow(n); const on = below.filter((f) => selected.has(keyOf(f))).length; + const path = n.file ? relPath(n.file) : undefined; return ( ({ indeterminate={on > 0 && on < below.length} onChange={() => toggle(n)} /> - - + + {n.name} {n.file ? (detailOf?.(n.file) ?? "") : fileCount(n.count)} @@ -254,11 +258,13 @@ export function FileChecklist({ selected, onChange, label, + className, }: { files: readonly FileStatus[]; selected: ReadonlySet; onChange: (next: Set) => void; label: string; + className?: string; }) { const root = useVcs((s) => s.root) ?? ""; return ( @@ -271,6 +277,7 @@ export function FileChecklist({ selected={selected} onChange={onChange} label={label} + className={className} /> ); } diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json index ad5c372aa..3af72e6b9 100644 --- a/src/platform/locales/text/en.json +++ b/src/platform/locales/text/en.json @@ -1,4 +1,9 @@ { + "No files selected": "No files selected", + "{added} added": "{added} added", + "{modified} modified": "{modified} modified", + "{deleted} deleted": "{deleted} deleted", + "Rollback discards uncommitted changes in the selected files.": "Rollback discards uncommitted changes in the selected files.", "MCP server instructions": "MCP server instructions", "MCP tools (deferred)": "MCP tools (deferred)", "System tools (deferred)": "System tools (deferred)", diff --git a/src/platform/locales/text/es.json b/src/platform/locales/text/es.json index 3be34621f..422e66eb9 100644 --- a/src/platform/locales/text/es.json +++ b/src/platform/locales/text/es.json @@ -4466,8 +4466,6 @@ "No local history for this folder yet": "Aún no hay historial local para esta carpeta", "No local history for this path yet": "Aún no hay historial local para esta ruta", "{name} has been resolved and staged.": "{name} ha sido resuelto y preparado (staged).", - "{selected} of {total} file will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} de {total} archivo se revertirá a su último estado confirmado. Los cambios sin confirmar se perderán.", - "{selected} of {total} files will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} de {total} archivos se revertirán a su último estado confirmado. Los cambios sin confirmar se perderán.", "Current branch: {branch}": "Rama actual: {branch}", "{count} TODO item found in the changed lines:": "Se encontró {count} elemento TODO en las líneas modificadas:", "{count} TODO items found in the changed lines:": "Se encontraron {count} elementos TODO en las líneas modificadas:", diff --git a/src/platform/locales/text/fr.json b/src/platform/locales/text/fr.json index ae131a5bf..80127b16d 100644 --- a/src/platform/locales/text/fr.json +++ b/src/platform/locales/text/fr.json @@ -4322,8 +4322,6 @@ "No local history for this folder yet": "Aucun historique local pour ce dossier pour l'instant", "No local history for this path yet": "Aucun historique local pour ce chemin pour l'instant", "{name} has been resolved and staged.": "{name} a été résolu et indexé.", - "{selected} of {total} file will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} fichier sur {total} sera rétabli à son dernier état validé. Les modifications non validées seront perdues.", - "{selected} of {total} files will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} fichiers sur {total} seront rétablis à leur dernier état validé. Les modifications non validées seront perdues.", "Current branch: {branch}": "Branche actuelle : {branch}", "{count} TODO item found in the changed lines:": "{count} élément TODO trouvé dans les lignes modifiées :", "{count} TODO items found in the changed lines:": "{count} éléments TODO trouvés dans les lignes modifiées :", diff --git a/src/platform/locales/text/ko.json b/src/platform/locales/text/ko.json index 7b8b7d31a..8773aa6f9 100644 --- a/src/platform/locales/text/ko.json +++ b/src/platform/locales/text/ko.json @@ -4534,8 +4534,6 @@ "No local history for this folder yet": "이 폴더에 대한 로컬 기록이 아직 없습니다", "No local history for this path yet": "이 경로에 대한 로컬 기록이 아직 없습니다", "{name} has been resolved and staged.": "{name}이(가) 해결되어 스테이징되었습니다.", - "{selected} of {total} file will be reverted to their last committed state. Uncommitted changes are lost.": "파일 {total}개 중 {selected}개가 마지막으로 커밋된 상태로 되돌려집니다. 커밋되지 않은 변경 사항은 손실됩니다.", - "{selected} of {total} files will be reverted to their last committed state. Uncommitted changes are lost.": "파일 {total}개 중 {selected}개가 마지막으로 커밋된 상태로 되돌려집니다. 커밋되지 않은 변경 사항은 손실됩니다.", "Current branch: {branch}": "현재 브랜치: {branch}", "{count} TODO item found in the changed lines:": "변경된 줄에서 TODO 항목 {count}개가 발견되었습니다:", "{count} TODO items found in the changed lines:": "변경된 줄에서 TODO 항목 {count}개가 발견되었습니다:", diff --git a/src/platform/locales/text/pl.json b/src/platform/locales/text/pl.json index 632c87919..2771925af 100644 --- a/src/platform/locales/text/pl.json +++ b/src/platform/locales/text/pl.json @@ -4419,8 +4419,6 @@ "No local history for this folder yet": "Brak jeszcze historii lokalnej dla tego folderu", "No local history for this path yet": "Brak jeszcze historii lokalnej dla tej ścieżki", "{name} has been resolved and staged.": "Konflikt w {name} został rozwiązany i plik został dodany do poczekalni (staged).", - "{selected} of {total} file will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} z {total} pliku zostanie przywrócony do ostatnio zatwierdzonego stanu. Niezatwierdzone zmiany zostaną utracone.", - "{selected} of {total} files will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} z {total} plików zostanie przywróconych do ostatnio zatwierdzonego stanu. Niezatwierdzone zmiany zostaną utracone.", "Current branch: {branch}": "Bieżąca gałąź: {branch}", "{count} TODO item found in the changed lines:": "Znaleziono element TODO ({count}) w zmienionych wierszach:", "{count} TODO items found in the changed lines:": "Znaleziono elementy TODO ({count}) w zmienionych wierszach:", diff --git a/src/platform/locales/text/pt.json b/src/platform/locales/text/pt.json index 5088f890a..48098afcd 100644 --- a/src/platform/locales/text/pt.json +++ b/src/platform/locales/text/pt.json @@ -4432,8 +4432,6 @@ "No local history for this folder yet": "Ainda não há histórico local para esta pasta", "No local history for this path yet": "Ainda não há histórico local para este caminho", "{name} has been resolved and staged.": "{name} foi resolvido e preparado no stage.", - "{selected} of {total} file will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} de {total} arquivo será revertido para o seu último estado comitado. Alterações não comitadas serão perdidas.", - "{selected} of {total} files will be reverted to their last committed state. Uncommitted changes are lost.": "{selected} de {total} arquivos serão revertidos para o seu último estado comitado. Alterações não comitadas serão perdidas.", "Current branch: {branch}": "Branch atual: {branch}", "{count} TODO item found in the changed lines:": "{count} item de TODO encontrado nas linhas alteradas:", "{count} TODO items found in the changed lines:": "{count} itens de TODO encontrados nas linhas alteradas:", diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json index 16c9de23b..86ca3840e 100644 --- a/src/platform/locales/text/zh.json +++ b/src/platform/locales/text/zh.json @@ -1298,6 +1298,11 @@ "Delete Shelved Changes": "删除已搁置的更改", "Delete all rows of": "删除以下表的所有行:", "Delete local copies of added files": "删除已添加文件的本地副本", + "No files selected": "未选择文件", + "{added} added": "新增 {added} 个", + "{modified} modified": "修改 {modified} 个", + "{deleted} deleted": "删除 {deleted} 个", + "Rollback discards uncommitted changes in the selected files.": "回滚将丢弃所选文件中未提交的更改。", "Deleted": "已删除", "Delete…": "删除…", "Description": "描述", @@ -5392,8 +5397,6 @@ "No local history for this folder yet": "此文件夹尚无本地历史记录", "No local history for this path yet": "此路径尚无本地历史记录", "{name} has been resolved and staged.": "{name} 已解决并暂存。", - "{selected} of {total} file will be reverted to their last committed state. Uncommitted changes are lost.": "{selected}/{total} 个文件将还原到其最后一次提交的状态。未提交的更改将丢失。", - "{selected} of {total} files will be reverted to their last committed state. Uncommitted changes are lost.": "{selected}/{total} 个文件将还原到其最后一次提交的状态。未提交的更改将丢失。", "Current branch: {branch}": "当前分支:{branch}", "{count} TODO item found in the changed lines:": "在更改的行中发现 {count} 个 TODO 项:", "{count} TODO items found in the changed lines:": "在更改的行中发现 {count} 个 TODO 项:",