Skip to content

Add button in atlases to be able to focus on the farm fields#506

Merged
SvenVw merged 9 commits into
developmentfrom
atlas-fly-to-fields
Mar 12, 2026
Merged

Add button in atlases to be able to focus on the farm fields#506
SvenVw merged 9 commits into
developmentfrom
atlas-fly-to-fields

Conversation

@BoraIneviNMI
Copy link
Copy Markdown
Collaborator

@BoraIneviNMI BoraIneviNMI commented Mar 11, 2026

Enhancements

  • Users get an option to focus the atlas onto their farm fields.
  • Newly selected fields are also included in the focus area if the user is currently creating new fields.

Summary by CodeRabbit

  • New Features
    • Atlas can be focused onto farm fields via a new fly-to control.
    • Fly-to control appears when fields exist across atlas views (fields, soil, elevation, and field creation).
    • Newly selected fields are included during field creation so the focus reflects selections.
    • Fly-to resets the view to the initial state and fits the map bounds to the combined field area.

@sentry
Copy link
Copy Markdown

sentry Bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@BoraIneviNMI BoraIneviNMI self-assigned this Mar 11, 2026
@BoraIneviNMI
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 11, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 83a3ba72-32d4-4363-b0c5-687c0e42c366

📥 Commits

Reviewing files that changed from the base of the PR and between c9ee50f and c5a5549.

📒 Files selected for processing (1)
  • fdm-app/app/components/blocks/atlas/atlas-controls.tsx

📝 Walkthrough

Walkthrough

Refactors atlas controls into a composable AtlasControls system and adds a "fly to fields" capability: Controls now accept showFlyToFields and onFlyToFields; multiple atlas and field routes attach a MapRef and implement handlers that reset viewState and fit map bounds to field features.

Changes

Cohort / File(s) Summary
Release notes
.changeset/brave-kiwis-wash.md
Adds release entry documenting the atlas focus-on-farm-fields feature.
Atlas controls refactor
fdm-app/app/components/blocks/atlas/atlas-controls.tsx
Replaces legacy inline controls with an AtlasControls composition, new AtlasButton/AtlasToggle and SingleAtlasButton/SingleAtlasToggle wrappers; exposes AtlasControls, SingleAtlasButton, SingleAtlasToggle; updates ControlsProps to include showFlyToFields?: boolean and onFlyToFields?: () => void; removes old ControlButton and CONTROL_OPTIONS.
Atlas route fly-to handlers
fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.elevation.tsx, fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.soil.tsx
Enable showFlyToFields when fields exist and add onFlyToFields that resets viewState and fits map bounds via map reference.
Field routes: mapRef & fly-to
fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.fields._index.tsx, fdm-app/app/routes/farm.$b_id_farm.$calendar.field.new._index.tsx
Attach mapRef to MapGL, add mapRef typings, compute visibility from saved/selected fields, implement showFlyToFields and onFlyToFields to merge features, set viewState, and call fitBounds.
Farm creation atlas
fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
Adds mapRef, combines saved and selected fields to compute overall view, updates viewState, and calls fitBounds with computed bounds and options.

Sequence Diagram(s)

sequenceDiagram
  participant User as "User"
  participant Controls as "AtlasControls\n(Controls)"
  participant Map as "MapGL / Map Component"
  participant MapRef as "MapRef (maplibre)\nfitBounds"

  User->>Controls: Click "Fly to fields"
  Controls->>Map: reset viewState / compute combined bounds
  Controls->>MapRef: call fitBounds(bounds, options)
  MapRef-->>Map: update camera / viewport
  Map-->>Controls: new viewState applied
  Controls-->>User: map centered on fields
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

fdm-app, enhancement, branch:development

Suggested reviewers

  • SvenVw
  • gerardhros

Poem

🐰 I hopped on a button, clicked "fly" with delight,
The atlas woke up and swept fields into sight.
From saved plots to new lines, the map snugly aligns,
I twitched my whiskers—now all the bounds fit just right. 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a button/feature to focus atlas views on farm fields, which matches the PR's core objective and the implemented FlyToFieldsControl.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch atlas-fly-to-fields

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx (1)

263-291: ⚠️ Potential issue | 🔴 Critical

MapGL component is missing the ref prop.

The mapRef is created but never passed to the MapGL component. Without ref={mapRef}, the mapRef.current?.fitBounds() call at line 327 will always be a no-op since mapRef.current will remain null.

🐛 Proposed fix
                             <MapGL
                                 {...viewState}
