refactor: extract components

This commit is contained in:
tao.chen
2026-08-07 17:38:28 +08:00
parent 873a464629
commit e2615be2e8
4 changed files with 529 additions and 112 deletions
+34 -1
View File
@@ -1,4 +1,10 @@
import { type Schedule, type ScheduleArtifact, type ScheduleNode } from "../../services/api";
import {
type Schedule,
type ScheduleArtifact,
type ScheduleNode,
type ScheduleNodeRun,
type ScheduleRunSummary,
} from "../../services/api";
import { EMPTY_SCHEDULE_FORM, EMPTY_NODE_FORM } from "./constants";
export function formatTime(value: string | null): string {
@@ -23,6 +29,33 @@ export function formatDuration(value: number | null): string {
return `${Math.floor(value / 60_000)}m ${Math.round((value % 60_000) / 1000)}s`;
}
export function formatSize(value: number): string {
if (value < 1024) return `${value} B`;
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`;
return `${(value / 1024 / 1024).toFixed(1)} MB`;
}
export const RUN_STATUS_LABELS: Record<ScheduleRunSummary["run_status"], string> = {
queued: "排队中",
running: "运行中",
succeeded: "成功",
failed: "失败",
cancelled: "已取消",
timed_out: "已超时",
};
export const NODE_STATUS_LABELS: Record<ScheduleNodeRun["node_status"], string> = {
...RUN_STATUS_LABELS,
skipped: "已跳过",
};
export const TRIGGER_TYPE_LABELS: Record<ScheduleRunSummary["trigger_type"], string> = {
manual: "手动触发",
cron: "Cron 定时",
api: "API 触发",
retry: "失败重试",
};
export function parseObject(text: string, label: string): Record<string, unknown> {
let value: unknown;
try {