mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
fix(assignments): keep untimed stops in place when a start is saved
Saving a start on a stop rewrote the whole day as the timed stops in time order followed by every untimed stop. Its own comment and the commit that added it promised that untimed stops keep their place, but a day of two untimed stops and a third one given 14:00 came back with the third one first. On a road trip the stop order is the drive, so the day was re-routed, its vias landed on other legs, and collaborators, who only got the one edited row, saw a third order until they reloaded. The intended rule, an untimed stop inheriting the time of the timed stop before it, now lives once as chronoOrder in @trek/shared, used by both the day plan (dayMerge) and AssignmentsService.updateTime. The server still reads a booked night's hour from its check-in, and a value without a colon still sorts after every clock time. The day is sorted only when the stop's start actually changed, so taking an End off or saving an unchanged start no longer snaps back a day somebody dragged out of time order. A sorted day is numbered from 0 like a drag. In the same transaction the day's road trip vias follow the stop they were drawn behind, the planner's own drag rule, and a via behind a last stop that stays last is kept, so the drive into the next day keeps its road. PUT /assignments/:id/time and the MCP update_assignment_time tool both broadcast assignment:reordered with the whole day, to the writer as well, and roadtripVia:changed when vias moved, so every client ends up with the same order. ASG-SVC-022, 023 and 027 pinned the old behaviour and now pin the intended one.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { chronoOrder } from '@trek/shared'
|
||||
// `orderedEndpoints` is the geometry order's single source of truth, in the module
|
||||
// that documents the multi-leg model. Sorting endpoints a second time here is how
|
||||
// the two drift.
|
||||
@@ -270,26 +271,22 @@ export function getAssignmentReservations<T extends {
|
||||
* transport/leg display time, a timed note) sorts by that time. An item WITHOUT a
|
||||
* time inherits the time of the timed item before it, so untimed items stay where
|
||||
* they were manually placed. Stable on the incoming order for ties.
|
||||
*
|
||||
* The rule itself is `chronoOrder` in @trek/shared, the same one the server uses when
|
||||
* a start time is saved. The server feeds it the day's stops only, though. An untimed
|
||||
* place behind a timed note or booking inherits that item's time here and the previous
|
||||
* stop's time there, so on such a day the stored order and this one can differ.
|
||||
*/
|
||||
function applyChronoOrder(
|
||||
items: MergedItem[],
|
||||
dayId: number,
|
||||
getDisplayTime: (r: any, dayId: number) => string | null
|
||||
): MergedItem[] {
|
||||
const timeOf = (it: MergedItem): number | null => {
|
||||
return chronoOrder(items, it => {
|
||||
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))
|
||||
}
|
||||
let last = -Infinity
|
||||
return items
|
||||
.map((it, i) => {
|
||||
const t = timeOf(it)
|
||||
if (t != null) last = t
|
||||
return { it, i, eff: t != null ? t : last }
|
||||
})
|
||||
.sort((a, b) => a.eff - b.eff || a.i - b.i)
|
||||
.map(k => k.it)
|
||||
})
|
||||
}
|
||||
|
||||
/** Merge places, notes, and transports into a single ordered day timeline. */
|
||||
|
||||
Reference in New Issue
Block a user