Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@e-esakman
Copy link
Contributor

@e-esakman e-esakman commented Nov 15, 2025

Fixes #4792
This PR fixes the map functionality in banned_apps.html where searching for a country did not zoom, highlight, or show relevant markers.

Improvements ~

1.Map now zooms correctly to the searched country.
2.Country highlighting fixed:
-Red → Countries with banned apps
-Grey → Countries with no banned apps
3.Single marker is shown for each country (to avoid clutter from multiple markers).
4.Marker click highlights all banned apps for the selected country

Before -

Untitled.design.mp4

After -

Untitled.design.1.mp4

Summary by CodeRabbit

  • New Features

    • Enhanced map interactivity with improved country highlighting and hover behavior.
    • Redesigned search results flow with integrated country information display panel.
  • Bug Fixes

    • Fixed search initialization to properly load map data before displaying results.
    • Improved data handling and consistency for country information display.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 15, 2025

Walkthrough

Refactors the banned apps map view to enable country highlighting and zooming on search. Replaces dynamic per-feature GeoJSON styling with a simplified approach, introduces geoJSONLoaded flag for readiness checks, and adds new functions (highlightCountry, placeCountryMarker, showCountryInfo) to handle country highlighting, marker placement, and search result display.

Changes

Cohort / File(s) Summary
GeoJSON Loading & Initialization
website/templates/banned_apps.html
Adds geoJSONLoaded flag initialization; replaces per-feature dynamic styling via onEachFeature with unified style object; stores feature data in allCountriesData map for per-country lookup instead of tracking via currentCountry.
Country Interaction Functions
website/templates/banned_apps.html
Introduces highlightCountry(country, hasApps) to recolor and focus a country on the map; adds placeCountryMarker(country, apps) to render custom marker and tooltip for banned apps; adds showCountryInfo(country, apps) to populate side-panel with country metadata and app list.
Search Flow Updates
website/templates/banned_apps.html
Updates searchApps to guard on geoJSONLoaded before processing; integrates showNoResults for empty results and calls highlightCountry + placeCountryMarker for successful matches.
UI Helper Refactoring
website/templates/banned_apps.html
Adjusts showNoResults, hideResults, and resetMap to align with new data flows; removes obsolete calculateMarkerPositions and multi-marker logic; refactors to use lower-cased country keys and safer property access.

Sequence Diagram

sequenceDiagram
    participant User
    participant SearchUI as Search UI
    participant searchApps as searchApps()
    participant Map
    participant Highlight as highlightCountry()
    participant Marker as placeCountryMarker()
    participant SidePanel as showCountryInfo()

    User->>SearchUI: Enter country name
    SearchUI->>searchApps: Call searchApps(query)
    
    alt geoJSONLoaded == false
        searchApps->>SearchUI: Return (not ready)
    else geoJSONLoaded == true
        searchApps->>Map: Query allCountriesData
        
        alt Results found
            searchApps->>Highlight: highlightCountry(country, hasApps)
            Highlight->>Map: Recolor country, zoom/pan
            searchApps->>Marker: placeCountryMarker(country, apps)
            Marker->>Map: Place marker, show tooltip
            searchApps->>SidePanel: showCountryInfo(country, apps)
            SidePanel->>SearchUI: Display country name, count, app list
        else No results
            searchApps->>SearchUI: showNoResults()
        end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • GeoJSON data structure and lookup logic: Verify that the allCountriesData map correctly captures all feature properties and that country key normalization (lower-casing) is applied consistently across all functions and user inputs.
  • New highlight and marker functions: Ensure highlightCountry correctly resets previous styling, that placeCountryMarker handles edge cases (missing coordinates, duplicate markers), and that showCountryInfo properly renders side-panel content.
  • Search flow guard and state synchronization: Confirm that the geoJSONLoaded flag is reliably set before search is attempted, and that state transitions between results/no-results/reset are correct.
  • Removal of old logic: Verify that deleted functions (calculateMarkerPositions, old multi-marker logic) are not referenced elsewhere and that the transition from currentCountry to the new approach is complete and consistent.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing map zoom and highlighting for banned countries, which directly matches the core objectives and changeset.
Linked Issues check ✅ Passed The PR implements all requirements from issue #4792: map now zooms to country boundaries, highlights countries with color coding, and shows markers for banned apps.
Out of Scope Changes check ✅ Passed All changes are scoped to map functionality and banned apps display on the banned_apps.html template, directly addressing the linked issue #4792.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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: 0

