mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
fix(roadtrip): a hop between two desks keeps its line and drops the pill
The hire desk beside the terminal is a 200 m leg, and the pill under it read "0 km in 0 min" where the eye wants the next stop. Under 150 m and two minutes a leg is a hop: the rail keeps the dashed line, the phone chain skips the row, and neither offers other ways of driving it. A note a plugin attached keeps the row. Refs #2428
This commit is contained in:
@@ -17,7 +17,7 @@ import { formatDistance } from '../../utils/units'
|
||||
import { formatDate, formatClockTime } from '../../utils/formatters'
|
||||
import { formatDurationShort, isServiceStopType, serviceColor, type ScheduleEntry, type ScheduleWarning, refuelsRange } from './roadtripModel'
|
||||
import { STOP_KIND_BY_KEY } from './stopKinds'
|
||||
import { destinationCount, legReroutable } from './roadtripRowModel'
|
||||
import { destinationCount, isHop, legReroutable } from './roadtripRowModel'
|
||||
import { spurWorthLabelling } from './accessSpur'
|
||||
import StopKindPicker from './StopKindPicker'
|
||||
import StopFillPicker from './StopFillPicker'
|
||||
@@ -693,6 +693,18 @@ function DriveBand({ leg, onAskAlternatives, alternativesOpen }: {
|
||||
const distanceUnit = useSettingsStore(s => s.settings.distance_unit)
|
||||
const mode = leg?.mode ?? 'driving'
|
||||
const Icon = mode.startsWith('plugin:') ? Zap : MODE_ICON[mode] ?? CarFront
|
||||
// A hop (the hire desk beside the terminal) keeps the line and drops the pill: there is
|
||||
// nothing to say about it and no other way to drive it.
|
||||
if (isHop(leg)) {
|
||||
return (
|
||||
<div className="grid" style={RAIL_GRID}>
|
||||
<span className="relative z-[1] flex min-h-[10px] flex-col items-center" aria-hidden>
|
||||
<span className="flex-1" style={RAIL_DASH} />
|
||||
</span>
|
||||
<span />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
// The band's contents, shared by the clickable and the read-only shape so the two can
|
||||
// never drift apart in what they say.
|
||||
const band = (
|
||||
|
||||
@@ -567,6 +567,17 @@ describe('roadtripRows with a ride (#2428)', () => {
|
||||
expect(stopRows(landing).map(r => [r.stop.name, r.number])).toEqual([['Hamburg Airport', null], ['Hotel', 1]])
|
||||
})
|
||||
|
||||
it('FE-RTROW-051: a hop, the desk beside the terminal, is no leg row and is offered no other ways', () => {
|
||||
const hop: RouteSegment = { ...seg(0), distance: 120, duration: 45, distanceText: '0 km', durationText: '0 min' }
|
||||
const d = day([stop('Sixt Airport'), stop('Hamburg Airport'), stop('Hotel')], { legs: [hop, seg(1)] })
|
||||
expect(roadtripRows(d).map(r => r.kind)).toEqual(['stop', 'stop', 'leg', 'stop'])
|
||||
expect(legReroutable(d, 0)).toBe(false)
|
||||
expect(legReroutable(d, 1)).toBe(true)
|
||||
// A note a plugin attached keeps the row, however short the hop.
|
||||
const noted = day([stop('A'), stop('B')], { legs: [{ ...hop, noteText: '10 min charge' }] })
|
||||
expect(roadtripRows(noted).map(r => r.kind)).toEqual(['stop', 'leg', 'stop'])
|
||||
})
|
||||
|
||||
it('FE-RTROW-050: a hire car\'s desks are unnumbered stop rows the road runs through', () => {
|
||||
const desk = (name: string, role: 'pickup' | 'return') =>
|
||||
stop(name, {
|
||||
|
||||
@@ -138,6 +138,20 @@ function isStationary(seg: RouteSegment | undefined): boolean {
|
||||
&& seg.from[1] === seg.to[1]
|
||||
}
|
||||
|
||||
/**
|
||||
* A leg too short to be a drive: the hire desk beside the terminal, the car park beside
|
||||
* the gate. Under 150 m and two minutes it is a hop, and a pill reading "0 km in 0 min"
|
||||
* under it is noise where the eye wants the next stop. The line still joins the two,
|
||||
* and a note a plugin attached is still worth the row.
|
||||
*/
|
||||
export function isHop(seg: RouteSegment | undefined): boolean {
|
||||
return !!seg
|
||||
&& Number.isFinite(seg.distance)
|
||||
&& seg.distance < 150
|
||||
&& seg.duration < 120
|
||||
&& !seg.noteText
|
||||
}
|
||||
|
||||
export function roadtripRows(day: RoadtripDay): RoadtripRow[] {
|
||||
const rows: RoadtripRow[] = []
|
||||
const spills = day.spills ?? []
|
||||
@@ -198,7 +212,7 @@ export function roadtripRows(day: RoadtripDay): RoadtripRow[] {
|
||||
function pushLeg(i: number): void {
|
||||
const stop = day.stops[i]!
|
||||
const seg = day.legs[i]
|
||||
if (i < day.stops.length - 1 && !isStationary(seg)) {
|
||||
if (i < day.stops.length - 1 && !isStationary(seg) && !isHop(seg)) {
|
||||
rows.push({ kind: 'leg', index: i, seg, mode: day.stops[i + 1]?.incomingLegMode ?? stop.legMode ?? null })
|
||||
const dry = (day.dryPoints ?? []).find(p => p.legIndex === i)
|
||||
if (dry) {
|
||||
@@ -226,6 +240,7 @@ export function legReroutable(day: RoadtripDay, index: number): boolean {
|
||||
return index >= 0
|
||||
&& index < day.stops.length - 1
|
||||
&& !!day.legs[index]
|
||||
&& !isHop(day.legs[index])
|
||||
&& !day.stops[index].automaticNight
|
||||
&& !day.stops[index + 1].automaticNight
|
||||
// A leg leaving a terminal is either the ride, which has no other way, or the road
|
||||
|
||||
Reference in New Issue
Block a user