Use schedule checkbox for biz-state; add compare job delete action.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-17 19:11:50 +08:00
parent 108c9da00f
commit e9b8042ca7
5 changed files with 109 additions and 60 deletions

View file

@ -183,12 +183,16 @@ const en = {
colConnect: "Connect",
start: "Start schedule",
pause: "Pause",
scheduleEnabled: "Enable schedule",
scheduleOn: "Scheduled",
scheduleOff: "Manual",
scheduleHint: "When checked, collect on interval; otherwise only Collect now.",
collectNow: "Collect now",
delete: "Delete",
confirmDelete: "Delete this task and all batches?",
deleted: "Deleted",
started: "Schedule started",
paused: "Paused",
started: "Schedule enabled",
paused: "Schedule off (manual only)",
collecting: "Collecting",
detail: "Details",
interval: "Interval",
@ -244,6 +248,7 @@ const en = {
templateSaved: "Template saved",
templateDeleted: "Template deleted",
confirmDeleteTemplate: "Delete this compare template?",
confirmDeleteJob: "Delete this compare job and all runs?",
emptyTemplates: "No templates yet. Create one or use built-ins.",
templateHint:
"A template holds multiple metric sheets. Key: row identity (no separate compare). Interface: port mapping. Compare: value checks after key match. Leave compare empty for presence-only (entry set match).",
@ -296,6 +301,7 @@ const en = {
runNow: "Run now",
saveJob: "Save config",
jobSaved: "Job config saved",
jobDeleted: "Compare job deleted",
jobList: "Compare jobs",
detail: "Details",
edit: "Edit",

View file

@ -183,12 +183,16 @@ const zh = {
colConnect: "连通",
start: "启动周期",
pause: "暂停",
scheduleEnabled: "启用周期调度",
scheduleOn: "周期",
scheduleOff: "手动",
scheduleHint: "勾选后按周期自动采集;不勾选则仅支持「立即采集」。",
collectNow: "立即采集",
delete: "删除",
confirmDelete: "删除该业务监控任务及所有批次?",
deleted: "已删除",
started: "已启动周期采集",
paused: "已暂停",
started: "已启用周期采集",
paused: "已关闭周期(仅手动采集)",
collecting: "采集中",
detail: "详情",
interval: "采集周期",
@ -244,6 +248,7 @@ const zh = {
templateSaved: "模板已保存",
templateDeleted: "模板已删除",
confirmDeleteTemplate: "删除该比对模板?",
confirmDeleteJob: "删除该比对任务及全部运行记录?",
emptyTemplates: "暂无模板。可新建或使用系统默认。",
templateHint:
"一个模板可包含多张监控表。Key:对齐前后条目(选中后即为行身份,无需再勾比对);接口:参与端口映射;比对:勾选具体参数做值检查。若不勾任何比对字段,则只校验条目是否一致(存在性)。",
@ -295,6 +300,7 @@ const zh = {
runNow: "立即比对",
saveJob: "保存配置",
jobSaved: "任务配置已保存",
jobDeleted: "比对任务已删除",
jobList: "比对任务",
detail: "详情",
edit: "编辑",

View file

@ -9,6 +9,7 @@ import {
bizCompareCreateJob,
bizCompareCreateMapping,
bizCompareCreateTemplate,
bizCompareDeleteJob,
bizCompareDeleteTemplate,
bizCompareGetRun,
bizCompareListJobs,
@ -471,6 +472,21 @@ export function BizComparePage() {
}
};
const removeJob = async (id: string) => {
if (!window.confirm(t("bizCompare.confirmDeleteJob"))) return;
setBusy(true);
try {
await bizCompareDeleteJob(id);
if (jobId === id) closeJob();
showOk(t("bizCompare.jobDeleted"));
await refresh();
} catch (e) {
showError(formatErr(e));
} finally {
setBusy(false);
}
};
const parseMapRows = () => {
const rows: { before_if: string; after_if: string }[] = [];
for (const line of mapText.split(/\r?\n/)) {
@ -945,6 +961,14 @@ export function BizComparePage() {
<Button size="sm" variant="primary" onPress={() => void openJob(j.id)}>
{t("bizCompare.detail")}
</Button>
<Button
size="sm"
variant="danger"
isDisabled={busy}
onPress={() => void removeJob(j.id)}
>
{t("bizCompare.delete")}
</Button>
</div>
</td>
</tr>
@ -1409,6 +1433,11 @@ export function BizComparePage() {
<Button size="sm" variant="ghost" onPress={closeJob}>
{t("bizState.cancel")}
</Button>
{jobId ? (
<Button size="sm" variant="danger" isDisabled={busy} onPress={() => void removeJob(jobId)}>
{t("bizCompare.delete")}
</Button>
) : null}
</Modal.Footer>
</AppModalShell>
</section>

View file

@ -397,13 +397,12 @@ export function BizStatePage() {
}
};
const setStatus = async (status: string) => {
if (!taskId) return;
const setScheduleEnabled = async (id: string, enabled: boolean) => {
setBusy(true);
try {
await bizStatePatchTask(taskId, { status });
showOk(status === "running" ? t("bizState.started") : t("bizState.paused"));
await loadTask(taskId);
await bizStatePatchTask(id, { status: enabled ? "running" : "paused" });
showOk(enabled ? t("bizState.started") : t("bizState.paused"));
if (taskId === id) await loadTask(id);
await refreshTasks();
} catch (e) {
showError(formatErr(e));
@ -593,7 +592,7 @@ export function BizStatePage() {
<div className="pt-list-kpi__value">{tasks.length}</div>
</div>
<div className="pt-list-kpi pt-list-kpi--live">
<div className="pt-list-kpi__label">{t("bizState.start")}</div>
<div className="pt-list-kpi__label">{t("bizState.scheduleOn")}</div>
<div className="pt-list-kpi__value">{runningCount}</div>
</div>
</div>
@ -613,6 +612,7 @@ export function BizStatePage() {
<th>{t("bizState.colNe")}</th>
<th>{t("bizState.colSource")}</th>
<th>{t("bizState.colInterval")}</th>
<th>{t("bizState.scheduleEnabled")}</th>
<th>{t("bizState.colStatus")}</th>
<th>{t("bizState.colLast")}</th>
<th>{t("bizState.colActions")}</th>
@ -641,12 +641,28 @@ export function BizStatePage() {
t("bizState.intervalUnitSeconds"),
)}
</td>
<td>
<label className="config-sync-policy-check">
<input
type="checkbox"
checked={row.status === "running"}
disabled={busy}
onChange={(e) => void setScheduleEnabled(row.id, e.target.checked)}
/>
<span>
{row.status === "running" ? t("bizState.scheduleOn") : t("bizState.scheduleOff")}
</span>
</label>
</td>
<td>
<div className="pt-list-actions" style={{ flexWrap: "wrap", gap: 4 }}>
<NmStatusChip color={jobChipColor(row.status)}>{row.status}</NmStatusChip>
{row.collect_running ? (
<NmStatusChip color="accent">{t("bizState.collecting")}</NmStatusChip>
) : null}
) : (
<NmStatusChip color={row.status === "running" ? "success" : "default"}>
{row.status === "running" ? t("bizState.scheduleOn") : t("bizState.scheduleOff")}
</NmStatusChip>
)}
</div>
</td>
<td className="pt-list-time">{fmtTime(row.last_collect_ended_at)}</td>
@ -658,47 +674,33 @@ export function BizStatePage() {
<Button size="sm" variant="ghost" onPress={() => void openTask(row.id, "batches")}>
{t("bizState.batches")}
</Button>
{row.status !== "running" ? (
<Button
size="sm"
variant="ghost"
isDisabled={busy}
onPress={async () => {
setBusy(true);
try {
await bizStatePatchTask(row.id, { status: "running" });
showOk(t("bizState.started"));
<Button
size="sm"
variant="secondary"
isDisabled={busy || row.collect_running}
onPress={async () => {
setBusy(true);
try {
await bizStateCollectNow(row.id);
showOk(t("bizState.collecting"));
for (let i = 0; i < 20; i++) {
await new Promise((r) => setTimeout(r, 1500));
await refreshTasks();
} catch (e) {
showError(formatErr(e));
} finally {
setBusy(false);
const cur = (await bizStateListTasks()).items?.find(
(x: any) => x.id === row.id,
);
if (!cur?.collect_running) break;
}
}}
>
{t("bizState.start")}
</Button>
) : (
<Button
size="sm"
variant="ghost"
isDisabled={busy}
onPress={async () => {
setBusy(true);
try {
await bizStatePatchTask(row.id, { status: "paused" });
showOk(t("bizState.paused"));
await refreshTasks();
} catch (e) {
showError(formatErr(e));
} finally {
setBusy(false);
}
}}
>
{t("bizState.pause")}
</Button>
)}
await refreshTasks();
} catch (e) {
showError(formatErr(e));
} finally {
setBusy(false);
}
}}
>
{t("bizState.collectNow")}
</Button>
<Button
size="sm"
variant="danger"
@ -713,7 +715,7 @@ export function BizStatePage() {
))}
{!filteredTasks.length ? (
<tr>
<td colSpan={6}>
<td colSpan={7}>
<div className="pt-list-empty">{t("bizState.empty")}</div>
</td>
</tr>
@ -846,6 +848,15 @@ export function BizStatePage() {
<Modal.Body className="flex flex-col gap-3">
{detail ? (
<div className="config-sync-policy-row bs-schedule-row">
<label className="config-sync-policy-check">
<input
type="checkbox"
checked={detail.status === "running"}
disabled={busy}
onChange={(e) => void setScheduleEnabled(taskId, e.target.checked)}
/>
<span>{t("bizState.scheduleEnabled")}</span>
</label>
<label className="config-sync-policy-field">
<span>{t("bizState.interval")}</span>
<Input
@ -892,7 +903,7 @@ export function BizStatePage() {
{t("bizState.saveSchedule")}
</Button>
<span className="muted">
{detail.vendor || "—"} · {detail.ne_ip || "—"}
{detail.vendor || "—"} · {detail.ne_ip || "—"} · {t("bizState.scheduleHint")}
</span>
</div>
) : null}
@ -1075,13 +1086,7 @@ export function BizStatePage() {
)}
</Modal.Body>
<Modal.Footer>
<Button size="sm" variant="primary" isDisabled={busy} onPress={() => void setStatus("running")}>
{t("bizState.start")}
</Button>
<Button size="sm" variant="secondary" isDisabled={busy} onPress={() => void setStatus("paused")}>
{t("bizState.pause")}
</Button>
<Button size="sm" variant="secondary" isDisabled={busy} onPress={() => void collectNow()}>
<Button size="sm" variant="primary" isDisabled={busy} onPress={() => void collectNow()}>
{t("bizState.collectNow")}
</Button>
<Button size="sm" variant="danger" isDisabled={busy} onPress={() => void removeTask(taskId)}>

View file

@ -1895,6 +1895,9 @@ export const bizCompareUpdateJob = (jobId: string, body: Record<string, unknown>
body,
);
export const bizCompareDeleteJob = (jobId: string) =>
apiDelete<{ ok: boolean }>(`/v1/biz-state/compare/jobs/${encodeURIComponent(jobId)}`);
export const bizCompareRunJob = (jobId: string) =>
apiPost<Record<string, unknown>>(
`/v1/biz-state/compare/jobs/${encodeURIComponent(jobId)}/run`,