mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
fix(planner): judge a move by the order a day is drawn in across time zones
The checks behind a drag and the up/down buttons read each booking's raw clock, so on a day whose flights were put in the order they happen every move of a timed stop asked to change its time (desktop) or was refused (mobile). They now read the same key the day is ordered by.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { parseTimeToMinutes, getSpanPhase, hidesOnMiddleDay, getTransportRouteEndpoints, getDisplayTimeForDay, getTransportForDay, getAssignmentReservations, pinnedAway, stopDayIds, getPlaceBookings, getMergedItems, nightRowsOf, rideSeatKey, seatTimedDrop, stayStartingOn, storedRideSlot, timedSlot, type MergedItem } from './dayMerge'
|
||||
import { parseTimeToMinutes, getSpanPhase, hidesOnMiddleDay, getTransportRouteEndpoints, getDisplayTimeForDay, getTransportForDay, getAssignmentReservations, pinnedAway, stopDayIds, getPlaceBookings, getMergedItems, chronoKeyOf, nightRowsOf, rideSeatKey, seatTimedDrop, stayStartingOn, storedRideSlot, timedSlot, type MergedItem } from './dayMerge'
|
||||
import { planMergedOrder, withTransportPositions } from './mergedOrder'
|
||||
|
||||
describe('parseTimeToMinutes', () => {
|
||||
@@ -739,4 +739,11 @@ describe('getMergedItems: bookings in different time zones (#2929)', () => {
|
||||
const order = getMergedItems({ dayAssignments: [], dayNotes: [], dayTransports: [toLA, toSeattle], dayId: DAY })
|
||||
expect(ids(seatTimedDrop([order[1], order[0]], 0, DAY))).toEqual([1, 2])
|
||||
})
|
||||
|
||||
it('gives the zoned flights the key they are drawn by, so the drawn order reads as in order', () => {
|
||||
const items = getMergedItems({ dayAssignments: [], dayNotes: [], dayTransports: [toSeattle, toLA], dayId: DAY })
|
||||
const keyOf = chronoKeyOf(items, DAY, getDisplayTimeForDay)
|
||||
// Drawn Auckland first: it takes the 17:00 slot, the Seattle flight the 20:20 one.
|
||||
expect(items.map(keyOf)).toEqual([17 * 60, 20 * 60 + 20])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -353,13 +353,27 @@ function applyChronoOrder(
|
||||
dayId: number,
|
||||
getDisplayTime: (r: any, dayId: number) => string | null
|
||||
): MergedItem[] {
|
||||
return chronoOrder(items, chronoKeyOf(items, dayId, getDisplayTime))
|
||||
}
|
||||
|
||||
/**
|
||||
* The minutes the day orders an item by: its own clock, or for a booking in a known
|
||||
* zone the clock slot it takes among the day's zoned bookings (#2929). The checks
|
||||
* that ask whether a move keeps the day in order read the same key, or a day whose
|
||||
* flights were put in the order they happen would read as out of order on every move.
|
||||
*/
|
||||
export function chronoKeyOf(
|
||||
items: readonly MergedItem[],
|
||||
dayId: number,
|
||||
getDisplayTime: (r: any, dayId: number) => string | null
|
||||
): (it: MergedItem) => number | null {
|
||||
const clockOf = (it: MergedItem): number | null => {
|
||||
if (it.type === 'place') return parseTimeToMinutes(it.data?.place?.place_time)
|
||||
if (it.type === 'note') return parseTimeToMinutes(it.data?.time)
|
||||
return parseTimeToMinutes(getDisplayTime(it.data, dayId))
|
||||
}
|
||||
const zoned = zonedClockSlots(items, dayId, getDisplayTime, clockOf)
|
||||
return chronoOrder(items, it => (zoned.has(it) ? zoned.get(it) : clockOf(it)))
|
||||
const zoned = zonedClockSlots([...items], dayId, getDisplayTime, clockOf)
|
||||
return it => (zoned.has(it) ? (zoned.get(it) as number) : clockOf(it))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user