D7: read-only schedule grid UI (rows=instances, cols=positions, week nav)
Server-component schedule page backed by a pure data layer (src/db/grid.ts): gridForWeek() returns positions + instances (->slots->assignments), and defaultWeekStart() defaults to the earliest upcoming published instance so a seeded DB shows data on first load. Week nav via ?week=YYYY-MM-DD (server rendered, no client state). Fixes two latent bugs that kept the grid empty/incorrect: - tz: weekdayInTz()/nextSundaysInTz() built Date.UTC(y,mo-1,d) from a LOCAL date string and read its weekday; for America/New_York (UTC-5) UTC midnight lands the previous evening, so the seed materialized instances on Mondays and the default week was off by one. weekdayInTz now builds the local-midnight instant via utcOffsetMs; nextSundaysInTz uses weekdayInTz + addDaysISO. - grid: occursOn (date mode) was run through dateInTimezone(), reinterpreting the UTC instant as wall-clock and shifting a day early; now extracts the UTC calendar date directly (occursOnISO). - schedule-grid: <table className=... collapse ...> set visibility: collapse (Tailwind 'collapse'), hiding the whole grid server-rendered-but-invisible; changed to border-collapse. E2E: new schedule-grid.spec.ts + shell.spec.ts grid assertion. Full suite green: tsc, eslint, 178 unit tests, next build, 6/6 Playwright.
This commit is contained in:
@@ -566,6 +566,42 @@ Build log for Media Team Hub. One unit per commit, top to bottom. Append after e
|
||||
|
||||
---
|
||||
|
||||
## D7 — Read-only grid UI — DONE 2026-11-18
|
||||
|
||||
**Scope (from BUILD-PLAN.md):** Grid UI, read-only: rows = instances, cols = positions, week nav. Done when: E2E renders a seeded week; no console errors. Depends on D1–D6 (all committed).
|
||||
|
||||
**Status:** DONE. All code written; typecheck + eslint + unit (178) + `next build` green; **full Playwright E2E green (6/6)** and committed. Two further latent bugs were found and fixed this session (see Decisions/Blockers).
|
||||
|
||||
**Delivered:**
|
||||
- `src/lib/tz.ts` — added `CHURCH_TIMEZONE`, `addDaysISO(dateStr, days)` (calendar-safe ISO ± days), `weekStartOn(dateStr, tz)` (Sunday of the week containing a date). **Fixed a pre-existing bug:** `weekdayInTz()` returned `undefined` because `partsInTz()` never emitted a `weekday` part; added `weekday: "short"` to its Intl format and made `weekdayInTz` return `WEEKDAYS.indexOf(label)` (0=Sun..6=Sat). This also corrects `nextSundaysInTz`, which relied on the same missing part (seed was producing instances on wrong dates).
|
||||
- **Fixed a second latent bug (this session):** `weekdayInTz()` and `nextSundaysInTz()` both built `new Date(Date.UTC(y, mo-1, d))` from a *local* date string and read its weekday — for a negative-offset zone like `America/New_York`, UTC midnight lands on the *previous* evening, so the weekday (and thus the seed's Sundays and the grid's default week) was off by one. The seed had materialized instances on **Mondays** (11-23/11-30) instead of Sundays. `weekdayInTz` now builds the instant for **local** midnight via `utcOffsetMs`; `nextSundaysInTz` now uses `weekdayInTz` + the calendar-safe `addDaysISO`. Verified: today Wed 2026-11-18 → next Sundays 2026-11-22 / 2026-11-29; `weekStartOn("2026-11-18")` = 2026-11-15.
|
||||
- `src/db/grid.ts` — pure data layer for the grid. `gridForWeek(weekStart)` returns `{ weekStart, weekEnd, positions[], instances[] }` (instances → slots → assignments → user display names). `defaultWeekStart()` returns the Sunday of the earliest upcoming published instance so a seeded DB shows data on first load. `occursOn` is a `date`-mode column → returned as a UTC-midnight instant; the grid now extracts the **UTC calendar date directly** (`occursOnISO`, via `getUTCFullYear/getUTCMonth/getUTCDate`) instead of running it through `dateInTimezone(...)` (which reinterprets the UTC instant as wall-clock and shifts a day early in negative-offset zones). `gridForWeek` filters `gte`/`lte` on `Date` objects (UTC midnight).
|
||||
- `src/components/app/week-nav.tsx` — prev/next week anchor links to `?week=YYYY-MM-DD` (server-rendered, no client state).
|
||||
- `src/components/app/schedule-grid.tsx` — semantic `<table>`: header row = active positions (by sortOrder), one row per instance, each cell = slot (assigned volunteer + status badge, or "Open", trainee slots shown as shadow). Empty state via `StateMessage`.
|
||||
- **Fixed a bug (this session):** the `<table>` used the Tailwind class `collapse`, which sets `visibility: collapse` (hides the whole table) — the grid rendered server-side but was invisible in the browser, so E2E saw an empty grid. Changed to `border-collapse` (the intended border-collapsing utility).
|
||||
- `src/app/(app)/schedule/page.tsx` — replaced the placeholder. Async server component, `searchParams: Promise<{ week?: string }>`. Validates `?week=`, falls back to `defaultWeekStart()`, fetches and renders nav + grid.
|
||||
- `e2e/schedule-grid.spec.ts` — new: renders a seeded week, asserts role column headers + an instance row + prev/next nav, captures console + page errors and fails if any. Week-nav test asserts URL + re-render.
|
||||
- `e2e/shell.spec.ts` — updated the schedule assertion from the old placeholder ("Nothing scheduled yet") to the grid (role headers + service name).
|
||||
|
||||
**Verification (all green):**
|
||||
- `tsc --noEmit` ✓ · `eslint .` ✓ · `vitest run` ✓ (**178** tests, 21 files) · `next build` ✓.
|
||||
- **Playwright E2E: 6/6 passing** — `e2e/schedule-grid.spec.ts` (2) + `e2e/shell.spec.ts` (4, incl. health + unauth redirect).
|
||||
- Live `/schedule` renders the seeded week `2026-11-22 – 2026-11-28` with Audio/Livestream/Slides columns and both Sunday services; label reads `Sun, Nov 22 · Sunday 9:00 AM`.
|
||||
- DB re-seeded after the tz fix (reset instances/slots/assignments): 4 instances on Sundays (11-22, 11-29) / 12 slots / 12 assignments / 3 roles.
|
||||
|
||||
**Decisions:**
|
||||
- **Read-only grid = server component, no API route.** A read-only grid doesn't need a client data layer; the page queries `src/db/grid.ts` directly and renders. D8 (mutate) will add its own client + routes.
|
||||
- **Week nav via URL param, not client state.** `?week=YYYY-MM-DD` survives reload/share and needs no JS — simplest robust approach for a read-only grid.
|
||||
- **Default week = earliest upcoming published instance.** So a freshly seeded DB shows data immediately instead of an empty state.
|
||||
- **`occursOn` compared as `Date`, not string.** The column is `date({ mode: "date" })`; `gte`/`lte` take `Date` objects (UTC midnight). Returned to the UI as the **UTC calendar date** (`occursOnISO`), not `dateInTimezone(...)` — reinterpreting the UTC instant as wall-clock shifts a day early in negative-offset zones.
|
||||
- **Fixed `weekdayInTz` rather than working around it.** `weekStartOn` needs the weekday; the underlying `partsInTz` gap was a latent bug affecting the seed too, so fixing it at the source is correct. The UTC-midnight reconstruction bug was the same class of issue and is fixed the same way (build the local-midnight instant).
|
||||
|
||||
**Blockers found (now resolved):**
|
||||
- `RangeError: Invalid time value` on `/schedule` was drizzle serializing an `Invalid Date` from `defaultWeekStart()`, which returned `NaN-NaN-NaN` because `weekdayInTz()` returned `undefined` (no `weekday` part in `partsInTz`). Fixed by adding `weekday: "short"` to `partsInTz` and returning `WEEKDAYS.indexOf(label)`.
|
||||
- **`collapse` Tailwind class hid the grid.** `<table className="min-w-full collapse text-sm">` set `visibility: collapse` — the grid rendered server-side (curl confirmed) but was invisible in the browser, so E2E saw an empty grid. Changed to `border-collapse`.
|
||||
|
||||
---
|
||||
|
||||
## D1 — Service CRUD + `expandRRULE()` — DONE 2026-11-18
|
||||
|
||||
**Scope (from BUILD-PLAN.md):** service CRUD + `expandRRULE()` (weekly / biweekly / monthly-nth). Done when: `pnpm test recurrence` green on 5 named cases — spring-forward Sunday, fall-back Sunday, monthly-nth across a year boundary, cancelled instance not regenerated, biweekly phase stable. ARCHITECTURE §4.3 / §5.1 / §5.8.3.
|
||||
|
||||
Reference in New Issue
Block a user