Public: anyone can read this; the crew can change it.
The review page's finished screen says when the next reminder will be drafted and for whom #276
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/273-the-review-page-s-finished-screen-says-w → main 4 commits fork 1 thread · 1 unresolved
5 files
changed +71
−3
src/coming.test.ts +20 −1
| @@ -5,7 +5,7 @@ import { tmpdir } from "node:os"; | ||
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { addDays, DEFAULT_ZONE, today } from "./dates.ts"; |
| 7 | 7 | import { openDb } from "./db.ts"; |
| 8 | import { COMING_MAX, coming } from "./coming.ts"; | |
| 8 | import { COMING_MAX, coming, nextComing } from "./coming.ts"; | |
| 9 | 9 | import { createDeal, getDeal, markDone, moveDeadline, setReminderLead, waiveDate, type DealView } from "./deals.ts"; |
| 10 | 10 | import { drafts } from "./reminders.ts"; |
| 11 | 11 | import { escape } from "./http.ts"; |
| @@ -85,3 +85,22 @@ test("a deal with nothing coming says so", () => { | ||
| 85 | 85 | const html = dealPage({ who: alice, agent, deal: fresh(deal.id), on: addDays(day, 5) }); |
| 86 | 86 | expect(html).toContain("No reminders coming. Every date is done, waived or past."); |
| 87 | 87 | }); |
| 88 | ||
| 89 | test("nextComing is undefined with no deals or nothing left to draft, and picks the soonest across deals", () => { | |
| 90 | expect(nextComing([], day, agent)).toBeUndefined(); | |
| 91 | const a = open(); | |
| 92 | const b = open(); | |
| 93 | expect(nextComing([fresh(a.id)], addDays(day, 400), agent)).toBeUndefined(); | |
| 94 | const soonest = (d: DealView) => coming(d, day, agent).shown[0]!.on; | |
| 95 | const id = inspection(fresh(b.id)).id; | |
| 96 | expect(moveDeadline(db, alice, { id, due: addDays(day, 3), reason: "test" }).ok).toBe(true); | |
| 97 | expect(setReminderLead(db, alice, { id, leadDays: 2 }).ok).toBe(true); | |
| 98 | const [ga, gb] = [fresh(a.id), fresh(b.id)]; | |
| 99 | const pick = nextComing([ga, gb], day, agent)!; | |
| 100 | const want = soonest(ga) <= soonest(gb) ? ga : gb; | |
| 101 | expect(pick.deal_id).toBe(want.id); | |
| 102 | expect(pick.address).toBe(want.address); | |
| 103 | expect(pick.coming.on).toBe(soonest(want)); | |
| 104 | expect(soonest(gb) < soonest(ga)).toBe(true); | |
| 105 | expect(pick.deal_id).toBe(b.id); | |
| 106 | }); |
src/coming.ts +17
| @@ -50,3 +50,20 @@ export function coming(deal: DealView, day: string, agent: Agent): ComingList { | ||
| 50 | 50 | /** "Mon, Nov 16 · 7 days before · Inspection due Mon, Nov 23 · to Ann Buyer (buyer)": one line, for the page and the terminal alike. */ |
| 51 | 51 | export const comingLine = (c: Coming): string => |
| 52 | 52 | `${spoken(c.on)} · ${c.moment} · ${c.label} due ${spoken(c.due)} · to ${c.party_name} (${PARTY_LABEL[c.party_role].toLowerCase()})`; |
| 53 | ||
| 54 | export interface Next { | |
| 55 | readonly deal_id: number; | |
| 56 | readonly address: string; | |
| 57 | readonly coming: Coming; | |
| 58 | } | |
| 59 | ||
| 60 | /** The soonest reminder still to be drafted across `deals`, or undefined when no open date has one. */ | |
| 61 | export function nextComing(deals: readonly DealView[], day: string, agent: Agent): Next | undefined { | |
| 62 | let best: Next | undefined; | |
| 63 | for (const deal of deals) { | |
| 64 | const first = coming(deal, day, agent).shown[0]; | |
| 65 | if (first !== undefined && (best === undefined || first.on < best.coming.on)) | |
| 66 | best = { deal_id: deal.id, address: deal.address, coming: first }; | |
| 67 | } | |
| 68 | return best; | |
| 69 | } |
src/pages/review.ts +11 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | import type { Agent } from "../reminders.ts"; |
| 10 | import type { Next } from "../coming.ts"; | |
| 10 | 11 | import { BODY_MAX, EMAIL_MAX, PHONE_MAX, REASON_MAX, SUBJECT_MAX } from "../deals.ts"; |
| 11 | 12 | import { spoken } from "../dates.ts"; |
| 12 | 13 | import { PARTY_LABEL } from "../deadlines.ts"; |
| @@ -64,6 +65,8 @@ export function reviewPage(input: { | ||
| 64 | 65 | notice?: string | undefined; |
| 65 | 66 | /** What was approved and declined today, for the finished screen. */ |
| 66 | 67 | settled?: Settled | undefined; |
| 68 | /** The soonest reminder still to come, for the finished screen. */ | |
| 69 | next?: Next | undefined; | |
| 67 | 70 | open?: readonly string[] | undefined; |
| 68 | 71 | error?: ReviewError | undefined; |
| 69 | 72 | typed?: Typed | undefined; |
| @@ -74,11 +77,18 @@ export function reviewPage(input: { | ||
| 74 | 77 | const back = `<a href="/${q === "" ? "" : `?q=${encodeURIComponent(q)}`}">Back to the clock</a>`; |
| 75 | 78 | const body = |
| 76 | 79 | draft === undefined |
| 77 | ? `<section class="card narrow"><h1>Review today's reminders</h1><p>${input.settled === undefined || settledLine(input.settled) === "" ? "All of today's reminders are sent or declined." : `All of today's reminders are sent or declined. ${escape(settledLine(input.settled))}`}</p><p>${back}</p></section>` | |
| 80 | ? `<section class="card narrow"><h1>Review today's reminders</h1><p>${input.settled === undefined || settledLine(input.settled) === "" ? "All of today's reminders are sent or declined." : `All of today's reminders are sent or declined. ${escape(settledLine(input.settled))}`}</p>${nextLine(input.next)}<p>${back}</p></section>` | |
| 78 | 81 | : form(draft, { q, at, done, position: done + at + 1, total: done + queue.length, error, typed }, back); |
| 79 | 82 | return layout({ body, who, agent, waiting: input.waiting, path: REVIEW_PATH, heading: "Review today's reminders", notice: input.notice, open: input.open, live: false }); |
| 80 | 83 | } |
| 81 | 84 | |
| 85 | /** "Next: Thu Nov 12, Financing reminder to Priya Nair, 9 Orchard Row", linked to the deal; nothing when nothing is coming. */ | |
| 86 | function nextLine(next: Next | undefined): string { | |
| 87 | if (next === undefined) return ""; | |
| 88 | const c = next.coming; | |
| 89 | return `<p>Next: ${escape(spoken(c.on))}, ${escape(c.label)} reminder to ${escape(c.party_name)}, <a href="/deals/${next.deal_id}">${escape(next.address)}</a></p>`; | |
| 90 | } | |
| 91 | ||
| 82 | 92 | /** |
| 83 | 93 | * The Save contact field for a party with nothing on file. It sits inside the |
| 84 | 94 | * draft's form, first, so the edited words travel with it and Enter in it |
src/review.test.ts +15
| @@ -249,3 +249,18 @@ test("the finished screen adds how many were held until tomorrow, and nothing wh | ||
| 249 | 249 | expect(count(after)).toBe(before + 1); |
| 250 | 250 | expect(await get("/reminders/today?q=zzzz-no-such-deal&done=9")).toContain(`${before + 1} held until tomorrow.`); |
| 251 | 251 | }); |
| 252 | ||
| 253 | test("the finished screen says which reminder is drafted next, linked to its deal", async () => { | |
| 254 | for (let i = 0; i < 200; i++) { | |
| 255 | forgetRationing(); | |
| 256 | const page = await get("/reminders/today"); | |
| 257 | if (!page.includes('name="deadline"')) break; | |
| 258 | const one = shown(page); | |
| 259 | const sent = await post("/reminders/today/send", { ...keys(one), subject: "s", body: "b" }); | |
| 260 | expect(sent.status).toBeLessThan(400); | |
| 261 | forgetRationing(); | |
| 262 | } | |
| 263 | const done = await get("/reminders/today"); | |
| 264 | expect(done).toContain("All of today's reminders are sent or declined."); | |
| 265 | expect(done).toMatch(/<p>Next: [^<]+, [^<]+ reminder to [^<]+, <a href="\/deals\/\d+">[^<]+<\/a><\/p>/); | |
| 266 | }); |
src/routes.ts +8 −1
| @@ -40,6 +40,7 @@ import { | ||
| 40 | 40 | import type { Verb } from "./can.ts"; |
| 41 | 41 | import { events } from "./live.ts"; |
| 42 | 42 | import { DEFAULT_ZONE, dayOf } from "./dates.ts"; |
| 43 | import { nextComing, type Next } from "./coming.ts"; | |
| 43 | 44 | import { tally } from "./book.ts"; |
| 44 | 45 | import { AMOUNT_MAX, RATE_MAX } from "./money.ts"; |
| 45 | 46 | import { progress } from "./progress.ts"; |
| @@ -606,6 +607,12 @@ function reviewQueue(c: Context, q: string): Result<Draft[]> { | ||
| 606 | 607 | return { ok: true, value: todaysDrafts(find(deals.value, q), dayOf(agentFor(c)), agentFor(c)).filter(unsent) }; |
| 607 | 608 | } |
| 608 | 609 | |
| 610 | /** The soonest reminder still to come among the deals this person may list; only asked for on the finished screen. */ | |
| 611 | function nextAfter(c: Context): Next | undefined { | |
| 612 | const deals = listDeals(c.db, c.who); | |
| 613 | return deals.ok ? nextComing(deals.value, dayOf(agentFor(c)), agentFor(c)) : undefined; | |
| 614 | } | |
| 615 | ||
| 609 | 616 | /** Whose deals these are, read once per request however many times a page and its header ask. */ |
| 610 | 617 | const agents = new WeakMap<Context, Agent>(); |
| 611 | 618 | function agentFor(c: Context): Agent { |
| @@ -1415,7 +1422,7 @@ export const routes: readonly Route[] = [ | ||
| 1415 | 1422 | const sent = open === undefined ? undefined : listDeals(c.db, c.who); |
| 1416 | 1423 | const link = open === undefined || !sent?.ok ? undefined : sent.value.flatMap((d) => d.sent).find((m) => m.id === open)?.hrefs ?? []; |
| 1417 | 1424 | return html( |
| 1418 | reviewPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), queue: queue.value, q, at: count(c.url.searchParams.get("at")), done: count(c.url.searchParams.get("done")), notice, open: link, settled: queue.value.length === 0 ? settledOn(c.db, agentFor(c).zone ?? DEFAULT_ZONE, dayOf(agentFor(c))) : undefined }), | |
| 1425 | reviewPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), queue: queue.value, q, at: count(c.url.searchParams.get("at")), done: count(c.url.searchParams.get("done")), notice, open: link, settled: queue.value.length === 0 ? settledOn(c.db, agentFor(c).zone ?? DEFAULT_ZONE, dayOf(agentFor(c))) : undefined, next: queue.value.length === 0 ? nextAfter(c) : undefined }), | |
| 1419 | 1426 | 200, |
| 1420 | 1427 | clear, |
| 1421 | 1428 | ); |
new above
offline
This only tests the case where a Next line exists. Add tests for nextComing returning undefined with no open dates, and for picking the soonest across deals.