import type { FeedHealth, Site } from "@umt/contracts"; import { Globe, Plus, RefreshCw } from "lucide-react"; import { useState } from "react"; import { Link } from "react-router"; import { useFeeds } from "~/api/feeds.ts"; import { snapshotStale, useSiteAccounts, useSites } from "~/api/sites.ts"; import { type DataColumn, DataTable } from "~/components/console/data-table.tsx"; import { DetailSection } from "~/components/console/detail-sheet.tsx"; import { FilterBar, FilterSelect } from "~/components/console/filter-bar.tsx"; import { consolePath } from "~/components/console/nav.ts"; import { PageHeader } from "~/components/console/page-header.tsx"; import { StatusBadge } from "~/components/console/status-badge.tsx"; import { useQueryState } from "~/components/console/use-query-state.ts"; import { Button } from "~/components/ui/button.tsx"; import { FEED_HEALTH, FeedTable } from "~/components/workbench/feed-table.tsx"; import { accountSummary, circuitLabel, relTime, SITE_HEALTH } from "~/components/workbench/release-fields.ts"; import { legacyRedirectLoader } from "./redirects.ts"; // 来源健康:跨站点的 Feed 列表与站点健康总表;单个站点的快照、Feed、账号在站点详情。 export const meta = () => [{ title: "来源健康 · UHD 媒体自动化控制台" }]; // 旧的 ?tab=snapshots&siteId= 跳到站点详情的"快照与 Feed" export const clientLoader = legacyRedirectLoader; export default function SourcesPage() { const f = useQueryState(["health", "siteId"] as const); const [creating, setCreating] = useState(false); const sites = useSites(); const accounts = useSiteAccounts(); const feeds = useFeeds({ health: (f.values.health || undefined) as FeedHealth | undefined, siteId: f.values.siteId || undefined, }); const siteColumns: DataColumn[] = [ { key: "name", header: "站点", cell: (s) => ( e.stopPropagation()} > {s.name} ), }, { key: "health", header: "健康", cell: (s) => (
{SITE_HEALTH[s.healthStatus].label} {circuitLabel(s) ? {circuitLabel(s)} : null} {!s.enabled && s.healthStatus !== "disabled" ? 已停用 : null}
), }, { key: "account", header: "账号", hideBelow: "md", cell: (s) => { const a = accountSummary((accounts.data?.items ?? []).filter((x) => x.siteId === s.id)); return {a.label}; }, }, { key: "snapshot", header: "最近快照", hideBelow: "sm", cell: (s) => ( {s.snapshotEnabled ? relTime(s.lastSnapshotAt) : "未开启"} {s.snapshotEnabled && snapshotStale(s) ? 已过期 : null} ), }, ]; return ( <> setCreating(true)}> 新建 Feed } />
s.id} loading={sites.isPending} error={sites.error} onRetry={() => void sites.refetch()} empty={{ icon: Globe, title: "还没有登记站点", description: "在站点页添加。", }} /> void feeds.refetch()} disabled={feeds.isFetching}> 刷新 } > f.set("health", v)} options={Object.entries(FEED_HEALTH).map(([value, h]) => ({ value, label: h.label }))} /> f.set("siteId", v)} options={(sites.data?.items ?? []).map((s) => ({ value: s.id, label: s.name }))} />
); }