feat: multi-farm polygon management#37
Conversation
- Added a required 'Field Name' text input above the map - Validation prevents confirming a polygon without a name - onPolygonComplete callback now includes fieldName in the payload - Map instructions updated to reflect the new flow - Component resets name and polygon after each confirmed field so multiple fields can be drawn back-to-back without a page reload
- Added Field interface to Farm type covering id, name, area, polygon coords - Replaced polygonData state with pendingField (includes fieldName) - handleSavePolygon replaced by handleAddField (calls addFarmField API) and handleDeleteField (calls deleteFarmField API) - Map tab renamed 'Field Manager' with an updated subtitle - Pending field confirm panel shows field name, area, discard/save buttons - Saved fields list renders below the mapper with coloured dot per field, name, area, and a Remove button with loading state per field - Farm cards in Farms tab now show field count when fields exist - FIELD_COLORS palette constant added for consistent colour cycling - Removed any cast in error handlers; using err instanceof Error pattern
- Each named field gets a distinct colour from the FIELD_COLORS palette - Field popups show field name, area in acres/ha, and parent farm name - Legacy farm.location.polygon still renders for backwards compatibility (only shown when a farm has no named fields yet) - Farm marker position derived from first field centre, then legacy polygon centroid, then explicit lat/lng — graceful fallback chain - Removed unused showAllFields prop; all fields always shown when present - Error handling uses err instanceof Error instead of any cast
TypeScript: - Extract FIELD_COLORS into frontend/src/utils/mapUtils.ts so Dashboard and FarmMap share a single source of truth (no duplication) - Remove unused showInstructions prop from PolygonMapper - Remove unused locationLoading state from PolygonMapper - Import FIELD_COLORS from mapUtils in Dashboard and FarmMap Python: - Add explicit return type annotation (-> dict) to get_fields, add_field, and delete_field endpoints - Add user: dict type annotation on the Depends(verify_token) parameter in all three field endpoints - Reformat long chained Supabase calls onto multiple lines (PEP 8) - Add current_loc: dict and current_fields: list local type annotations
The hook uses isComplete: points.length >= 4 (by design — a rectangle needs 4 corners). Updated all UI copy that said '3+' to say '4', and fixed the 'Drop X more pins' counter which was subtracting from 3 instead of 4.
|
@Shade555 is attempting to deploy a commit to the karan3431's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
🎉 Thanks for your contribution, @Shade555! Please make sure CI passes and the checklist in the PR template is complete. A maintainer will review this soon. — The AgroNavis team |
|
their is merge conflict in the main.py pull the all latest changes and fix the issue if persists. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@jpdevhub pulled the latest changes, the conflict is resolved now |
|
I will be fixing and merging tonight. Thanks for contribution. |
|
Hey Shade555! We had a small Git hiccup on our end and had to revert the main branch, which accidentally closed this PR. Your code is perfect! Could you please open a brand new PR from your feat/multi-farm-polygon-management branch? It will pass the CI checks now and I will merge it immediately! |
Title:
Description:
Summary
Allows a single farmer to draw and manage multiple distinct named field polygons (e.g. "Wheat Field", "Rice Paddy") per farm, backed by a dedicated database table.
Related Issue
Closes #23
Changes
Database
farm_fieldstable (id,farm_id,name,area_acres,area_hectaresgenerated,polygonJSONB,center_latitude,center_longitude,created_at,updated_at)farm_idfor fast field lookups, partial index on centre coordinatestrg_sync_farm_total_areaauto-updatesfarms.total_areaon any field insert/update/delete — no application-level bookkeeping neededfarms.location.fieldsinto the new tablebackend/supabase/migrations/20260607000000_farm_fields_table.sqlBackend (
backend/main.py)GET /api/farms/{id}/fieldsto queryfarm_fieldstable directlyPOST /api/farms/{id}/fieldsto insert intofarm_fieldstableDELETE /api/farms/{id}/fields/{field_id}to delete fromfarm_fieldstabletotal_arearecalculation (now handled by DB trigger)FieldResponsePydantic model for typed field responsesarea_hectaresfromFieldCreate(now a generated column in DB)owned.data[0][0]→owned.data[0]) in old field endpointsres.data.get()bug on list type inget_fields-> dictreturn type annotations anduser: dictparameter type on all three field endpointsFrontend
PolygonMapper(frontend/src/components/map/PolygonMapper.tsx):onPolygonCompletecallback now includesfieldNamein the payloadusePolygonAreahook thresholdshowInstructionsprop andlocationLoadingstateDashboard Field Manager tab (
frontend/src/components/Dashboard.tsx):fields: Field[]state loaded fromGET /api/farms/{id}/fieldshandleSavePolygon(which calledupdateFarm) withhandleAddField(callsaddFarmField) andhandleDeleteField(callsdeleteFarmField)farm.location.fieldsJSONB reads — all field data now comes from the APIPolygonMapperFarmMap(frontend/src/components/FarmMap.tsx):GET /api/farms/{id}/fields(new table) instead of readingfarm.location.fieldsFIELD_COLORSpalettefarms.location.polygonstill renders for farms with no named fields yet (backwards compatible)showAllFarmsis truefrontend/src/utils/mapUtils.ts(new file):FIELD_COLORSpalette into a shared utility soDashboardandFarmMapuse the same coloursTesting
Tested locally (describe steps)
npm run devfrom the project rootGET /api/farms/{id}/fieldsin FastAPI docs (http://localhost:8000/docs) that fields are stored in thefarm_fieldstablefarms.total_areain Supabase Studio (http://127.0.0.1:54323) matches the sum of field areasChecklist
.envvalues are committed