Public: anyone can read this; the crew can change it.
An overdue date on This week says when it was due and how late it is, so the agent knows what to chase first #211
mason/deal-clock:mason/209-an-overdue-date-on-this-week-says-when-i → main 1 commit fork
5 files
changed +38
−4
src/pages/clock.ts +2 −2
| @@ -14,7 +14,7 @@ import { todaysDrafts, unsent, type Agent } from "../reminders.ts"; | ||
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | 15 | import { conflictShort } from "../order.ts"; |
| 16 | 16 | import { clashLine, clashesLine } from "../overlap.ts"; |
| 17 | import { byDay, thisWeek, whereNote } from "../week.ts"; | |
| 17 | import { byDay, lateNote, thisWeek, whereNote } from "../week.ts"; | |
| 18 | 18 | import { layout } from "./layout.ts"; |
| 19 | 19 | import { mayRestore } from "../actions.ts"; |
| 20 | 20 | import { badge, draftLink, opens, owedBy, URGENCY_LABEL } from "./sheet.ts"; |
| @@ -112,7 +112,7 @@ export function weekCard(deals: readonly DealView[], on: string, q = "", side: S | ||
| 112 | 112 | (g) => `<h3 class="week-day">${escape(g.heading)}</h3> |
| 113 | 113 | <ul class="week-list">${g.items |
| 114 | 114 | .map(({ deal, deadline: d }) => |
| 115 | weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}${whereNote(deal, d) === "" ? "" : ` · ${escape(whereNote(deal, d))}`}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${d.kind === "closing" ? clashLine(deal.closingConflicts, "small", false) : ""}${clashesLine(d.clashes, "small", false)}${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`), | |
| 115 | weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}${whereNote(deal, d) === "" ? "" : ` · ${escape(whereNote(deal, d))}`}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${d.kind === "closing" ? clashLine(deal.closingConflicts, "small", false) : ""}${clashesLine(d.clashes, "small", false)}${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${lateNote(d.due, on) === "" ? "" : `<small class="muted">${escape(lateNote(d.due, on))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`), | |
| 116 | 116 | ) |
| 117 | 117 | .join("")}</ul>`, |
| 118 | 118 | ) |
src/pages/week.ts +2 −1
| @@ -12,7 +12,7 @@ import { agent as defaults } from "../env.ts"; | ||
| 12 | 12 | import { asset, escape } from "../http.ts"; |
| 13 | 13 | import { STATUS } from "../timeline.ts"; |
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | import { byDay, owner, whereNote, thisWeek } from "../week.ts"; | |
| 15 | import { byDay, lateNote, owner, whereNote, thisWeek } from "../week.ts"; | |
| 16 | 16 | import { clashLine, clashesLine } from "../overlap.ts"; |
| 17 | 17 | import { layout } from "./layout.ts"; |
| 18 | 18 | import { sideLabel } from "./side.ts"; |
| @@ -46,6 +46,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re | ||
| 46 | 46 | <p class="timeline-label"><b>${escape(d.label)}${closingAt(deal, d)}</b></p> |
| 47 | 47 | <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p> |
| 48 | 48 | ${d.kind === "closing" ? clashLine(deal.closingConflicts) : ""}${clashesLine(d.clashes)} |
| 49 | ${lateNote(d.due, on) === "" ? "" : `<p class="timeline-owner">${escape(lateNote(d.due, on))}</p>`} | |
| 49 | 50 | ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`} |
| 50 | 51 | <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p> |
| 51 | 52 | </li>`; |
src/week.page.test.ts +19
| @@ -96,3 +96,22 @@ test("a place with markup in it is escaped on the sheet", async () => { | ||
| 96 | 96 | expect(html).toContain("8:00 am at <b>Title</b> & Co"); |
| 97 | 97 | expect(html).not.toContain("<b>Title</b>"); |
| 98 | 98 | }); |
| 99 | ||
| 100 | test("an overdue row on /week and on the clock carries its due date and how late it is", async () => { | |
| 101 | forgetRationing(); | |
| 102 | const { lateNote } = await import("./week.ts"); | |
| 103 | const { spoken } = await import("./dates.ts"); | |
| 104 | const deals = (await (await get("/api/deals")).json()) as { closed?: boolean; fell_through?: boolean; deadlines: { due: string; done_at: string | null; waived_at: string | null }[] }[]; | |
| 105 | const { dayOf } = await import("./dates.ts"); | |
| 106 | const { agent } = await import("./env.ts"); | |
| 107 | const on = dayOf(agent); | |
| 108 | const late = deals | |
| 109 | .filter((d) => d.closed !== true && d.fell_through !== true) | |
| 110 | .flatMap((d) => d.deadlines) | |
| 111 | .find((d) => d.done_at === null && d.waived_at === null && d.due < on); | |
| 112 | expect(late).toBeDefined(); | |
| 113 | const words = lateNote(late!.due, on); | |
| 114 | expect(words).toContain(`due ${spoken(late!.due)} · `); | |
| 115 | expect(await (await get("/week")).text()).toContain(words); | |
| 116 | expect(await (await get("/")).text()).toContain(words); | |
| 117 | }); |
src/week.test.ts +8
| @@ -47,3 +47,11 @@ test("on one day timed closings come first by time, then the other rows as befor | ||
| 47 | 47 | const rows = thisWeek([other, c("Z Street", "15:00"), c("Y Street", null), c("X Street", "09:30")], on); |
| 48 | 48 | expect(rows.map((i) => i.deal.address)).toEqual(["X Street", "Z Street", "A Street", "Y Street"]); |
| 49 | 49 | }); |
| 50 | ||
| 51 | test("lateNote says when an overdue date was due and how late it is", async () => { | |
| 52 | const { lateNote } = await import("./week.ts"); | |
| 53 | expect(lateNote("2026-11-06", "2026-11-08")).toBe("due Fri, Nov 6 · 2 days late"); | |
| 54 | expect(lateNote("2026-11-07", "2026-11-08")).toBe("due Sat, Nov 7 · 1 day late"); | |
| 55 | expect(lateNote("2026-11-08", "2026-11-08")).toBe(""); | |
| 56 | expect(lateNote("2026-11-09", "2026-11-08")).toBe(""); | |
| 57 | }); |
src/week.ts +7 −1
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | * within the next seven days, oldest first, then by address. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | import { addDays, spoken } from "./dates.ts"; | |
| 6 | import { addDays, daysBetween, spoken } from "./dates.ts"; | |
| 7 | 7 | import { appointmentLine, isAppointment } from "./appointment.ts"; |
| 8 | 8 | import { closingWhere } from "./closing.ts"; |
| 9 | 9 | import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; |
| @@ -77,6 +77,12 @@ export function owner( | ||
| 77 | 77 | return { name: deal.parties.find((p) => p.role === d.owes)?.name, role: PARTY_LABEL[d.owes] }; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | /** "due Fri, Nov 6 · 2 days late" for a date overdue on `on`; "" for one due today or later. */ | |
| 81 | export function lateNote(due: string, on: string): string { | |
| 82 | const days = daysBetween(due, on); | |
| 83 | return days < 1 ? "" : `due ${spoken(due)} · ${days} ${days === 1 ? "day" : "days"} late`; | |
| 84 | } | |
| 85 | ||
| 80 | 86 | /** The day heading a date sits under: overdue ones share one. */ |
| 81 | 87 | const dayHeading = (due: string, on: string): string => |
| 82 | 88 | due < on ? "Overdue" : due === on ? "Today" : spoken(due); |
new above
offline