Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

@google-labs-jules google-labs-jules bot commented Nov 13, 2025

User description

This change conditionally renders the Mapbox NavigationControl based on the current map mode. The zoom icons will now only appear when the user has activated the drawing tools, providing a cleaner and more intuitive user interface.


PR created automatically by Jules for task 16229590957999346687 started by @ngoiyaeric


PR Type

Enhancement


Description

  • Conditionally render Mapbox NavigationControl based on map mode

  • Navigation controls only display in DrawingMode

  • Removed unconditional NavigationControl initialization

  • Cleaner UI by hiding zoom icons in non-drawing modes


Diagram Walkthrough

flowchart LR
  mapType["Map Mode Changed"]
  check{"Is DrawingMode?"}
  add["Add NavigationControl"]
  remove["Remove NavigationControl"]
  mapType --> check
  check -->|Yes| add
  check -->|No| remove
Loading

File Walkthrough

Relevant files
Enhancement
mapbox-map.tsx
Conditional NavigationControl rendering based on map mode

components/map/mapbox-map.tsx

  • Added navigationControlRef to track NavigationControl instance
  • Moved NavigationControl initialization from map setup to
    mode-dependent logic
  • Added conditional logic to add/remove NavigationControl based on
    DrawingMode
  • NavigationControl now only displays when user enters DrawingMode
+14/-2   

The zoom icons on the map are now only displayed when the user is in 'DrawingMode'. This declutters the interface and improves the user experience by only showing the controls when they are relevant.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!


For security, I will only act on instructions from the user who triggered this task.

New to Jules? Learn more at jules.google/docs.

@vercel
Copy link

vercel bot commented Nov 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
qcx Ready Ready Preview Comment Nov 13, 2025 7:55pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ngoiyaeric ngoiyaeric marked this pull request as ready for review November 13, 2025 19:53
@qodo-code-review
Copy link
Contributor

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
No audit logs: The new logic that adds/removes the Mapbox NavigationControl based on map mode does not
record any audit/log entry for these critical UI control changes, making it unclear who
triggered the mode switch and its outcome.

Referred Code
// Handle navigation controls based on mode
if (mapType === MapToggleEnum.DrawingMode) {
  if (!navigationControlRef.current) {
    navigationControlRef.current = new mapboxgl.NavigationControl();
    map.current.addControl(navigationControlRef.current, 'top-left');
  }
} else {
  if (navigationControlRef.current) {
    map.current.removeControl(navigationControlRef.current);
    navigationControlRef.current = null;
  }
}

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Missing try/catch: Adding and removing the Mapbox NavigationControl is performed without guarding against
failures (e.g., map not ready, control already removed), and no error handling or fallback
is present.

Referred Code
// Handle navigation controls based on mode
if (mapType === MapToggleEnum.DrawingMode) {
  if (!navigationControlRef.current) {
    navigationControlRef.current = new mapboxgl.NavigationControl();
    map.current.addControl(navigationControlRef.current, 'top-left');
  }
} else {
  if (navigationControlRef.current) {
    map.current.removeControl(navigationControlRef.current);
    navigationControlRef.current = null;
  }
}

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Add null check before access

Add a null check for map.current before accessing it in the else block to
prevent potential runtime errors.