🧹 Nitpick comments (3)
website/templates/banned_apps.html (3)

136-138: Graceful error handling for GeoJSON fetch, but lacks explicit failure notification.

Setting geoJSONLoaded = true even on fetch failure allows the search flow to proceed, but countriesLayer will be undefined. While downstream guard clauses (line 184) prevent null-pointer exceptions, users receive no visual feedback that the map is non-functional.

Consider logging the error and optionally displaying a toast/banner to inform users that the map couldn't load the country boundaries. The current approach silently degrades, which could confuse users.


118-118: Minor: Redundant .toLowerCase() call.

countryName is already lowercased on line 114, so calling .toLowerCase() again on line 118 is redundant. Consider removing it for clarity.

-                            allCountriesData[countryName.toLowerCase()] = {
+                            allCountriesData[countryName] = {

274-298: Minor: Country name formatting could handle multi-word names better.

Line 281 capitalizes only the first letter: .charAt(0).toUpperCase() + country.slice(1). This produces correct output for single-word names (e.g., "India" → "India") but inconsistent output for multi-word names if the backend returns lowercase (e.g., "united states" → "United states" instead of "United States").

If the backend already returns properly formatted names (e.g., "United States"), this is not an issue. Verify the API response format before deciding whether to apply a title-case utility.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between ff701fe and 737c103.

📒 Files selected for processing (1)
  • website/templates/banned_apps.html (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test
🔇 Additional comments (5)
website/templates/banned_apps.html (5)

156-180: Solid search flow with GeoJSON readiness guard.

The implementation correctly waits for geoJSONLoaded before proceeding, preventing race conditions. The API call handles empty results gracefully. However, verify the following with your backend team:

  • The /api/banned_apps/search/ endpoint consistently returns a structure with an apps array (even if empty).
  • Empty apps array is used to distinguish "no apps for country" from "country not found" scenarios.
  • The search is case-insensitive on the backend side, or the frontend should normalize the query.

182-199: Solid country highlighting with appropriate zoom and color coding.

The function correctly:

  • Validates map and layer existence before proceeding (line 184).
  • Resets prior state to prevent visual artifacts.
  • Uses semantic color choices (red for banned, grey for not banned).
  • Applies flyToBounds() with a reasonable animation duration for UX.

The implementation achieves the PR objective of zooming and highlighting on search.


201-242: Effective marker placement with single-marker-per-country design.

The function:

  • Clears previous markers to prevent clutter (line 204).
  • Uses a custom div icon with count display—visually distinct and informative.
  • Binds a tooltip showing app count (lines 231–234).
  • Attaches a click handler to show country info panel (lines 237–239).

Achieves the PR objective of single marker per country with app count visibility and interactive details.


300-322: UI state management is clear and consistent.

The helper functions (showNoResults, hideResults, resetMap) correctly manage visibility of:

  • Results grid (resultsSection).
  • No-results message (noResults).
  • Country info panel (countryInfo).

The state transitions ensure users see the appropriate UI for each search outcome. Implementation is clean and maintainable.


63-63: API integration verified and aligned correctly.

The endpoint chain is fully implemented and functional:

  • Frontend correctly calls /api/banned_apps/search/?country={country} at line 167
  • Backend routing properly wires to search_banned_apps view
  • View correctly filters BannedApp by country_name__icontains and returns active records only
  • Response structure with app_name, app_type, country_name, ban_reason, ban_date, source_url is properly defined in the model
  • Database indexing on country_name ensures efficient queries
  • Empty input handling returns appropriate empty list response

The refactoring objectives are met and the code is production-ready. The suggestion to test edge cases (network failures, slow GeoJSON loading, rapid searches) remains a valid testing recommendation for comprehensive coverage.

@github-project-automation github-project-automation bot moved this from Backlog to Ready in 📌 OWASP BLT Project Board Nov 15, 2025
@DonnieBLT DonnieBLT merged commit efa8879 into OWASP-BLT:main Nov 15, 2025
16 checks passed
@DonnieBLT
Copy link
Collaborator

Thank you!

@e-esakman e-esakman deleted the fix-banned-apps-map-v2 branch November 16, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Fix: In banned_apps, map does not zoom or highlight any banned country

2 participants