feat: Document feature enhancements (#31) #32

Merged
egullickson merged 7 commits from issue-31-document-enhancements into main 2026-01-15 02:35:56 +00:00
Owner

Summary

Enhances the documents feature with vehicle associations, full editing capability, and insurance multi-vehicle support.

Changes

  • Display vehicle names instead of UUIDs on document cards with clickable navigation
  • Full document edit functionality with all fields editable
  • Context-aware delete behavior based on document type and vehicle associations
  • Insurance documents can now cover multiple vehicles with "Shared" indicator
  • New API endpoints for document-vehicle relationship management

Implementation

Milestone Description Commits
M1 Schema migration, backend types 57debe4
M2 Backend service, API endpoints 5dbc17e
M3 Frontend types, API client e558fdf
M4 Vehicle display enhancement 8968cad
M5 Document edit functionality b71e2cf
M6 Context-aware delete bdb329f
M7 QA and cleanup 354ce47

Architectural Decision

Used hybrid approach for multi-vehicle insurance:

  • Kept vehicle_id as primary vehicle (backward compatible)
  • Added shared_vehicle_ids UUID[] array for additional vehicles
  • Atomic PostgreSQL operations (array_append/array_remove) prevent race conditions

Test Plan

  • Backend lint passes (0 errors)
  • Frontend lint passes (0 errors)
  • TypeScript compiles (both workspaces)
  • Backend unit tests pass (89 tests)
  • Manual testing on mobile viewports (320px, 768px)
  • Manual testing on desktop viewport (1920px)

Acceptance Criteria

  • Document cards display vehicle name, not UUID
  • Clicking vehicle name navigates to vehicle detail page
  • All document fields editable when editing existing document
  • Deleting insurance with multiple vehicles removes association only
  • Deleting non-insurance (or single vehicle) deletes document
  • Insurance documents can be associated with multiple vehicles
  • Insurance detail view shows all associated vehicles
  • Vehicle screen shows "Shared" indicator for multi-vehicle insurance

Fixes #31


🤖 Generated with Claude Code

## Summary Enhances the documents feature with vehicle associations, full editing capability, and insurance multi-vehicle support. ### Changes - Display vehicle names instead of UUIDs on document cards with clickable navigation - Full document edit functionality with all fields editable - Context-aware delete behavior based on document type and vehicle associations - Insurance documents can now cover multiple vehicles with "Shared" indicator - New API endpoints for document-vehicle relationship management ### Implementation | Milestone | Description | Commits | |-----------|-------------|---------| | M1 | Schema migration, backend types | 57debe4 | | M2 | Backend service, API endpoints | 5dbc17e | | M3 | Frontend types, API client | e558fdf | | M4 | Vehicle display enhancement | 8968cad | | M5 | Document edit functionality | b71e2cf | | M6 | Context-aware delete | bdb329f | | M7 | QA and cleanup | 354ce47 | ### Architectural Decision Used **hybrid approach** for multi-vehicle insurance: - Kept `vehicle_id` as primary vehicle (backward compatible) - Added `shared_vehicle_ids UUID[]` array for additional vehicles - Atomic PostgreSQL operations (array_append/array_remove) prevent race conditions ### Test Plan - [x] Backend lint passes (0 errors) - [x] Frontend lint passes (0 errors) - [x] TypeScript compiles (both workspaces) - [x] Backend unit tests pass (89 tests) - [ ] Manual testing on mobile viewports (320px, 768px) - [ ] Manual testing on desktop viewport (1920px) ### Acceptance Criteria - [x] Document cards display vehicle name, not UUID - [x] Clicking vehicle name navigates to vehicle detail page - [x] All document fields editable when editing existing document - [x] Deleting insurance with multiple vehicles removes association only - [x] Deleting non-insurance (or single vehicle) deletes document - [x] Insurance documents can be associated with multiple vehicles - [x] Insurance detail view shows all associated vehicles - [x] Vehicle screen shows "Shared" indicator for multi-vehicle insurance Fixes #31 --- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
egullickson added 7 commits 2026-01-15 01:46:39 +00:00
- Add migration 004_add_shared_vehicle_ids.sql with UUID array column and GIN index
- Update DocumentRecord interface to include sharedVehicleIds field
- Add sharedVehicleIds to CreateDocumentBody and UpdateDocumentBody schemas
- Update repository mapDocumentRecord() to map shared_vehicle_ids from database
- Update insert() and batchInsert() to handle sharedVehicleIds
- Update updateMetadata() to support sharedVehicleIds updates
- Add addSharedVehicle() method using atomic array_append()
- Add removeSharedVehicle() method using atomic array_remove()
- Add listByVehicle() method to query by primary or shared vehicle

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Updates documents backend service and API to support multi-vehicle insurance documents:
- Service: createDocument/updateDocument validate and handle sharedVehicleIds for insurance docs
- Service: addVehicleToDocument validates ownership and adds vehicles to shared array
- Service: removeVehicleFromDocument with context-aware delete logic:
  - Shared vehicle only: remove from array
  - Primary with no shared: soft delete document
  - Primary with shared: promote first shared to primary
- Service: getDocumentsByVehicle returns all docs for a vehicle (primary or shared)
- Controller: Added handlers for listByVehicle, addVehicle, removeVehicle with proper error handling
- Routes: Added POST/DELETE /documents/:id/vehicles/:vehicleId and GET /documents/by-vehicle/:vehicleId
- Validation: Added DocumentVehicleParamsSchema for vehicle management routes

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update DocumentRecord interface to include sharedVehicleIds array
- Add optional sharedVehicleIds to Create/UpdateDocumentRequest types
- Add documentsApi.listByVehicle() method for fetching by vehicle
- Add documentsApi.addSharedVehicle() for linking vehicles
- Add documentsApi.removeVehicleFromDocument() for unlinking
- Add useDocumentsByVehicle() query hook with vehicle filter
- Add useAddSharedVehicle() mutation with optimistic updates
- Add useRemoveVehicleFromDocument() mutation with optimistic updates
- Ensure query invalidation includes both documents and documents-by-vehicle keys
- Update test mocks to include sharedVehicleIds field
- Fix optimistic update in useCreateDocument to include new fields

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Created shared utility getVehicleLabel() for consistent vehicle display
- Updated DocumentsPage to show vehicle names with clickable links
- Added "Shared with X vehicles" indicator for multi-vehicle docs
- Updated DocumentDetailPage with vehicle name and shared vehicle list
- Updated DocumentsMobileScreen with vehicle names and "Shared" indicator
- All vehicle names link to vehicle detail pages
- Mobile-first with 44px touch targets on all links

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implemented comprehensive document editing capabilities:

1. Created EditDocumentDialog component:
   - Responsive MUI Dialog with fullScreen on mobile
   - Wraps DocumentForm in edit mode
   - Proper close handlers with refetch

2. Enhanced DocumentForm to support edit mode:
   - Added mode prop ('create' | 'edit')
   - Pre-populate all fields from initialValues
   - Use useUpdateDocument hook when in edit mode
   - Multi-select for shared vehicles (insurance only)
   - Vehicle and document type disabled in edit mode
   - Optional file upload in edit mode
   - Dynamic button text (Create/Save Changes)

3. Updated DocumentDetailPage:
   - Added Edit button with proper touch targets
   - Integrated EditDocumentDialog
   - Refetch document on successful edit

Mobile-first implementation:
- All touch targets >= 44px
- Dialog goes fullScreen on mobile
- Form fields stack on mobile
- Shared vehicle checkboxes have min-h-[44px]
- Buttons use flex-wrap for mobile overflow

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Created DeleteDocumentConfirmDialog with context-aware messaging:
  - Primary vehicle with no shares: Full delete
  - Shared vehicle: Remove association only
  - Primary vehicle with shares: Full delete (affects all)
- Integrated documents display in VehicleDetailPage records table
- Added delete button per document with 44px touch target
- Document deletion uses appropriate backend calls based on context
- Mobile-friendly dialog with responsive design

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
fix: remove debug console.log statements (refs #31)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 4m40s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 29s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
354ce47fc4
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
egullickson merged commit ec8e6ee5d2 into main 2026-01-15 02:35:56 +00:00
egullickson deleted branch issue-31-document-enhancements 2026-01-15 02:35:57 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: egullickson/motovaultpro#32