"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { api, type Connection, type Pipeline, type RunWithPipeline, } from "@/components/api"; import { StatusBadge } from "@/components/status-badge"; import { fmtTime, fmtDuration } from "@/components/format"; import { Card, CardContent, CardHeader, CardTitle, } from "@/components/ui/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; export default function DashboardPage() { const [connections, setConnections] = useState([]); const [pipelines, setPipelines] = useState([]); const [runs, setRuns] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { Promise.all([ api("/api/connections"), api("/api/pipelines"), api("/api/runs"), ]) .then(([c, p, r]) => { setConnections(c); setPipelines(p); setRuns(r); }) .catch((e) => setError(e instanceof Error ? e.message : "加载失败")) .finally(() => setLoading(false)); }, []); if (loading) return
加载中…
; if (error) return
加载失败:{error}
; const recent = runs.slice(0, 5); const stats = [ { label: "连接数", value: connections.length, href: "/connections" }, { label: "流水线数", value: pipelines.length, href: "/pipelines" }, { label: "运行总数", value: runs.length, href: "/runs" }, ]; return (

Dashboard

{stats.map((s) => ( {s.label} {s.value} ))}
最近运行 {recent.length === 0 ? (
还没有运行记录。
) : ( ID 流水线 状态 开始时间 耗时 {recent.map((r) => ( #{r.id} {r.pipeline_name ?? `(已删除 #${r.pipeline_id})`} {fmtTime(r.started_at)} {fmtDuration(r.started_at, r.finished_at)} ))}
)}
); }