feat(web): unified task stream with plan tab, task detail drawer and audit links (FE-1)
Tasks page merges engine runs (with W9-I business fields) into one stream: all / active / failed / plan tabs, filters for source, business kind, status and time; detail drawer with business summary, timeline, collapsed engine steps, cancel/retry and related audit links. The schedule board moves into the plan tab; card history jumps to the stream filtered by schedule key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
f8362a3f4c
commit
d8b9bd9662
10 files changed
+1189
-30
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { AssetOperation, DownloadTask, Task } from "@umt/contracts";
|
||||
import { ArrowLeft } from "lucide-react";
|
||||
import { Link, Navigate, useParams } from "react-router";
|
||||
import { Link, Navigate, useNavigate, useParams } from "react-router";
|
||||
import { z } from "zod";
|
||||
import { useEngineRun } from "~/api/engine.ts";
|
||||
import { apiParsed, isMissingEndpoint } from "~/api/parse.ts";
|
||||
import { DetailSection } from "~/components/console/detail-sheet.tsx";
|
||||
import { ErrorState, LoadingState } from "~/components/console/empty-state.tsx";
|
||||
@@ -10,11 +11,18 @@ import { consolePath } from "~/components/console/nav.ts";
|
||||
import { PageHeader } from "~/components/console/page-header.tsx";
|
||||
import type { StatusTone } from "~/components/console/status-badge.tsx";
|
||||
import { Timeline } from "~/components/console/timeline.tsx";
|
||||
import { TASK_KIND_LABEL, TaskActions, TaskStatusLine, TaskSummary } from "~/components/downloads/business-tasks.tsx";
|
||||
import {
|
||||
TASK_KIND_LABEL,
|
||||
TaskActions,
|
||||
TaskStatusLine as TaskStatusLine2,
|
||||
TaskSummary,
|
||||
} from "~/components/downloads/business-tasks.tsx";
|
||||
import { runTitle } from "~/components/tasks/labels.ts";
|
||||
import { RunActions, TaskDetailBody, TaskStatusLine } from "~/components/tasks/task-detail.tsx";
|
||||
import { Button } from "~/components/ui/button.tsx";
|
||||
import { TTL_SECOND } from "~/lib/api.ts";
|
||||
|
||||
export const meta = () => [{ title: "业务任务 · UHD 媒体自动化控制台" }];
|
||||
export const meta = () => [{ title: "任务 · UHD 媒体自动化控制台" }];
|
||||
|
||||
const OP_TONE: Record<AssetOperation["status"], StatusTone> = {
|
||||
planned: "neutral",
|
||||
@@ -59,8 +67,9 @@ const OP_KIND: Record<AssetOperation["kind"], string> = {
|
||||
other: "其他",
|
||||
};
|
||||
|
||||
function useTask(id: string) {
|
||||
function useTask(id: string, enabled: boolean) {
|
||||
return useQuery({
|
||||
enabled,
|
||||
queryKey: ["tasks", "one", id],
|
||||
retry: false,
|
||||
queryFn: ({ signal }) => apiParsed(Task, "/api/v1/tasks/:id", { pathParams: { id }, signal }),
|
||||
@@ -113,33 +122,74 @@ function Operations({ taskId }: { taskId: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
export default function BusinessTaskPage() {
|
||||
const back = (
|
||||
<Button asChild variant="ghost" size="sm">
|
||||
<Link to={consolePath("tasks")}>
|
||||
<ArrowLeft />
|
||||
任务
|
||||
</Link>
|
||||
</Button>
|
||||
);
|
||||
|
||||
/**
|
||||
* /console/tasks/:id:id 先当引擎运行查(统一任务);查不到再当旧的业务任务 ID
|
||||
* (有引擎运行就跳过去,没有就显示旧视图),最后当下载任务 ID 跳到下载详情。
|
||||
*/
|
||||
export default function TaskPage() {
|
||||
const { id = "" } = useParams();
|
||||
const task = useTask(id);
|
||||
const navigate = useNavigate();
|
||||
const run = useEngineRun(id);
|
||||
const runMissing = !!run.error && isMissingEndpoint(run.error);
|
||||
const task = useTask(id, runMissing);
|
||||
const notFound = !!task.error && isMissingEndpoint(task.error);
|
||||
const legacy = useLegacyDownload(id, notFound);
|
||||
|
||||
if (run.data) {
|
||||
const r = run.data;
|
||||
const open = (rid: string) => navigate(`/console/tasks/${encodeURIComponent(rid)}`);
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={runTitle(r)}
|
||||
description={<TaskStatusLine r={r} />}
|
||||
actions={
|
||||
<>
|
||||
{back}
|
||||
<RunActions r={r} onOpenRun={open} />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<div className="pg-slab space-y-5 rounded-xl p-4 md:p-5">
|
||||
<TaskDetailBody r={r} onOpenRun={open} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
if (run.error && !runMissing)
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="任务" actions={back} />
|
||||
<ErrorState error={run.error} onRetry={() => void run.refetch()} />
|
||||
</>
|
||||
);
|
||||
if (task.data?.engineRunId)
|
||||
return <Navigate to={`/console/tasks/${encodeURIComponent(task.data.engineRunId)}`} replace />;
|
||||
if (notFound && legacy.data) return <Navigate to={consolePath("downloads", id)} replace />;
|
||||
const t = task.data;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={t ? (TASK_KIND_LABEL[t.kind] ?? t.kind) : "业务任务"}
|
||||
description={t ? <TaskStatusLine t={t} /> : undefined}
|
||||
title={t ? (TASK_KIND_LABEL[t.kind] ?? t.kind) : "任务"}
|
||||
description={t ? <TaskStatusLine2 t={t} /> : undefined}
|
||||
actions={
|
||||
<>
|
||||
<Button asChild variant="ghost" size="sm">
|
||||
<Link to={consolePath("tasks")}>
|
||||
<ArrowLeft />
|
||||
业务任务
|
||||
</Link>
|
||||
</Button>
|
||||
{back}
|
||||
{t ? <TaskActions t={t} /> : null}
|
||||
</>
|
||||
}
|
||||
/>
|
||||
{task.isPending || (notFound && legacy.isPending) ? (
|
||||
{run.isPending || task.isPending || (notFound && legacy.isPending) ? (
|
||||
<div className="pg-slab rounded-xl p-4 md:p-5">
|
||||
<LoadingState rows={5} />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user