Add period history UI with CRUD operations
All checks were successful
Deploy / deploy (push) Successful in 2m27s

- Add GET /api/period-history route with pagination, cycle length
  calculation, and prediction accuracy tracking
- Add PATCH/DELETE /api/period-logs/[id] routes for editing and
  deleting period entries with ownership validation
- Add /period-history page with table view, edit/delete modals,
  and pagination controls
- Include 61 new tests covering all functionality

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 22:33:36 +00:00
parent 6e391a46be
commit 07577dbdbb
7 changed files with 2278 additions and 30 deletions

View File

@@ -4,7 +4,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
## Current State Summary
### Overall Status: 889 tests passing across 46 test files
### Overall Status: 950 tests passing across 49 test files
### Library Implementation
| File | Status | Gap Analysis |
@@ -31,7 +31,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
| OIDC Authentication | specs/authentication.md | P2.18 | **COMPLETE** |
| Token Expiration Warnings | specs/email.md | P3.9 | **COMPLETE** |
### API Routes (15 route files, 18 HTTP endpoints)
### API Routes (18 route files, 21 HTTP endpoints)
| Route | Status | Notes |
|-------|--------|-------|
| POST /api/auth/logout | **COMPLETE** | Clears pb_auth cookie, logs out user (5 tests) |
@@ -50,10 +50,13 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
| POST /api/cron/garmin-sync | **COMPLETE** | Syncs Garmin data for all users, creates DailyLogs, sends token expiration warnings (32 tests) |
| POST /api/cron/notifications | **COMPLETE** | Sends daily emails with timezone matching, DailyLog handling (20 tests) |
| GET /api/history | **COMPLETE** | Paginated historical daily logs with date filtering (19 tests) |
| GET /api/period-history | **COMPLETE** | Paginated period logs with cycle lengths and average (18 tests) |
| PATCH /api/period-logs/[id] | **COMPLETE** | Edit period log startDate (10 tests) |
| DELETE /api/period-logs/[id] | **COMPLETE** | Delete period log with user.lastPeriodDate update (6 tests) |
| GET /api/health | **COMPLETE** | Health check for deployment monitoring (14 tests) |
| GET /metrics | **COMPLETE** | 33 tests (18 lib + 15 route) |
### Pages (7 total)
### Pages (8 total)
| Page | Status | Notes |
|------|--------|-------|
| Dashboard (`/`) | **COMPLETE** | Wired with /api/today, DecisionCard, DataPanel, NutritionPanel, OverrideToggles |
@@ -62,6 +65,7 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
| Settings/Garmin (`/settings/garmin`) | **COMPLETE** | Token management UI, connection status, disconnect functionality, 27 tests |
| Calendar (`/calendar`) | **COMPLETE** | MonthView with navigation, ICS subscription section, token regeneration, 23 tests |
| History (`/history`) | **COMPLETE** | Table view with date filtering, pagination, decision styling, 26 tests |
| Period History (`/period-history`) | **COMPLETE** | Period log table with edit/delete, cycle lengths, average, prediction accuracy, 27 tests |
| Plan (`/plan`) | **COMPLETE** | Phase overview, training guidelines, rebounding techniques, 16 tests |
### Components
@@ -107,8 +111,11 @@ This file is maintained by Ralph. Run `./ralph-sandbox.sh plan 3` to generate ta
| `src/app/api/calendar/[userId]/[token].ics/route.test.ts` | **EXISTS** - 11 tests (token validation, ICS generation with period prediction feedback, caching, error handling) |
| `src/app/api/calendar/regenerate-token/route.test.ts` | **EXISTS** - 9 tests (token generation, URL formatting, auth) |
| `src/app/api/history/route.test.ts` | **EXISTS** - 19 tests (pagination, date filtering, auth, validation) |
| `src/app/api/period-history/route.test.ts` | **EXISTS** - 18 tests (pagination, cycle length calculation, average, auth) |
| `src/app/api/period-logs/[id]/route.test.ts` | **EXISTS** - 16 tests (PATCH edit, DELETE with user update, auth, validation) |
| `src/app/api/health/route.test.ts` | **EXISTS** - 14 tests (healthy/unhealthy states, PocketBase connectivity, error handling) |
| `src/app/history/page.test.tsx` | **EXISTS** - 26 tests (rendering, data loading, pagination, date filtering, styling) |
| `src/app/period-history/page.test.tsx` | **EXISTS** - 27 tests (rendering, edit/delete modals, pagination, prediction accuracy) |
| `src/app/api/metrics/route.test.ts` | **EXISTS** - 15 tests (Prometheus format validation, metric types, route handling) |
| `src/components/calendar/month-view.test.tsx` | **EXISTS** - 30 tests (calendar grid, phase colors, navigation, legend, keyboard navigation) |
| `src/app/calendar/page.test.tsx` | **EXISTS** - 23 tests (rendering, navigation, ICS subscription, token regeneration) |
@@ -868,12 +875,12 @@ P4.* UX Polish ────────> After core functionality complete
| Done | P4.4 Loading Performance | Complete | Next.js loading.tsx provides 100ms target |
| Done | P4.5 Period Prediction | Complete | Prediction tracking with feedback loop |
| Done | P4.6 Rate Limiting | Complete | Client-side rate limiting implemented |
| **Medium** | P5.1 Period History UI | Medium | New page + 3 API routes |
| Done | P5.1 Period History UI | Complete | Page + 3 API routes with 61 tests |
| **Low** | P5.2 Toast Notifications | Low | Install library + integrate |
| **Low** | P5.3 CI Pipeline | Low | Single workflow file |
| **Low** | P5.4 E2E Tests | Medium | 6 missing test files |
**All P0-P4 items are complete. P5 contains remaining gaps identified during gap analysis (2026-01-12).**
**All P0-P4 items are complete. P5.1 complete. Remaining P5 items: Toast Notifications, CI Pipeline, E2E Tests.**
@@ -914,7 +921,7 @@ P4.* UX Polish ────────> After core functionality complete
- [x] **MonthView** - Calendar grid with DayCell integration, navigation controls (prev/next month, Today button), phase legend, 21 tests
- [x] **MiniCalendar** - Compact calendar widget with phase colors, navigation, legend, 23 tests (P2.14)
### API Routes (18 complete)
### API Routes (21 complete)
- [x] **POST /api/auth/logout** - Clears session cookie, logs user out, 5 tests
- [x] **GET /api/user** - Returns authenticated user profile, 4 tests (P0.4)
- [x] **PATCH /api/user** - Updates user profile (cycleLength, notificationTime, timezone), 17 tests (P1.1)
@@ -931,16 +938,20 @@ P4.* UX Polish ────────> After core functionality complete
- [x] **GET /api/calendar/[userId]/[token].ics** - Returns ICS feed with 90-day phase events and period prediction feedback, token validation, caching headers, 11 tests (P2.6, P4.5)
- [x] **POST /api/calendar/regenerate-token** - Generates new 32-char calendar token, returns URL, 9 tests (P2.7)
- [x] **GET /api/history** - Paginated historical daily logs with date filtering, validation, 19 tests (P2.8)
- [x] **GET /api/period-history** - Paginated period logs with cycle length calculation and average, 18 tests (P5.1)
- [x] **PATCH /api/period-logs/[id]** - Edit period log startDate with validation, 10 tests (P5.1)
- [x] **DELETE /api/period-logs/[id]** - Delete period log with user.lastPeriodDate update, 6 tests (P5.1)
- [x] **GET /api/health** - Health check endpoint with PocketBase connectivity check, 14 tests (P2.15)
- [x] **GET /metrics** - Prometheus metrics endpoint with counters, gauges, histograms, 33 tests (18 lib + 15 route) (P2.16)
### Pages (7 complete)
### Pages (8 complete)
- [x] **Login Page** - OIDC (Pocket-ID) with email/password fallback, error handling, loading states, redirect, rate limiting, 32 tests (P1.6, P2.18, P4.6)
- [x] **Dashboard Page** - Complete daily interface with /api/today integration, DecisionCard, DataPanel, NutritionPanel, OverrideToggles, 23 tests (P1.7)
- [x] **Settings Page** - Form for cycleLength, notificationTime, timezone with validation, loading states, error handling, logout button, 34 tests (P2.9)
- [x] **Settings/Garmin Page** - Token input form, connection status, expiry warnings, disconnect functionality, 27 tests (P2.10)
- [x] **Calendar Page** - MonthView with navigation controls, ICS subscription section with URL display, copy button, token regeneration, 23 tests (P2.11)
- [x] **History Page** - Table view of DailyLogs with date filtering, pagination, decision styling, 26 tests (P2.12)
- [x] **Period History Page** - Table view of PeriodLogs with edit/delete modals, pagination, cycle length calculation, average cycle length, prediction accuracy display, 27 tests (P5.1)
- [x] **Plan Page** - Phase overview, training guidance, exercise reference, rebounding techniques, 16 tests (P2.13)
### Test Infrastructure
@@ -991,30 +1002,40 @@ Analysis of all specs vs implementation revealed these gaps:
These items were identified during gap analysis and remain pending.
### P5.1: Period History UI (PENDING)
- [ ] Create period history viewing and editing UI
### P5.1: Period History UI ✅ COMPLETE
- [x] Create period history viewing and editing UI
- **Spec Reference:** specs/cycle-tracking.md lines 93-111
- **Required Features:**
- List of all logged period dates
- Calculated cycle lengths between periods
- Average cycle length over time
- Ability to edit/delete entries
- **Current State:**
- `/history` page exists but shows DailyLogs (training history), not PeriodLogs
- No UI for viewing period history
- No API routes for editing/deleting PeriodLog entries
- **Implementation Tasks:**
1. Create GET /api/period-history route (paginated list of PeriodLogs with calculated cycle lengths)
2. Create PATCH /api/period-logs/[id] route (edit period start date)
3. Create DELETE /api/period-logs/[id] route (delete period entry)
4. Create `/period-history` page with table view
5. Add average cycle length calculation
6. Add edit/delete UI with confirmation dialogs
- **Files to Create:**
- `src/app/api/period-history/route.ts` + tests
- `src/app/api/period-logs/[id]/route.ts` + tests
- `src/app/period-history/page.tsx` + tests
- **Why:** Users need to view and correct their period log history
- **Implementation Details:**
- **GET /api/period-history** - Paginated list of period logs with cycle length calculations (18 tests)
- Returns items with startDate, id, cycleLength (days since previous period)
- Calculates average cycle length across all periods
- Includes prediction accuracy metrics (totalPeriods, predictedCorrectly)
- Pagination with page/limit/totalPages/hasMore
- Sorts by startDate descending (most recent first)
- **PATCH /api/period-logs/[id]** - Edit period log startDate (10 tests)
- Validates startDate in YYYY-MM-DD format
- Prevents duplicate period dates
- Updates associated PeriodLog record
- Returns updated period log
- **DELETE /api/period-logs/[id]** - Delete period log (6 tests)
- Updates user.lastPeriodDate to most recent remaining period
- Handles deletion of last period log (sets lastPeriodDate to null)
- Requires authentication
- Returns 204 No Content on success
- **/period-history page** - Table view with edit/delete modals (27 tests)
- Table columns: Date, Cycle Length, Days Early/Late, Actions (Edit/Delete)
- Edit modal with date input and validation
- Delete confirmation modal with warning text
- Pagination controls with page numbers
- Displays average cycle length at top
- Shows prediction accuracy percentage
- Loading states and error handling
- **Files Created:**
- `src/app/api/period-history/route.ts` - API route with 18 tests
- `src/app/api/period-logs/[id]/route.ts` - API route with 16 tests (10 PATCH, 6 DELETE)
- `src/app/period-history/page.tsx` - Page component with 27 tests
- **Total Tests Added:** 61 tests (18 + 16 + 27)
- **Why:** Users need to view and correct their period log history per spec requirement
### P5.2: Toast Notifications (PENDING)
- [ ] Add toast notification system for user feedback