import Link from "next/link"; import { deliverStateOf } from "@/lib/report/deliver.mjs"; import { badgeVariants } from "@/components/ui/badge"; import type { ProjectRef } from "@/lib/project-types"; import DeliverActions from "./DeliverActions"; // --------------------------------------------------------------------------- // DELIVER: the half of the work that starts when the walk ends. // // The bench answers one question per clip. What the report owes its readers is // a different list -- which sections were actually confirmed, which confirmed // clips have no file yet, which prose still cites a clip the walk threw out -- // and until now that list lived in one project's shell scripts and in whoever // remembered to run them in order. // // COUNTED BY SECTION, because that is how the report is read and how it falls // apart: "69 of 163 confirmed" says nothing about a section where eleven of // nineteen clips were ruled wrong, and that section is the one whose argument // has to change. // --------------------------------------------------------------------------- type Section = { letter: string; heading: string | null; folder: string; total: number; confirmed: number; incorrect: number; unreviewed: number; cut: number; }; type State = { sections: Section[]; review: { total: number; confirmed: number; incorrect: number; unreviewed: number }; cut: number; needCut: { id: string; seconds: number }[]; notFetched: string[]; batches: { name: string; label: string; count: number; hasList: boolean }[]; excluded: { shared: string[]; incorrect: string[] }; candidates: { id: string; section: string; file: string }[]; nextName: string; variants: { file: string; module: string; out: string }[]; incorrect: { id: string; correction: string; hits: { file: string; line: number; text: string }[] }[]; hasApplyScript: boolean; hasBuildScript: boolean; storage: Storage; }; /** Where the deliverables live (lib/report/storage.mjs deliverablesState, release 17). */ type Storage = { mode: "local" | "media" | null; value: unknown; error?: string; tiered: boolean; mediaRoot: string | null; dirs: { name: string; state: string; target?: string; leftovers: string[] }[]; cutBlocked: string[]; shareBlocked: string[]; }; export default async function DeliverSection({ project, manifest, entries, }: { project: ProjectRef; manifest: unknown; /** readClipDetail's entries, so `fetched` is the bench's own answer. */ entries: unknown[]; }) { const state = (await deliverStateOf(project, { manifest, entries })) as State | null; // A timeline with no clips has nothing to deliver, and a panel of zeroes on // every card-only cut is noise on a page that is already long. if (!state || !state.review.total) return null; const { review } = state; return (

deliver

{review.confirmed} confirmed · {review.incorrect} incorrect · {review.unreviewed} not yet judged · {state.cut} of {review.confirmed} cut
{/* --- by section ------------------------------------------------- */}
{state.sections.map((s) => ( ))}
section clips confirmed incorrect unjudged cut
{s.letter}{" "} {s.heading ?? "—"} {s.total} {s.confirmed} {s.incorrect ? ( {s.incorrect} ) : ( — )} {s.unreviewed || "—"} {s.cut} / {s.confirmed}
{/* --- the actions ------------------------------------------------ */}
({ module: v.module, out: v.out }))} storage={{ mode: state.storage.mode, tiered: state.storage.tiered, // What would stop a move: a link whose drive is not there, or a cut // move's leftovers (a move refuses over both, and says so). blocked: state.storage.dirs.flatMap((d) => d.state === "dangling" ? [`${d.name}/ is a link to ${d.target}, which is not there — is the media drive mounted?`] : [], ), cutBlocked: state.storage.cutBlocked, shareBlocked: state.storage.shareBlocked, }} />
{/* --- where the deliverables live (release 17) --------------------- */} {/* clips/ and every share-* live in the project, or on the media root behind a link, as the manifest's storage.deliverables says. A reader opens them by path either way; this line is the one place that says which, and what each directory is right now. */}

deliverables — {state.storage.mode === "media" ? "on the media root" : state.storage.mode === "local" ? "in the project" : `storage.deliverables is not "local" or "media"`} {state.storage.mode === "media" && state.storage.mediaRoot && ( <> {" "} ({state.storage.mediaRoot}) )} {state.storage.dirs.map((d) => ( {" · "} {d.name}/{" "} {d.state === "dangling" ? "link, NOT THERE" : d.state === "dir" ? "here" : d.state === "absent" ? "moving" : d.state} {d.leftovers.length ? ` (a cut move left ${d.leftovers.join(", ")})` : ""} ))} {state.storage.dirs.length === 0 && " · nothing cut or shared yet"}

{/* --- confirmed, but no file yet ---------------------------------- */} {state.needCut.length > 0 && (

no file yet — {state.needCut.map((c, i) => ( {i > 0 && " "} {c.id} ))}

)} {/* --- confirmed, and nothing cached to cut from -------------------- */} {/* A DIFFERENT PROBLEM, and it needs a different button. Nothing here fetches: the clip's window is a download, which the bench already has a managed path for (the editor's fetch, with its cookie policy and its per-platform sleeps). So this lists them and links to the clip page where that button lives. */} {state.notFetched.length > 0 && (

not fetched — {state.notFetched.map((id, i) => ( {i > 0 && " "} {id} ))} — open one and fetch its window through the editor, then cut.

)} {/* --- prose that still cites a clip the walk threw out -------------- */} {state.incorrect.length > 0 && (

prose citing an incorrect clip — {state.incorrect.length}

{state.incorrect.map((c) => (
{c.id} {" "} {c.correction} {c.hits.length === 0 ? (
(no reference found in the prose)
) : (
    {c.hits.map((h) => (
  • {h.file}:{h.line} {" "} {h.text}
  • ))}
)}
))}

Nothing here rewrites prose: what a wrong clip does to an argument is a judgement about the argument. Fix the lines, then rebuild.

)} {/* --- batches already sent ---------------------------------------- */}

{state.batches.length ? ( <> batches — {state.batches.map((b, i) => ( {i > 0 && " · "} {b.name} ({b.count}) ))} {". "} ) : ( "no batch has been packaged yet. " )} The next one ships {state.candidates.length} clip {state.candidates.length === 1 ? "" : "s"}: every confirmed clip with a file, minus the{" "} {state.excluded.shared.length} already shared and the {state.excluded.incorrect.length}{" "} ruled incorrect.

{state.variants.length > 0 && (

reports — {state.variants.map((v, i) => ( {i > 0 && " · "} {v.file} →{" "} {v.out} ))}

)}
); }