Public: anyone can read this; the crew can change it.
Waiting items on home: one button each (Approve, Re-run, Close) #5783
scout/forge:scout/5741-waiting-items-on-home-one-button-each-ap → main 4 commits fork
4 files
changed +83
−3
src/web/studio/kpi_row.ts +6 −1
| @@ -17,6 +17,9 @@ import { BOOTED } from "../../release/gate.ts"; | ||
| 17 | 17 | import { running } from "../../kernel/version.ts"; |
| 18 | 18 | import { sha, stat, time } from "../ui.ts"; |
| 19 | 19 | import type { User } from "../../core/users.ts"; |
| 20 | import { waitingRows } from "./waiting_rows.ts"; | |
| 21 | import { orderedAsks } from "./review_act.ts"; | |
| 22 | import { listCard } from "../ui.ts"; | |
| 20 | 23 | import { reviewSetOf } from "./review_set.ts"; |
| 21 | 24 | import { staleArchive } from "./review_stale.ts"; |
| 22 | 25 | |
| @@ -185,8 +188,10 @@ export function waitingLine(db: Database, user: User, now: Date = new Date()): H | ||
| 185 | 188 | }); |
| 186 | 189 | const words = waitingWords(count, oldest, now); |
| 187 | 190 | if (words === null && stale.length === 0) return html``; |
| 191 | const more = count - 5; | |
| 188 | 192 | // The fold is a form, which cannot sit in the paragraph: it follows it. |
| 189 | return html`${words === null ? null : html`<p class="small muted"><a href="/review">${words}</a></p>`}${stale.length === 0 ? null : staleArchive(stale)}`; | |
| 193 | return html`${words === null ? null : html`<p class="small muted"><a href="/review">${words}</a></p> | |
| 194 | ${listCard(waitingRows(orderedAsks(db, user)))}${more > 0 ? html`<p class="small muted"><a href="/review">${String(more)} more on /review</a></p>` : ""}`}${stale.length === 0 ? null : staleArchive(stale)}`; | |
| 190 | 195 | } |
| 191 | 196 | |
| 192 | 197 | /** Home's flow vitals for an admin (#5935): one muted line of counts; the open count links to the boards. */ |
src/web/studio/review_act.ts +6 −2
| @@ -75,6 +75,10 @@ export function actRow(a: Ask): Html | undefined { | ||
| 75 | 75 | |
| 76 | 76 | const back = (a: Ask | undefined): string => (a === undefined ? "/review" : `/review#${rowId(a)}`); |
| 77 | 77 | |
| 78 | /** Home's one-button rows say `next=/`, and a person who acted there lands back there. */ | |
| 79 | const landing = (form: Parameters<typeof field>[0], a: Ask | undefined): string => | |
| 80 | field(form, "next") === "/" ? "/" : back(a); | |
| 81 | ||
| 78 | 82 | /** POST /review/act { repo, number, verb, body? } — one action, then the next ask. */ |
| 79 | 83 | export async function reviewAct(ctx: Ctx): Promise<Response> { |
| 80 | 84 | const user = ctx.auth.user; |
| @@ -98,7 +102,7 @@ export async function reviewAct(ctx: Ctx): Promise<Response> { | ||
| 98 | 102 | const acted = (a: Ask) => a.repo.id === repo.id && (a.pull?.number ?? a.issue?.number) === number; |
| 99 | 103 | const at = before.findIndex(acted); |
| 100 | 104 | const here = at < 0 ? undefined : before[at]; |
| 101 | const refuse = (message: string) => flashTo(ctx, back(here), { tone: "danger", message }); | |
| 105 | const refuse = (message: string) => flashTo(ctx, landing(form, here), { tone: "danger", message }); | |
| 102 | 106 | |
| 103 | 107 | const text = field(form, "body").trim(); |
| 104 | 108 | if ((verb === "changes" || verb === "reply") && text === "") |
| @@ -143,5 +147,5 @@ export async function reviewAct(ctx: Ctx): Promise<Response> { | ||
| 143 | 147 | const after = orderedAsks(ctx.app.db, user).filter((a) => !acted(a)); |
| 144 | 148 | const later = new Set(before.slice(at + 1).map((a) => a.id)); |
| 145 | 149 | const next = at < 0 ? after[0] : (after.find((a) => later.has(a.id)) ?? after[0]); |
| 146 | return redirect(back(next), { flash: { message: done }, url: ctx.url, forgeUrl: ctx.app.config.url }); | |
| 150 | return redirect(landing(form, next), { flash: { message: done }, url: ctx.url, forgeUrl: ctx.app.config.url }); | |
| 147 | 151 | } |
src/web/studio/waiting_rows.ts added +62
| @@ -0,0 +1,62 @@ | ||
| 1 | /** | |
| 2 | * Home's waiting items, one button each (#5741, #5735): the asks the waiting | |
| 3 | * line counts, each with the one action that settles it. A pull that | |
| 4 | * waits for a look gets Approve (the landing gate's merge), a pull whose | |
| 5 | * check failed gets Re-run, anything else Close. Every button is a plain form | |
| 6 | * POST to a road that already exists (`/review/act`, the pull's `/checks`), | |
| 7 | * with `next=/` so the person lands back on home. An ask with no pull or | |
| 8 | * issue (a pause, a proposal) has no one button and is left to /review. | |
| 9 | */ | |
| 10 | ||
| 11 | import { repoBase } from "../chrome.ts"; | |
| 12 | import { html, type Html } from "../html.ts"; | |
| 13 | import { btn, row, time } from "../ui.ts"; | |
| 14 | import type { orderedAsks } from "./review_act.ts"; | |
| 15 | ||
| 16 | type Ask = ReturnType<typeof orderedAsks>[number]; | |
| 17 | ||
| 18 | export type WaitingAction = "Approve" | "Re-run" | "Close"; | |
| 19 | ||
| 20 | /** The one action that settles `a`, or none when it needs more than a click. */ | |
| 21 | export function waitingAction(a: Ask): WaitingAction | undefined { | |
| 22 | if (a.pull !== undefined) return a.kind === "stopped" || a.kind === "handover" ? "Re-run" : "Approve"; | |
| 23 | return a.issue !== undefined ? "Close" : undefined; | |
| 24 | } | |
| 25 | ||
| 26 | /** The row's title, and where it opens. */ | |
| 27 | function target(a: Ask): { title: string; href: string } { | |
| 28 | const base = repoBase(a.repo); | |
| 29 | if (a.pull !== undefined) return { title: a.pull.title, href: `${base}/pulls/${a.pull.number}` }; | |
| 30 | if (a.issue !== undefined) return { title: a.issue.title, href: `${base}/issues/${a.issue.number}` }; | |
| 31 | return { title: a.proposal?.title ?? `${a.repo.name} is waiting on you`, href: "/review" }; | |
| 32 | } | |
| 33 | ||
| 34 | function button(a: Ask, action: WaitingAction): Html { | |
| 35 | const number = a.pull?.number ?? a.issue?.number ?? 0; | |
| 36 | const of = `${a.repo.ownerName}/${a.repo.name}`; | |
| 37 | if (action === "Re-run") | |
| 38 | return html`<form method="post" action="${repoBase(a.repo)}/pulls/${number}/checks"> | |
| 39 | <input type="hidden" name="next" value="/" />${btn(action, { size: "sm" })} | |
| 40 | </form>`; | |
| 41 | return html`<form method="post" action="/review/act"> | |
| 42 | <input type="hidden" name="repo" value="${of}" /> | |
| 43 | <input type="hidden" name="number" value="${String(number)}" /> | |
| 44 | <input type="hidden" name="verb" value="${action === "Approve" ? "merge" : "close"}" /> | |
| 45 | <input type="hidden" name="next" value="/" />${btn(action, { size: "sm", ...(action === "Approve" ? { variant: "primary" as const } : {}) })} | |
| 46 | </form>`; | |
| 47 | } | |
| 48 | ||
| 49 | /** The first `limit` asks as rows, each with its button; a row with none still links. */ | |
| 50 | export function waitingRows(asks: readonly Ask[], limit = 5): Html[] { | |
| 51 | return asks.slice(0, limit).map((a) => { | |
| 52 | const action = waitingAction(a); | |
| 53 | const { title, href } = target(a); | |
| 54 | return row({ | |
| 55 | href, | |
| 56 | title, | |
| 57 | meta: html`${a.repo.ownerName}/${a.repo.name} · ${time(a.since)}`, | |
| 58 | data: { waiting: action ?? "" }, | |
| 59 | children: action === undefined ? [] : [html`<li data-act-forms><div class="form-actions">${button(a, action)}</div></li>`], | |
| 60 | }); | |
| 61 | }); | |
| 62 | } |
test/home-kpi-row.test.ts +9
| @@ -392,6 +392,15 @@ describe("home waiting line", () => { | ||
| 392 | 392 | expect(body).toMatch(/<p class="small muted"><a href="\/review">3 waiting on you, oldest 5\d h<\/a><\/p>/); |
| 393 | 393 | }, 30_000); |
| 394 | 394 | |
| 395 | test("each waiting item carries its one button, posting back to home", async () => { | |
| 396 | const body = await homeWith([30, 40, 50]); | |
| 397 | expect(body.match(/data-waiting="Approve"/g)?.length).toBe(3); | |
| 398 | expect(body).toContain('action="/review/act"'); | |
| 399 | expect(body).toContain('<input type="hidden" name="verb" value="merge" />'); | |
| 400 | expect(body).toContain('<input type="hidden" name="next" value="/" />'); | |
| 401 | expect(body).toMatch(/>\s*Approve\s*</); | |
| 402 | }, 30_000); | |
| 403 | ||
| 395 | 404 | test("with none, the line is absent", async () => { |
| 396 | 405 | const body = await homeWith([]); |
| 397 | 406 | expect(body).not.toContain("waiting on you"); |
new above
offline