diff --git a/docs/DESIGN.md b/docs/DESIGN.md index d128c257..a82749f6 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -695,7 +695,7 @@ of a full-width panel and nothing on the right. | 2026-10-01 | E31 Statistics overview | Number tiles, and the per-operation counts as horizontal bars | Three narrow cards; a 30-day chart | The label sits by its value; what spends the quota is seen at a glance | | 2026-10-01 | E31 Channel page header | The full banner, folding to one row once the grid scrolls | Always compact; no banner | The header is fixed and took 40% of a 685px window; the channel keeps its face at first sight | | 2026-10-01 | E31 Channel page watch state | A fresh channel page shows the unwatched videos; a picked state is remembered | Show all, forgotten on reload | The owner: open a channel to see what is new; a choice made there should stick | -| 2026-10-01 | E31 Audit log runs | Back-to-back successful runs of one job fold into one row that opens; a failure is never folded and reads in the danger colour | A filter defaulting to admin actions; both | Nothing hidden, the noise collapsed, the failure seen | +| 2026-10-01 | E31 Audit log runs | A job's successful runs fold into one row that opens, whatever ran between; only that job's failure (never folded, danger colour) breaks it | A filter defaulting to admin actions; both | Nothing hidden, the noise collapsed, the failure seen | | 2026-10-01 | E31 Users row | Role and state as badges, the actions in the row's one menu | An inline role toggle; icon-only buttons | Action placement: the row shows state, rare and destructive actions live in the menu | | 2026-10-01 | E31 YouTube player | Video beside an info panel at 1280px and wider (the video as large as the height allows); stacked below | Today's stack with a one-line bar; full-window like Plex | The owner's eyesight: about 1460px of video on 1080p instead of 1008, the actions still visible | | 2026-10-01 | E31 Plex info and show pages | A second column for the facts, keywords and crew, as the person page; a collection's hero sized to its content | Full-width text; a larger poster and fanart | The right ~40% was empty; one composition for every media page | diff --git a/frontend/src/lib/auditGroups.test.ts b/frontend/src/lib/auditGroups.test.ts index ff505de3..a4f6a7c3 100644 --- a/frontend/src/lib/auditGroups.test.ts +++ b/frontend/src/lib/auditGroups.test.ts @@ -1,5 +1,6 @@ -// E31: the audit log's first screen was one job's "done" ten times over. Back-to-back successful runs -// of one job fold into one row; a failure, a skip, another job or an admin's own action breaks the run. +// E31: the audit log's first screen was one job's "done" ten times over. A job's successful runs fold +// into one row whatever ran between them (the owner: a fold broken by every other job read as the same +// row five times); only that job's own failure or skip breaks it. import { describe, expect, it } from "vitest"; import type { AuditRow } from "./api"; import { foldJobRuns } from "./auditGroups"; @@ -22,7 +23,7 @@ const shape = (rows: ReturnType) => rows.map((r) => `${r.target_id}:${String(r.after?.status)}×${r.runs?.length ?? 1}`); describe("folding the job runs", () => { - it("folds back-to-back successful runs of one job, newest first", () => { + it("folds a job's successful runs into one row, newest first", () => { const rows = [run("enrich"), run("enrich"), run("enrich"), run("people")]; const out = foldJobRuns(rows); expect(shape(out)).toEqual(["enrich:ok×3", "people:ok×1"]); @@ -44,11 +45,22 @@ describe("folding the job runs", () => { ]); }); - it("keeps an admin's own action between two runs, and the runs apart", () => { - expect(shape(foldJobRuns([run("enrich"), admin(), run("enrich")]))).toEqual([ - "enrich:ok×1", - "x:ok×1", + it("folds across other jobs and an admin's own action, each at its own place", () => { + const rows = [run("enrich"), run("plex"), run("enrich"), admin(), run("shorts"), run("enrich")]; + rows.push(run("plex")); + const out = foldJobRuns(rows); + expect(shape(out)).toEqual(["enrich:ok×3", "plex:ok×2", "x:ok×1", "shorts:ok×1"]); + expect(out[0]!.runs!.map((r) => r.id)).toEqual([rows[0]!.id, rows[2]!.id, rows[5]!.id]); + }); + + it("starts a new fold below the job's own failure, which another job's does not", () => { + const rows = [run("enrich"), run("enrich", "error"), run("enrich"), run("rss", "error")]; + rows.push(run("enrich")); + expect(shape(foldJobRuns(rows))).toEqual([ "enrich:ok×1", + "enrich:error×1", + "enrich:ok×2", + "rss:error×1", ]); }); diff --git a/frontend/src/lib/auditGroups.ts b/frontend/src/lib/auditGroups.ts index 6fe39b81..ace58e36 100644 --- a/frontend/src/lib/auditGroups.ts +++ b/frontend/src/lib/auditGroups.ts @@ -2,31 +2,47 @@ import type { AuditRow } from "./api"; // The audit log's scheduler noise, folded (E31, the owner's pick): the background jobs write a row per // run that changed something, so an hour of "enrichment done" filled the first screen and pushed the -// admins' own actions down. Back-to-back SUCCESSFUL runs of the same job become one row that names how -// many there were and opens to each; a failed or skipped run is never folded — it stays a row of its -// own, where it is seen. Rows arrive newest first; the group stands at its newest run's place. +// admins' own actions down. A job's SUCCESSFUL runs become one row that names how many there were and +// opens to each — whatever ran between them (another job, an admin's action): the owner read a fold +// that broke at every other job as the same row five times. Only that job's own failed or skipped run +// breaks it: that row stays on its own, at its moment, where it is seen, and the job's older successes +// start a new fold below it. Rows arrive newest first; a fold stands at its newest run's place. -/** An audit row as the table lists it: a lone row, or the newest of a run of folded ones (`runs`, the - * whole run newest first, the row itself included). */ +/** An audit row as the table lists it: a lone row, or the newest of a job's folded runs (`runs`, the + * whole fold newest first, the row itself included). */ export type AuditListRow = AuditRow & { runs?: AuditRow[] }; -/** The job a row is a successful run of, or null for any other row. */ -function okRunOf(row: AuditRow): string | null { - if (row.action !== "job_run" || row.target_type !== "job" || !row.target_id) return null; - return row.after?.status === "ok" ? row.target_id : null; +/** The job a row is a run of, or null for any other row. */ +function jobOf(row: AuditRow): string | null { + return row.action === "job_run" && row.target_type === "job" && row.target_id + ? row.target_id + : null; } export function foldJobRuns(rows: readonly AuditRow[]): AuditListRow[] { const out: AuditListRow[] = []; - let head: AuditListRow | null = null; + // Each job's open fold: the row its next older success joins. + const open = new Map(); for (const row of rows) { - const job = okRunOf(row); - if (job !== null && head !== null && okRunOf(head) === job) { + const job = jobOf(row); + if (job === null) { + out.push(row); + continue; + } + if (row.after?.status !== "ok") { + // A failure or a skip stands alone and closes the job's fold. + open.delete(job); + out.push(row); + continue; + } + const head = open.get(job); + if (head) { head.runs = [...(head.runs ?? [head]), row]; continue; } - head = { ...row }; - out.push(head); + const fresh: AuditListRow = { ...row }; + open.set(job, fresh); + out.push(fresh); } return out; }