Fix Team Race duplicate-membership bug and two related team-roster gaps
Reported by the user: creating a team, adding the wrong driver, then moving that driver to another team by ticking them on the new team's edit form left the driver on both teams at once. Root cause: there was never a "move" action - the edit form only ever added a driver to the team being saved, never removed them from wherever they already were. Live laps from a driver on two teams were then silently credited to only the first-matching team, with no clear error. reassignTeamMembers (event_race_logic.js) now strips a driver/car being saved onto one team out of every other team in the same event, and the team checkbox list shows which team a driver is already on before you move them. Also fixed two related gaps found while investigating, at the user's request to fix everything: getTeamDriverPool had regressed to ignoring the event's class/participant scoping entirely (showing every driver in the club), and deleting a driver or car left them behind in team rosters forever. Added a duplicate_team_members Race Day preflight check as defense in depth for any already-corrupted saved state. Verified with new unit tests for reassignTeamMembers, getTeamDriverPool and the new preflight check, plus a new permanent browser test reproducing the user's exact reported scenario end to end. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71b3451b13
commit
15b574a37d
16 files changed
+261
-15
No files matched your search
@@ -567,6 +567,18 @@ export function renderDriversView(deps) {
|
||||
state.drivers = state.drivers.filter((x) => x.id !== d.id);
|
||||
state.sessions.forEach((s) => {
|
||||
s.assignments = (s.assignments || []).filter((a) => a.driverId !== d.id);
|
||||
s.driverIds = (s.driverIds || []).filter((id) => id !== d.id);
|
||||
s.manualGridIds = (s.manualGridIds || []).filter((id) => id !== d.id);
|
||||
});
|
||||
// Otherwise a deleted driver stays a "member" of every team/participant list they
|
||||
// were ever added to, silently inflating team/participant counts forever.
|
||||
state.events.forEach((event) => {
|
||||
if (!event.raceConfig) return;
|
||||
event.raceConfig.driverIds = (event.raceConfig.driverIds || []).filter((id) => id !== d.id);
|
||||
event.raceConfig.teams = (event.raceConfig.teams || []).map((team) => ({
|
||||
...team,
|
||||
driverIds: (team.driverIds || []).filter((id) => id !== d.id),
|
||||
}));
|
||||
});
|
||||
saveState();
|
||||
renderView();
|
||||
@@ -781,6 +793,13 @@ export function renderCarsView(deps) {
|
||||
state.sessions.forEach((s) => {
|
||||
s.assignments = (s.assignments || []).filter((a) => a.carId !== c.id);
|
||||
});
|
||||
state.events.forEach((event) => {
|
||||
if (!event.raceConfig) return;
|
||||
event.raceConfig.teams = (event.raceConfig.teams || []).map((team) => ({
|
||||
...team,
|
||||
carIds: (team.carIds || []).filter((id) => id !== c.id),
|
||||
}));
|
||||
});
|
||||
saveState();
|
||||
renderView();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user