"use client"; import { use } from "react"; import Link from "next/link"; import { ArrowLeft, Loader2, Repeat, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { usePipeline, usePipelineStatuses, useDeletePipeline } from "@/hooks/use-pipelines"; import { PipelineProgress } from "@/components/pipeline/pipeline-progress"; import { toast } from "sonner"; import { useRouter } from "next/navigation"; export default function PipelineDetailPage({ params, }: { params: Promise<{ id: string }>; }) { const { id: idStr } = use(params); const id = Number(idStr); const router = useRouter(); const { data, isLoading, error } = usePipeline(id); const { data: statuses } = usePipelineStatuses(); const deleteMutation = useDeletePipeline(); const status = (statuses ?? []).find((s) => s.pipeline_id === id) ?? null; function handleDelete() { deleteMutation.mutate(id, { onSuccess: () => { toast.success("Pipeline deleted"); router.push("/automations"); }, onError: (err) => toast.error(`Failed to delete: ${err.message}`), }); } if (isLoading) { return (
); } if (error || !data) { return (

Failed to load pipeline. It may have been deleted.

); } const { config, runs } = data; return (

{config.name}

{config.loop && ( )}
{config.description && (

{config.description}

)}
{/* Live progress */} {/* Stages overview */} Stages ({config.stages.length})
{config.stages.map((stage, idx) => (
Stage {idx + 1} {stage.name} {stage.character_steps.length} worker {stage.character_steps.length !== 1 && "s"}
{stage.character_steps.map((cs) => (
{cs.character_name}
{cs.strategy_type}
{cs.transition && (
Until: {cs.transition.type} {cs.transition.value != null && ` ${cs.transition.operator ?? ">="} ${cs.transition.value}`}
)}
))}
))}
{/* Run history */} {runs.length > 0 && ( Run History ({runs.length}) Run Status Stage Actions Started Stopped {runs.slice(0, 20).map((run) => ( #{run.id} {run.status} {run.current_stage_index + 1} {run.loop_count > 0 && ` (loop ${run.loop_count})`} {run.total_actions_count} {new Date(run.started_at).toLocaleString()} {run.stopped_at ? new Date(run.stopped_at).toLocaleString() : "\u2014"} ))}
)}
); }