+                                ref={mapRef}
                                 style={{
                                     height: "calc(100vh - 64px - 147px)",
                                     width: "100%",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fdm-app/app/routes/farm.create`.$b_id_farm.$calendar.atlas.tsx around lines
263 - 291, The MapGL instance never receives the mapRef, so mapRef.current stays
null and calls like mapRef.current?.fitBounds() do nothing; update the MapGL JSX
to include ref={mapRef} (the ref created earlier) so the MapGL component is
wired to the existing mapRef used elsewhere (e.g., the fitBounds call at line
327); ensure the ref type matches the MapGL/MapRef expected by the component and
leave other handlers (onMove/onClick/handleClickSavedField) unchanged.
🧹 Nitpick comments (1)
fdm-app/app/components/blocks/atlas/atlas-controls.tsx (1)

132-136: Minor typo in documentation.

Line 135 has a typo: "tall" should be "tell".

📝 Proposed fix
 /**
  * React root that can be added to a react-map-gl Map to include buttons etc. on it
  *
- * - position will tall MapGL where to put the controls
+ * - position will tell MapGL where to put the controls
  */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fdm-app/app/components/blocks/atlas/atlas-controls.tsx` around lines 132 -
136, Update the JSDoc comment in atlas-controls.tsx: change the typo "tall" to
"tell" in the block describing the React root/MapGL controls so the sentence
reads "position will tell MapGL where to put the controls"; locate the comment
near the React root description in the atlas controls component and correct the
single word.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@fdm-app/app/routes/farm.create`.$b_id_farm.$calendar.atlas.tsx:
- Around line 229-230: The file is missing imports for useRef and MapRef causing
build failure; add useRef to the React import (e.g., import React, { useRef }
from 'react') and import MapRef from 'react-map-gl' (e.g., import type { MapRef
} from 'react-map-gl') so the mapRef declaration const mapRef =
useRef<MapRef>(null) resolves correctly; update the existing React and
react-map-gl import blocks to include these symbols.
- Around line 318-332: The onFlyToFields handler uses featureCollection but the
symbol is not imported; update the `@turf/turf` import to include
featureCollection (the code using it is inside onFlyToFields which builds a
combined featureCollection from fieldsSaved.features and
selectedFieldsData.features, computes overallViewState via getViewState, calls
setViewState and mapRef.current?.fitBounds). Add featureCollection to the
existing import alongside simplify so the identifier resolves and the
onFlyToFields logic works.

---

Outside diff comments:
In `@fdm-app/app/routes/farm.create`.$b_id_farm.$calendar.atlas.tsx:
- Around line 263-291: The MapGL instance never receives the mapRef, so
mapRef.current stays null and calls like mapRef.current?.fitBounds() do nothing;
update the MapGL JSX to include ref={mapRef} (the ref created earlier) so the
MapGL component is wired to the existing mapRef used elsewhere (e.g., the
fitBounds call at line 327); ensure the ref type matches the MapGL/MapRef
expected by the component and leave other handlers
(onMove/onClick/handleClickSavedField) unchanged.

---

Nitpick comments:
In `@fdm-app/app/components/blocks/atlas/atlas-controls.tsx`:
- Around line 132-136: Update the JSDoc comment in atlas-controls.tsx: change
the typo "tall" to "tell" in the block describing the React root/MapGL controls
so the sentence reads "position will tell MapGL where to put the controls";
locate the comment near the React root description in the atlas controls
component and correct the single word.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fbec3b85-e30b-4ce5-8b10-81cfb8ad0a59

📥 Commits

Reviewing files that changed from the base of the PR and between 4005748 and 63fd7b8.

📒 Files selected for processing (7)
  • .changeset/brave-kiwis-wash.md
  • fdm-app/app/components/blocks/atlas/atlas-controls.tsx
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.elevation.tsx
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.fields._index.tsx
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.atlas.soil.tsx
  • fdm-app/app/routes/farm.$b_id_farm.$calendar.field.new._index.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx

Comment thread fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
Comment thread fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
fdm-app/app/components/blocks/atlas/atlas-controls.tsx (1)

170-187: Consider adding aria-label for improved accessibility.

The button uses title for the tooltip, which provides hover text but limited screen reader support. Adding aria-label={props.label} would improve accessibility for assistive technologies.

♿ Proposed accessibility improvement
         <button
             className="maplibregl-ctrl-icon flex items-center justify-center p-0!"
             type="button"
             title={props.label}
+            aria-label={props.label}
             onClick={(e) => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fdm-app/app/components/blocks/atlas/atlas-controls.tsx` around lines 170 -
187, The AtlasButton component currently only sets title for the button which is
not reliably read by screen readers; update the JSX for the button in
AtlasButton to add aria-label={props.label} (or a fallback string when
props.label is undefined) alongside the existing title, ensuring the accessible
name comes from props.label and remains consistent with props.Icon usage and the
onClick behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@fdm-app/app/components/blocks/atlas/atlas-controls.tsx`:
- Around line 170-187: The AtlasButton component currently only sets title for
the button which is not reliably read by screen readers; update the JSX for the
button in AtlasButton to add aria-label={props.label} (or a fallback string when
props.label is undefined) alongside the existing title, ensuring the accessible
name comes from props.label and remains consistent with props.Icon usage and the
onClick behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4749ed9b-bc35-4bce-be68-52317fd5e431

📥 Commits

Reviewing files that changed from the base of the PR and between 63fd7b8 and c9ee50f.

📒 Files selected for processing (2)
  • fdm-app/app/components/blocks/atlas/atlas-controls.tsx
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • fdm-app/app/routes/farm.create.$b_id_farm.$calendar.atlas.tsx

@BoraIneviNMI BoraIneviNMI requested a review from SvenVw March 11, 2026 16:03
Copy link
Copy Markdown
Collaborator

@SvenVw SvenVw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@SvenVw SvenVw merged commit c9fe671 into development Mar 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants