Skip to content

Refactor: extract shared map/table hover logic from map_expedition_filter.js and map_compilation_filter.js into a common module #295

Description

@ksalamy

Background

map_expedition_filter.js and map_compilation_filter.js are nearly identical — they share the same highlight state management, label building, table layout logic, hover wiring, and slug→row index. This duplication means any future fix (e.g. hover debounce changes, selector escaping, layout tweaks) must be applied twice, and it is easy to miss one file.

This was flagged during Copilot review of PR #16 (ksalamy fork) and deferred to keep that PR focused.

Proposed approach

  1. Create smdb/smdb/static/js/map_filter_shared.js with a single factory function:

    function initMapFilter({ mapId, tableWrapperId }) { ... }

    containing all shared logic: highlight state, clearAllMissionHighlights(), highlightMission(), slugRowIndex building, label positioning, nav-track GeoJSON styling, initTableLayout(), and attachTableRowHover().

  2. Reduce map_expedition_filter.js and map_compilation_filter.js to ~20 lines each — just load the GeoJSON, call initMapFilter() with their respective IDs, and handle any page-specific overrides.

  3. Update expedition_filter.html and compilation_filter.html to load map_filter_shared.js before the page-specific script.

  4. Docker image rebuild required (static JS files are compressed at build time).

  5. Full test run to confirm no regressions.

Files affected

  • smdb/smdb/static/js/map_expedition_filter.js
  • smdb/smdb/static/js/map_compilation_filter.js
  • smdb/smdb/static/js/map_filter_shared.js (new)
  • smdb/smdb/templates/smdb/expedition_filter.html
  • smdb/smdb/templates/smdb/compilation_filter.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions