feat(layouts): switch track layout mid-practice and view stats per layout
A club can run one Open Practice all season and re-lay the track now and then. Previously a session's layout was frozen at start and every training lap inherited it, so a season-long practice stayed on its first layout forever, and changing layout was hidden under Settings -> Appearance. - Each practice lap now counts toward the layout active when it was driven; a running practice session moves onto a new layout when one is added - "New layout" strip on Training stats, Race Day and the Dashboard, offered only around practice; a running race session blocks layout changes everywhere - "Stats for" selector (current / older layout / before layouts / all layouts) on Training stats and in the driver's mobile profile (?layout= on the public API) - A layout that has practice laps on it can no longer be deleted - Fix: the buildDriverTrainingStats wrapper in app.js dropped extra arguments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
196437d25b
commit
627179b95a
22 files changed
+454
-44
No files matched your search
@@ -42,3 +42,26 @@ export function getTrackLayoutLabel(layouts, layoutId) {
|
||||
export function nextTrackLayoutLabel(layouts) {
|
||||
return `Layout ${(Array.isArray(layouts) ? layouts.length : 0) + 1}`;
|
||||
}
|
||||
|
||||
// Layouts are a practice concept: a club re-lays the track between practice days (or mid
|
||||
// Open Practice), never in the middle of a race format. These are the casual practice
|
||||
// session types that may be running when a layout changes.
|
||||
const PRACTICE_SESSION_TYPES = ["open_practice", "free_practice"];
|
||||
|
||||
export function isPracticeSessionType(type) {
|
||||
return PRACTICE_SESSION_TYPES.includes(String(type || "").toLowerCase());
|
||||
}
|
||||
|
||||
// A new layout can't start while a race-format session (qualifying, heat, final, ...) is
|
||||
// running or paused - that race must finish on the track it started on.
|
||||
export function findRaceSessionBlockingLayoutChange(sessions) {
|
||||
return (Array.isArray(sessions) ? sessions : []).find((session) =>
|
||||
["running", "paused"].includes(session?.status) && !isPracticeSessionType(session?.type)) || null;
|
||||
}
|
||||
|
||||
// In use = any session started on it, or any training lap driven on it. Deleting a layout
|
||||
// that practice laps belong to would silently move those laps onto the previous layout.
|
||||
export function isTrackLayoutInUse(layoutId, { sessions = [], ledger = [] } = {}) {
|
||||
return sessions.some((session) => session?.trackLayoutId === layoutId)
|
||||
|| ledger.some((lap) => lap?.trackLayoutId === layoutId);
|
||||
}
|
||||
Reference in new issue
Block a user