✨ Show per-project and fixed batch cleanup progress bars
This commit is contained in:
parent
886ad9edde
commit
fa8248d359
@ -41,6 +41,11 @@ closing the dialog does not cancel admitted cleanup. A retry of the same selecti
|
||||
reuses existing task IDs, and completed projects are not deleted again. Deletion
|
||||
history remains the recovery entry after a lost response or API interruption.
|
||||
|
||||
Each project's cleanup count has a progress bar, and the batch footer keeps the
|
||||
overall step progress visible while scrolling long manifests. Percentages use
|
||||
completed targets divided by all targets, not bytes or elapsed time. Failed tasks
|
||||
retain their completed steps; 100% requires the final completed task status.
|
||||
|
||||
Batch validation includes partial failure, cross-organization rejection, duplicate
|
||||
selection, admin role checks, repeat requests, and isolated browser checks of
|
||||
three projects followed by retrying only the failed one.
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { DeletionProgressBar } from "./DeletionProgressBar";
|
||||
import { projectDeletionsApi, type DeletionPlan, type DeletionTask } from "../services/api/project-deletions";
|
||||
import { getActionErrorMessage } from "../lib/action-errors.js";
|
||||
|
||||
@ -233,10 +234,9 @@ export function BatchProjectDeletionDialog({
|
||||
))}
|
||||
</details>
|
||||
{!!row.task && (
|
||||
<p className="mt-2 text-sm">
|
||||
清理步骤:{row.plan.targets.filter((t) => t.status === "done").length} /{" "}
|
||||
{row.plan.targets.length}
|
||||
</p>
|
||||
<div className="mt-3">
|
||||
<DeletionProgressBar rows={[row]} label={`${row.plan.projectName} 清理进度`} />
|
||||
</div>
|
||||
)}
|
||||
{row.plan.blockers.map((text, i) => (
|
||||
<p role="alert" key={i} className="break-words text-red-600">
|
||||
@ -274,6 +274,14 @@ export function BatchProjectDeletionDialog({
|
||||
)}
|
||||
</div>
|
||||
<footer className="flex flex-wrap items-center justify-between gap-3 border-t border-[color:var(--app-border)] p-4">
|
||||
{!incomplete && rows.some((row) => row.task) && (
|
||||
<div className="w-full">
|
||||
<DeletionProgressBar rows={rows} label="总体清理进度" />
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
按已完成清理步骤统计;单步耗时不同,不代表文件大小或剩余时间。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<p className="text-sm text-slate-500">已启动的删除不会因关闭窗口取消,可在“删除记录”查看。</p>
|
||||
{candidates.length > 0 && (
|
||||
<button
|
||||
|
||||
36
src/components/DeletionProgressBar.tsx
Normal file
36
src/components/DeletionProgressBar.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
import { deletionProgress } from "../lib/deletion-progress.js";
|
||||
import type { DeletionPlan, DeletionTask } from "../services/api/project-deletions";
|
||||
|
||||
export function DeletionProgressBar({
|
||||
rows,
|
||||
label,
|
||||
}: {
|
||||
rows: { plan?: DeletionPlan; task?: DeletionTask; error?: string }[];
|
||||
label: string;
|
||||
}) {
|
||||
const progress = deletionProgress(rows);
|
||||
return (
|
||||
<div className="min-w-0 w-full space-y-1.5">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-sm">
|
||||
<span>
|
||||
{label}:{progress.done} / {progress.total} 步骤{progress.failed ? " · 有项目未完成" : ""}
|
||||
</span>
|
||||
<span className="tabular-nums font-semibold">{progress.percent}%</span>
|
||||
</div>
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label={label}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={progress.percent}
|
||||
aria-valuetext={`已完成 ${progress.done} / ${progress.total} 个清理步骤,${progress.percent}%${progress.failed ? ",有项目未完成" : ""}`}
|
||||
className="h-2.5 overflow-hidden rounded-full bg-slate-200 dark:bg-slate-700"
|
||||
>
|
||||
<div
|
||||
style={{ width: `${progress.percent}%` }}
|
||||
className={`h-full rounded-full transition-[width] duration-300 motion-reduce:transition-none ${progress.complete ? "bg-emerald-500" : progress.failed ? "bg-red-500" : "bg-blue-500"}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
11
src/lib/deletion-progress.js
Normal file
11
src/lib/deletion-progress.js
Normal file
@ -0,0 +1,11 @@
|
||||
// Steps are equally weighted. This is not a byte/file transfer estimate.
|
||||
export function deletionProgress(rows = []) {
|
||||
const targets = rows.flatMap((row) => row.plan?.targets || []);
|
||||
const done = targets.filter((target) => target.status === "done").length;
|
||||
const total = targets.length;
|
||||
const complete = rows.length > 0 && rows.every((row) => row.task?.status === "completed");
|
||||
const failed = rows.some((row) => row.error || ["failed", "interrupted"].includes(row.task?.status));
|
||||
// The last receipt may arrive before the task's final completion record.
|
||||
const percent = complete ? 100 : total ? Math.min(99, Math.round((done / total) * 100)) : 0;
|
||||
return { done, total, percent, complete, failed };
|
||||
}
|
||||
24
tests/frontend/deletion-progress.test.mjs
Normal file
24
tests/frontend/deletion-progress.test.mjs
Normal file
@ -0,0 +1,24 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { deletionProgress } from "../../src/lib/deletion-progress.js";
|
||||
const row = (done, total, status = "running") => ({
|
||||
plan: { targets: Array.from({ length: total }, (_, i) => ({ status: i < done ? "done" : "pending" })) },
|
||||
task: { status },
|
||||
});
|
||||
test("progress uses actual completed steps including the reported 9/26 case", () => {
|
||||
assert.equal(deletionProgress([row(9, 26)]).percent, 35);
|
||||
assert.equal(deletionProgress([row(9, 26), row(1, 1, "completed")]).done, 10);
|
||||
assert.equal(deletionProgress([row(9, 26), row(1, 1, "completed")]).total, 27);
|
||||
});
|
||||
test("failure does not fabricate completion and final receipt is required for 100 percent", () => {
|
||||
assert.deepEqual(deletionProgress([row(9, 26, "failed")]), {
|
||||
done: 9,
|
||||
total: 26,
|
||||
percent: 35,
|
||||
complete: false,
|
||||
failed: true,
|
||||
});
|
||||
assert.equal(deletionProgress([row(26, 26)]).percent, 99);
|
||||
assert.equal(deletionProgress([row(26, 26, "completed")]).percent, 100);
|
||||
assert.equal(deletionProgress([]).percent, 0);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user