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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/273-the-review-page-s-finished-screen-says-w → main 4 commits fork 1 thread · 1 unresolved

  • Merged. mason/273-the-review-page-s-finished-screen-says-w was merged into main as 33d0843.

Review

Sign in to review this change.
5 files changed +71 −3
src/coming.test.ts +20 −1
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 import { addDays, DEFAULT_ZONE, today } from "./dates.ts";
77 import { openDb } from "./db.ts";
8 import { COMING_MAX, coming } from "./coming.ts";
8 import { COMING_MAX, coming, nextComing } from "./coming.ts";
99 import { createDeal, getDeal, markDone, moveDeadline, setReminderLead, waiveDate, type DealView } from "./deals.ts";
1010 import { drafts } from "./reminders.ts";
1111 import { escape } from "./http.ts";
@@ -85,3 +85,22 @@ test("a deal with nothing coming says so", () => {
8585 const html = dealPage({ who: alice, agent, deal: fresh(deal.id), on: addDays(day, 5) });
8686 expect(html).toContain("No reminders coming. Every date is done, waived or past.");
8787 });
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 {
5050 /** "Mon, Nov 16 · 7 days before · Inspection due Mon, Nov 23 · to Ann Buyer (buyer)": one line, for the page and the terminal alike. */
5151 export const comingLine = (c: Coming): string =>
5252 `${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 @@
77 */
88
99 import type { Agent } from "../reminders.ts";
10 import type { Next } from "../coming.ts";
1011 import { BODY_MAX, EMAIL_MAX, PHONE_MAX, REASON_MAX, SUBJECT_MAX } from "../deals.ts";
1112 import { spoken } from "../dates.ts";
1213 import { PARTY_LABEL } from "../deadlines.ts";
@@ -64,6 +65,8 @@ export function reviewPage(input: {
6465 notice?: string | undefined;
6566 /** What was approved and declined today, for the finished screen. */
6667 settled?: Settled | undefined;
68 /** The soonest reminder still to come, for the finished screen. */
69 next?: Next | undefined;
6770 open?: readonly string[] | undefined;
6871 error?: ReviewError | undefined;
6972 typed?: Typed | undefined;
@@ -74,11 +77,18 @@ export function reviewPage(input: {
7477 const back = `<a href="/${q === "" ? "" : `?q=${encodeURIComponent(q)}`}">Back to the clock</a>`;
7578 const body =
7679 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>`
7881 : form(draft, { q, at, done, position: done + at + 1, total: done + queue.length, error, typed }, back);
7982 return layout({ body, who, agent, waiting: input.waiting, path: REVIEW_PATH, heading: "Review today's reminders", notice: input.notice, open: input.open, live: false });
8083 }
8184
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
8292 /**
8393 * The Save contact field for a party with nothing on file. It sits inside the
8494 * 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
249249 expect(count(after)).toBe(before + 1);
250250 expect(await get("/reminders/today?q=zzzz-no-such-deal&done=9")).toContain(`${before + 1} held until tomorrow.`);
251251 });
252
253 test("the finished screen says which reminder is drafted next, linked to its deal", async () => {

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.

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 {
4040 import type { Verb } from "./can.ts";
4141 import { events } from "./live.ts";
4242 import { DEFAULT_ZONE, dayOf } from "./dates.ts";
43 import { nextComing, type Next } from "./coming.ts";
4344 import { tally } from "./book.ts";
4445 import { AMOUNT_MAX, RATE_MAX } from "./money.ts";
4546 import { progress } from "./progress.ts";
@@ -606,6 +607,12 @@ function reviewQueue(c: Context, q: string): Result<Draft[]> {
606607 return { ok: true, value: todaysDrafts(find(deals.value, q), dayOf(agentFor(c)), agentFor(c)).filter(unsent) };
607608 }
608609
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
609616 /** Whose deals these are, read once per request however many times a page and its header ask. */
610617 const agents = new WeakMap<Context, Agent>();
611618 function agentFor(c: Context): Agent {
@@ -1415,7 +1422,7 @@ export const routes: readonly Route[] = [
14151422 const sent = open === undefined ? undefined : listDeals(c.db, c.who);
14161423 const link = open === undefined || !sent?.ok ? undefined : sent.value.flatMap((d) => d.sent).find((m) => m.id === open)?.hrefs ?? [];
14171424 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 }),
14191426 200,
14201427 clear,
14211428 );

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs