PR: #512: feat(brief): wire field-history timeline to frame-versions [Story-2025] by @ankitmaheshwari-com
View PR →

Files changed

9 file(s), +236 / -8 lines

Path Role + -
src/app/[locale]/(workspace)/matters/[matterId]/page.tsxApp route+5-0
src/app/api/internal/matters/[matterId]/frame/versions/route.tsApp route+32-0
src/components/matter-detail/brief/matter-brief-page.tsxComponent+6-3
src/components/matter-detail/brief/matter-brief-sections.tsxComponent+24-4
src/components/matter-detail/brief/presentation.test.tsComponent+80-0
src/components/matter-detail/brief/presentation.tsComponent+36-1
src/components/matter-detail/brief/use-field-versions.tsComponent+24-0
src/lib/kubb-client.tsLibrary+12-0
src/lib/matters/gateway.tsLibrary+17-0

Story-2025: wire the Brief field-history timeline to frame/versions

The Brief's per-field history control (the gutter History popover, the full-history modal, ⌘Z/⌘⇧Z, and Restore this version) used to show a single, current-only row: the brief payload carries only the newest frame version, so fieldVersionStack was an honest one-entry stub. The backend now serves the full append-only history at GET /app/matters/{id}/frame/versions (MatterFrameVersionHistoryResponse, newest-first). This story wires the timeline to that endpoint so every field shows its real multi-version history.

The read path (forum pattern)

Mapping a version page to a field's stack

useFieldVersions(matterId, field, fallback) reads the shared versions query (TanStack dedupes the four call sites on the page into one request) and maps it with the pure mapFieldVersions(items, field) helper:

Wiring

matterId threads from matter-brief-page.tsx (matter.matterId) into BriefHeader (frame_summary) and the EditableFields (core_dispute, theory_of_case, settlement_posture). Each builds its versions from useFieldVersions instead of the sync stub. The EditableFieldWithHistory presentation component is unchanged — it already renders any newest-first SummaryVersion[], so undo/redo and Restore work across the real versions for free.

Verification

pnpm lint (0 errors), pnpm build (green; the new /api/internal/matters/[matterId]/frame/versions route is registered), and a new presentation.test.ts covering mapFieldVersions (order, dedupe/drop-empty, agent-vs-counsel authors, flattened-envelope fallback) all pass.