2.6 KiB
2.6 KiB
Carry Forward Feature - Implementation Complete
Overview
The carry-forward feature automatically populates form fields in the new report form with calculated values from the last report for the same location combination (Area, Dredger Location, and Reclamation Location).
Implementation Details
API Endpoint
File: app/routes/api.last-report-data.ts
Fetches the most recent report for a given location combination and calculates carry-forward values:
- Dredger Line Length: Same as last report
- Shore Connection: Same as last report
- Reclamation Height Base: (Base Height + Extra Height) from last report
- Pipeline Main: (Main + Extension 1) from last report
- Pipeline Reserve: (Reserve + Extension 2) from last report
Frontend Integration
File: app/routes/reports_.new.tsx
useEffect Hook
Added a useEffect that triggers when:
- User reaches Step 2
- All three location fields are selected (Area, Dredger Location, Reclamation Location)
The hook:
- Fetches last report data from the API
- Only updates fields that are still at their default values
- Preserves any user-modified values
User Experience
- Info message displayed in Step 2 explaining that values are auto-filled
- Users can modify any auto-filled values
- Only applies to fields that haven't been manually changed
- Gracefully handles cases where no previous report exists
Behavior
When Values Are Carried Forward
- User selects Area, Dredger Location, and Dredger Line Length in Step 1
- User moves to Step 2 and selects Reclamation Location
- System automatically fetches and populates:
- Dredger Line Length (if not already entered)
- Shore Connection (if empty)
- Reclamation Height Base (if still at default 0)
- Pipeline Main (if still at default 0)
- Pipeline Reserve (if still at default 0)
When Values Are NOT Carried Forward
- No previous report exists for the location combination
- User has already manually entered values
- API request fails (fails silently, doesn't block user)
Benefits
- Efficiency: Reduces data entry time for recurring locations
- Accuracy: Ensures continuity of measurements across shifts
- User-Friendly: Non-intrusive - users can still override any value
- Smart: Only updates fields that haven't been touched by the user
Technical Notes
- Uses GET request to
/api/last-report-datawith query parameters - Calculations performed server-side for data integrity
- Client-side state management prevents overwriting user input
- Error handling ensures feature doesn't break form functionality