import { useState } from "react";
import { Link, useParams } from "react-router";
import { api, type DatasetDetail as DD, type Graph } from "../api";
import { useFetch, fmtBytes, fmtDate, num } from "../hooks";
import { Badge, ErrorBox, JobStatus, JsonTree, KV, Loading, Tabs, Td } from "../components/ui";
import { LayeredGraph } from "../components/Graph";
export default function DatasetDetail() {
const { id } = useParams();
const { data, error, loading, reload } = useFetch
(`datasets/${id}`);
const lineage = useFetch(`datasets/${id}/lineage`);
const quality = useFetch>(`datasets/${id}/quality`);
const [tab, setTab] = useState("Assessment");
const [job, setJob] = useState(null);
if (loading) return ; if (error) return ; if (!data) return null;
const d = data;
const cols = Object.keys(d.schema_json?.columns ?? {}).slice(0, 12);
const exportIt = async (verified: boolean) => { const r = await api<{ job_id: string }>(`datasets/${d.id}/export`, { body: { verified } }); setJob(r.job_id); };
return (
{d.name} project {d.project_slug} · {num(d.row_count)} rows · granularity {d.granularity ?? "—"} · hash {d.hash}
exportIt(true)}>Export (verified) exportIt(false)}>Export (unverified)
{tab === "Assessment" &&
{d.assessment.verified ? "All checks pass: a verified export is allowed." : "Some checks fail: verified export is blocked; an unverified export is clearly labelled."}
{d.assessment.checks.map((c, i) =>
{c.ok ? "✓" : "✕"} {c.check}{c.detail && — {c.detail} }
)}
`${k}: ${v}`).join(", ") : "—"], ["License", (d.license?.name as string) ?? "—"], ["Records path", d.schema_json?.records_path ?? "—"], ["Created", `${fmtDate(d.created_at)} by ${d.created_by ?? "system"}`]]} /> }
{tab === "Preview" &&
{d.preview.length ?
{cols.map((c) => {c} )} {d.preview.map((r, i) => {cols.map((c) => {String(r[c] ?? "")} )} )}
:
No rows.
}
first {d.preview.length} rows · {cols.length} of {Object.keys(d.schema_json?.columns ?? {}).length} columns
}
{tab === "Quality" &&
{quality.loading && } {quality.data && }
}
{tab === "Lineage" &&
{lineage.loading && } {lineage.data && }
}
{tab === "Sources" &&
Executions {d.executions.length ?
Execution State AKP URL Hash When {d.executions.map((e) => {e.id.slice(0, 8)} {e.observed === false && }{e.akp_id ? `${e.akp_id} v${e.akp_version} (${e.akp_lifecycle ?? ""})` : "—"}{(e as { opaque?: boolean }).opaque && } {e.url} {e.response_hash?.slice(0, 12)}{fmtDate(e.finished_at)} )}
:
none (derived dataset) }
Transformations {d.transformations.length ? d.transformations.map((t) =>
{t.name} ({t.kind}) code sha256 {t.code_hash.slice(0, 12)} · inputs {t.input_dataset_ids.map((i) => {i.slice(0, 8)} )}) :
none }
}
{tab === "Exports" &&
{d.exports.length ? d.exports.map((x) =>
{fmtDate(x.created_at)} · {fmtBytes(x.size_bytes)} · {x.sha256.slice(0, 12)}download zip ) :
No exports yet.
}
}
);
}