// VERSIONS TO JUDGE (umtool redesign L4, "What needs you"): a saved version // (lib/report/versions.mjs) -- or a legacy take -- that has a RENDER and no // verdict is a call in the Inbox's Review group. One row per version (the API // keeps one row per decision), one card per piece ("3 versions to judge"), its // action Play and judge: Play on the newest of them (`?take=`), where the // verdict buttons are. // // Not a version to judge: one with no render on disk (a saved version not yet // rendered, a draft take -- `previewSize` null), a quick draft-quality // render, a superseded take (folded away by a person), and a quick clip's one // take (a share, not a version -- lib/report/quickClip.mjs). "Rendered" is the // preview file being there, whatever take.json's `draft` says. // // Pure: lib/inbox/projectCalls.ts reads the takes and verdicts and hands them // here. Never throws on a shape it does not know: it is left out. export const VERSION_UNJUDGED = "version-unjudged"; /** * A render older than this that nobody judged is no longer waiting: its rows are `info` (the Quiet group, * folded) rather than Review -- on the real tree (9 Nov) 46 projects had a render with no verdict, 18 of them * from the last two weeks. */ export const RECENT_DAYS = 14; const timeOf = (t) => { const ms = Date.parse(t?.builtAt ?? t?.savedAt ?? ""); if (Number.isFinite(ms)) return ms; return Number.isFinite(t?.previewMtimeMs) ? t.previewMtimeMs : 0; }; /** * The takes that wait on a verdict, newest first. * * @param {Array>} takes listTakes()'s takes * @param {Record} verdicts readVerdicts() * @param {{ skip?: (take: Record) => boolean }} [o] */ export function versionsToJudge(takes, verdicts, { skip = () => false } = {}) { const v = verdicts && typeof verdicts === "object" ? verdicts : {}; return (Array.isArray(takes) ? takes : []) .filter((t) => t && typeof t.id === "string") .filter((t) => t.previewSize != null && t.quick !== true) .filter((t) => !v[t.id]?.verdict && !v[t.id]?.superseded) .filter((t) => !skip(t)) .sort((a, b) => timeOf(b) - timeOf(a) || String(a.id).localeCompare(String(b.id))); } /** The card's title: how many wait. */ export function versionsWhat(waiting) { const n = waiting.length; return `${n} version${n === 1 ? "" : "s"} to judge`; } const day = (ms) => (ms ? new Date(ms).toISOString().slice(0, 10) : null); const mins = (s) => (Number.isFinite(s) && s > 0 ? `${Math.floor(s / 60)}:${String(Math.round(s % 60)).padStart(2, "0")}` : null); /** * The `version-unjudged` rows of one project. * * @param {{ * project: string, projectTitle: string, projectKind?: string, * takes: Array>, verdicts: Record, * playHref: (take: string) => string, * skip?: (take: Record) => boolean, * now?: number, * }} o */ export function versionsDecisions({ project, projectTitle, projectKind, takes, verdicts, playHref, skip, now = Date.now() }) { const waiting = versionsToJudge(takes, verdicts, { skip }); if (!waiting.length) return []; const old = (t) => now - timeOf(t) > RECENT_DAYS * 864e5; // Two cards at most: the recent renders (Review) and the older ones (Quiet), each counted and named by its own. return [waiting.filter((t) => !old(t)), waiting.filter(old)].flatMap((rows) => { if (!rows.length) return []; const what = versionsWhat(rows); // The card's sentence is its newest row's (summarizeGroups keeps the first, ranked newest first). const newest = rows[0]; const href = playHref(newest.id); const facts = [`${newest.version ? "version" : "take"} ${newest.id}`, newest.label && newest.label !== newest.id ? `“${newest.label}”` : null, mins(newest.seconds), day(timeOf(newest)) ? `rendered ${day(timeOf(newest))}` : null]; const why = `${what} · newest ${facts.filter(Boolean).join(" · ")} — play it and say like, maybe or no`; return rows.map((t) => ({ project, projectTitle, ...(projectKind ? { projectKind } : {}), kind: VERSION_UNJUDGED, target: t.id, what, why, href, severity: old(t) ? "info" : "open", at: timeOf(t), })); }); }