// DRAFTS AS DECISIONS (plans/umtool-redesign.md, P2b): a report project whose // fields a model drafted and nobody has reviewed is a call in the Inbox's // Review group -- one row per field (the API keeps one row per decision), one // card per piece ("narration draft · 5 fields"), its action the project's // review page. Pure: lib/inbox.ts reads r28's draftsView() and hands its rows // here. // // "Not yet reviewed" is what a final build would refuse for want of an // approval: `unreviewed` (never judged) and `edited` (judged, then the field // changed under the verdict). A rejected draft is a ruling already made. /** The review states that wait on the operator. */ export const WAITING = new Set(["unreviewed", "edited"]); /** * THE fields awaiting review (P4b: one number, one meaning -- the Inbox's * drafts card, the piece's Media tab count and its "to review"): a field a * model drafted -- its `drafted` mark, or a task's draft file records it * (release 25's narration-draft.json carries no mark) -- whose verdict is not * given on its current value. A narration written by hand is listed and can * be judged, but nothing waits on it. * * @template {{ address: string, state: string, drafted: unknown }} R * @param {R[]} rows draftsView()'s rows * @param {Record} [provenance] readFieldProvenance()'s, by address * @returns {R[]} */ export function awaitingReview(rows, provenance = {}) { return (rows ?? []).filter((r) => WAITING.has(r.state) && (!!r.drafted || !!provenance?.[r.address])); } /** * What a drafts card is about, the canvas's card title: which kinds of field * and how many ("Narration draft · 5 fields"). * * @param {{ label: string }[]} rows the waiting rows */ export function draftsWhat(rows) { const labels = [...new Set(rows.map((r) => r.label))]; const named = labels.length <= 3 ? labels : [...labels.slice(0, 2), `${labels.length - 2} more`]; const list = named.length === 1 ? named[0] : `${named.slice(0, -1).join(", ")} and ${named[named.length - 1]}`; const head = `${list} draft${labels.length === 1 ? "" : "s"}`; const n = rows.length; return `${head[0].toUpperCase()}${head.slice(1)} · ${n} field${n === 1 ? "" : "s"}`; } /** * The card's whole sentence: what (draftsWhat), who drafted it, and how many * changed since they were approved. The API row's `why`; the Inbox shows the * `what` as the card's title and the rest under it. * * @param {{ label: string, state: string, drafted: { model?: string } | null }[]} rows the waiting rows */ export function draftsWhy(rows) { const models = [...new Set(rows.map((r) => r.drafted?.model).filter(Boolean))]; const edited = rows.filter((r) => r.state === "edited").length; return [draftsWhat(rows), models.length ? `by ${models.join(", ")}` : null, edited ? `${edited} changed since approved` : null] .filter(Boolean) .join(" · "); } /** * The `drafts-unreviewed` rows of one project. * * @param {{ * project: string, projectTitle: string, href: string, at: number, * view: { rows: { address: string, label: string, state: string, drafted: { model?: string } | null }[] }, * provenance?: Record, * }} o */ export function draftsDecisions({ project, projectTitle, href, at, view, provenance = {} }) { const waiting = awaitingReview(view?.rows ?? [], provenance); if (!waiting.length) return []; const what = draftsWhat(waiting); const why = draftsWhy(waiting); return waiting.map((r) => ({ project, projectTitle, kind: "drafts-unreviewed", target: r.address, what, why, href, severity: "open", at, })); }