mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
Align the Rollback Changes dialog (#4770)
The Rollback Changes dialog gets a consistent layout with a change summary and an explanation of what rollback discards.
This commit is contained in:
@@ -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([]);
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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 && (
|
||||
<Checkbox checked={deleteAdded} onChange={setDeleteAdded} label="Delete local copies of added files" />
|
||||
)
|
||||
}
|
||||
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" },
|
||||
]}
|
||||
>
|
||||
<div className={styles.section}>
|
||||
{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.`}
|
||||
<div className={rollbackStyles.content}>
|
||||
<FileChecklist
|
||||
files={files}
|
||||
selected={selected}
|
||||
onChange={setSelected}
|
||||
label="Files to roll back"
|
||||
className={rollbackStyles.tree}
|
||||
/>
|
||||
<div className={rollbackStyles.summary} role="status">
|
||||
{!chosen.length && <T>No files selected</T>}
|
||||
{added > 0 && <span className={rollbackStyles.added}>{tx`${added} added`}</span>}
|
||||
{modified > 0 && <span className={rollbackStyles.modified}>{tx`${modified} modified`}</span>}
|
||||
{deleted > 0 && <span className={rollbackStyles.deleted}>{tx`${deleted} deleted`}</span>}
|
||||
</div>
|
||||
<Checkbox
|
||||
checked={added > 0 && deleteAdded}
|
||||
disabled={!added}
|
||||
onChange={setDeleteAdded}
|
||||
label="Delete local copies of added files"
|
||||
/>
|
||||
<p className={rollbackStyles.warning}>
|
||||
<T>Rollback discards uncommitted changes in the selected files.</T>
|
||||
</p>
|
||||
</div>
|
||||
<FileChecklist files={files} selected={selected} onChange={setSelected} label="Files to roll back" />
|
||||
<div style={{ height: 12 }} />
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<F>({
|
||||
selected,
|
||||
onChange,
|
||||
label,
|
||||
className,
|
||||
}: {
|
||||
files: readonly F[];
|
||||
keyOf: (f: F) => string;
|
||||
@@ -195,6 +197,7 @@ function ChangeChecklist<F>({
|
||||
selected: ReadonlySet<string>;
|
||||
onChange: (next: Set<string>) => void;
|
||||
label: string;
|
||||
className?: string;
|
||||
}) {
|
||||
const tree: FileTreeNode<F>[] = [
|
||||
{ key: "r:", name: rootName, file: null, children: buildFileTree(files, relPath), count: files.length },
|
||||
@@ -211,7 +214,7 @@ function ChangeChecklist<F>({
|
||||
onChange(next);
|
||||
};
|
||||
return (
|
||||
<div className={styles.fileTree}>
|
||||
<div className={clsx(styles.fileTree, className)}>
|
||||
<Tree<FileTreeNode<F>>
|
||||
roots={tree}
|
||||
getKey={(n) => n.key}
|
||||
@@ -226,6 +229,7 @@ function ChangeChecklist<F>({
|
||||
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 (
|
||||
<span className={styles.fileTreeRow}>
|
||||
<Checkbox
|
||||
@@ -235,8 +239,8 @@ function ChangeChecklist<F>({
|
||||
indeterminate={on > 0 && on < below.length}
|
||||
onChange={() => toggle(n)}
|
||||
/>
|
||||
<Icon name={n.file ? fileIconName(n.name, relPath(n.file)) : "folder"} size={14} />
|
||||
<span className={styles.fileName} style={{ color: n.file ? colorOf(n.file) : undefined }}>
|
||||
<Icon name={path === undefined ? "folder" : fileIconName(n.name, path)} size={14} />
|
||||
<span className={styles.fileName} style={{ color: n.file ? colorOf(n.file) : undefined }} title={path}>
|
||||
{n.name}
|
||||
</span>
|
||||
<span className={styles.fileDir}>{n.file ? (detailOf?.(n.file) ?? "") : fileCount(n.count)}</span>
|
||||
@@ -254,11 +258,13 @@ export function FileChecklist({
|
||||
selected,
|
||||
onChange,
|
||||
label,
|
||||
className,
|
||||
}: {
|
||||
files: readonly FileStatus[];
|
||||
selected: ReadonlySet<string>;
|
||||
onChange: (next: Set<string>) => 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}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -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 :",
|
||||
|
||||
@@ -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}개가 발견되었습니다:",
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -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 项:",
|
||||
|
||||
Reference in New Issue
Block a user