Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 25, 2026

When editing a route or route instance linked to a completed map, the map is filtered out of the selection list, preventing the route from being saved.

Changes

route-detail.component.ts

  • Cache unfiltered maps in allMaps signal on initial load
  • Refilter maps when route data loads: maps.filter(m => !m.completed || selectedMaps.includes(m.mapId))
  • Avoids duplicate API calls by reusing cached data

route-instances-edit.component.ts

  • Apply same filter logic: include non-completed maps OR already-linked maps
  • Ensures existing linked completed maps remain selectable

Result

  • New routes/instances: see only non-completed maps
  • Existing routes/instances: see non-completed maps + their linked completed maps
  • Users can edit routes after marking associated maps as completed
Original prompt

This section details on the original issue you should resolve

<issue_title>Issue with existing routes and completed maps</issue_title>
<issue_description>in #168 the option to complete maps was added. However, when editing an existing map the (by now) completed map doesn't show up. That means the route can't be saved.

For existing routes any map it is already linked to should always be shown in maps selection, both for routes and route instances.</issue_description>

<agent_instructions>Please try to understand the user flow through the application, especially

  1. adding a new map
  2. Adding trips to that map
  3. marking that map as competed , as that travel is now done and fully logged in OVDB.

After that editing or watching those existing routes should work fine with the maps selection, meaning any existing map is still shown as selected and can be (de)selected</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 25, 2026 23:57
…e editing

Co-authored-by: jjasloot <5612709+jjasloot@users.noreply.github.com>
…icolon

Co-authored-by: jjasloot <5612709+jjasloot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with existing routes not showing completed maps Fix completed maps not appearing when editing existing routes Jan 26, 2026
Copilot AI requested a review from jjasloot January 26, 2026 00:03
@jjasloot jjasloot marked this pull request as ready for review January 26, 2026 17:18
Copilot AI review requested due to automatic review settings January 26, 2026 17:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where completed maps were being filtered out of the selection list when editing existing routes or route instances, preventing users from saving routes that were already linked to completed maps.

Changes:

  • Added caching of unfiltered maps in route-detail component to enable refiltering when route data loads
  • Modified map filtering logic to include completed maps that are already linked to the current route/instance
  • Applied the same filtering pattern to both route editing and route instance editing components

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
route-detail.component.ts Caches all maps in allMaps signal and refilters to include linked completed maps when route data loads
route-instances-edit.component.ts Applies filter logic to include non-completed maps or already-linked completed maps


// Update maps list to include any completed maps that are already linked to this route
const allMaps = this.allMaps();
this.maps.set(allMaps.filter(m => !m.completed || this.selectedMaps.includes(m.mapId)));
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

In route-detail.component.ts, selectedMaps is an uninitialized array property. If loadData() is called before the getMaps() subscription completes, or if the maps API call completes before route data loads, the filter logic on line 171 will fail because this.selectedMaps will be undefined. This can cause a runtime error when trying to call includes() on undefined.

Initialize selectedMaps to an empty array at declaration: selectedMaps: number[] = [];

Copilot uses AI. Check for mistakes.
Comment on lines +169 to +171
// Update maps list to include any completed maps that are already linked to this route
const allMaps = this.allMaps();
this.maps.set(allMaps.filter(m => !m.completed || this.selectedMaps.includes(m.mapId)));
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

There's a race condition between the getMaps() API call and loadData(). If the route data loads before the maps API call completes, this.allMaps() will be an empty array on line 170, causing the filter on line 171 to produce an empty maps list even though completed maps should be shown.

Consider one of these solutions:

  1. Check if allMaps is empty and skip the refilter if so (the initial filter from line 134 will be used)
  2. Use a more robust caching/loading pattern where the route data waits for maps to load first
  3. Move the refiltering logic to the getMaps subscription, triggered when route data is available

For example:

const allMaps = this.allMaps();
if (allMaps.length > 0) {
  this.maps.set(allMaps.filter(m => !m.completed || this.selectedMaps.includes(m.mapId)));
}
Suggested change
// Update maps list to include any completed maps that are already linked to this route
const allMaps = this.allMaps();
this.maps.set(allMaps.filter(m => !m.completed || this.selectedMaps.includes(m.mapId)));
// Update maps list to include any completed maps that are already linked to this route.
// Guard against the case where maps have not yet loaded to avoid overwriting the list with empty data.
const allMaps = this.allMaps();
if (allMaps.length > 0) {
this.maps.set(allMaps.filter(m => !m.completed || this.selectedMaps.includes(m.mapId)));
}

Copilot uses AI. Check for mistakes.
@jjasloot jjasloot merged commit 6de6558 into master Jan 26, 2026
8 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.

Issue with existing routes and completed maps

2 participants