components/map/mapbox-map.tsx [357-367]

 if (mapType === MapToggleEnum.DrawingMode) {
   if (!navigationControlRef.current) {
     navigationControlRef.current = new mapboxgl.NavigationControl();
     map.current.addControl(navigationControlRef.current, 'top-left');
   }
 } else {
-  if (navigationControlRef.current) {
+  if (navigationControlRef.current && map.current) {
     map.current.removeControl(navigationControlRef.current);
     navigationControlRef.current = null;
   }
 }
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly identifies a potential null pointer access on map.current and proposes adding a defensive null check, which improves code robustness.

Low
  • More

Copy link

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

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

  • Zoom controls are only toggled when isMapTypeChanged is true, causing the controls to be absent on initial load when starting in DrawingMode.
  • New navigationControlRef lacks explicit cleanup on component unmount, which can leave dangling references.
  • A dev.log file is committed, which should be removed and ignored.

These changes may lead to incorrect initial UI state and repository hygiene issues.

Additional notes (1)
  • Maintainability | dev.log:1-1
    A log file (dev.log) is committed to the repo. Committing runtime/dev logs is undesirable and should be avoided. Please remove it and add it to .gitignore to prevent future accidental commits.
Summary of changes
  • Introduces navigationControlRef to track a single mapboxgl.NavigationControl instance.
  • Removes unconditional NavigationControl addition during map initialization.
  • Adds conditional add/remove of NavigationControl when mapType === MapToggleEnum.DrawingMode within the mode-change handling.
  • Adds a new file dev.log to the repository.

Links/Code:

  • New logic added around handling of navigation controls when switching modes.
  • Removed map.current.addControl(new mapboxgl.NavigationControl(), 'top-left') from initialization.

Comment on lines +356 to +367
// Handle navigation controls based on mode
if (mapType === MapToggleEnum.DrawingMode) {
if (!navigationControlRef.current) {
navigationControlRef.current = new mapboxgl.NavigationControl();
map.current.addControl(navigationControlRef.current, 'top-left');
}
} else {
if (navigationControlRef.current) {
map.current.removeControl(navigationControlRef.current);
navigationControlRef.current = null;
}
}

Choose a reason for hiding this comment

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

The navigation control toggling is gated by isMapTypeChanged. This can cause the zoom icons to never appear on initial load when the app starts in DrawingMode (because no mode change has occurred yet and the unconditional add during init was removed). This is a functional regression relative to the previous behavior and violates the stated goal of showing zoom icons whenever drawing tools are active.

Recommend handling the control setup regardless of whether the mode changed (idempotent due to the ref), or add an initial check after map initialization to reflect the current mode.

Suggestion

Move the navigation control toggling outside of the isMapTypeChanged branch so it runs whenever the effect executes and the map is initialized, e.g.:

// After ensuring map.current and initializedRef.current
if (mapType === MapToggleEnum.DrawingMode) {
  if (!navigationControlRef.current) {
    navigationControlRef.current = new mapboxgl.NavigationControl();
    map.current.addControl(navigationControlRef.current, 'top-left');
  }
} else if (navigationControlRef.current) {
  map.current.removeControl(navigationControlRef.current);
  navigationControlRef.current = null;
}

Alternatively, add a one-time check in the map.current.on('load', ...) handler to add the control if the initial mode is DrawingMode.

Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change.

const { mapData, setMapData } = useMapData(); // Consume the new context, get setMapData
const { setIsMapLoaded } = useMapLoading(); // Get setIsMapLoaded from context
const previousMapTypeRef = useRef<MapToggleEnum | null>(null)
const navigationControlRef = useRef<mapboxgl.NavigationControl | null>(null);

Choose a reason for hiding this comment

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

You added a persistent navigationControlRef, but there is no corresponding unmount/cleanup path shown for removing the control if the map is destroyed. While Mapbox cleans up on map.remove(), explicitly removing the control prevents potential dangling references and keeps the lifecycle clear.

Suggestion

Add cleanup to remove the control during component unmount or before calling map.remove():

// In your cleanup useEffect
if (map.current && navigationControlRef.current) {
  map.current.removeControl(navigationControlRef.current);
  navigationControlRef.current = null;
}

Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change.

Comment on lines +357 to +361
if (mapType === MapToggleEnum.DrawingMode) {
if (!navigationControlRef.current) {
navigationControlRef.current = new mapboxgl.NavigationControl();
map.current.addControl(navigationControlRef.current, 'top-left');
}

Choose a reason for hiding this comment

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

If the intent is to show only zoom icons (as the PR title/description states), the default NavigationControl will also render the compass. You should explicitly configure it to hide the compass.

Suggestion

Replace the constructor with options to hide the compass and show only zoom:

navigationControlRef.current = new mapboxgl.NavigationControl({
  showCompass: false,
  showZoom: true,
});

Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this change.

@charliecreates charliecreates bot removed the request for review from CharlieHelps November 13, 2025 19:58
@ngoiyaeric
Copy link
Collaborator

@coderabbitai its still not showing only when its mapping

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Fetch the PR to examine the implementation
gh pr view 366 --json files --jq '.files[].path'

Length of output: 37


🏁 Script executed:

#!/bin/bash
# Get the full content of the changed file
gh pr view 366 --json files --jq '.files[] | select(.path == "components/map/mapbox-map.tsx") | .patch' > /tmp/patch.txt
cat /tmp/patch.txt

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Get the full file content to understand the context
gh pr diff 366 --patch

Length of output: 2610


🏁 Script executed:

#!/bin/bash
# Look for MapType enum or mode definitions to understand what "mapping" mode might be
rg -n "enum.*MapType|type.*MapType|const.*MapType" --type=ts --type=tsx -A 5

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for DrawingMode definition
rg -n "DrawingMode" --type=ts --type=tsx -C 3

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for MapToggleEnum definition
rg -n "MapToggleEnum" -C 5

Length of output: 11978


🏁 Script executed:

#!/bin/bash
# Get the full content of the mapbox-map.tsx file
cat components/map/mapbox-map.tsx

Length of output: 22492


🏁 Script executed:

#!/bin/bash
# Search for all map modes/types
rg -n "enum.*Toggle|MapToggle" -A 10

Length of output: 20563


@ngoiyaeric I can see the current implementation shows the navigation controls (zoom icons) only when in DrawingMode (the "Draw & Measure" option).

Looking at your map, there are three modes available:

  1. Live - RealTimeMode
  2. My Maps - FreeMode
  3. Draw & Measure - DrawingMode

When you say "when its mapping," which mode are you referring to? Are you wanting the navigation controls to show in:

  • FreeMode ("My Maps") instead of DrawingMode?
  • Both FreeMode and DrawingMode?
  • Or a different combination?

Please let me know which mode(s) should display the zoom navigation controls, and I'll help update the logic accordingly.

@google-labs-jules
Copy link
Contributor Author

@coderabbitai its still not showing only when its mapping

I apologize that the previous fix was not sufficient. I've re-implemented the logic with a more robust solution that should resolve the issue. The zoom controls will now be displayed in both FreeMode and DrawingMode.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2025

Skipped: Cannot respond to another bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants