mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
fix(dayplan): a moving day with a flight draws no drive from one stay to the next
A day that checks out of one hotel and into another, with nothing else planned, falls back to a drive from the first hotel to the second (#1297). A flight, train, ferry or coach booked on that day is the move itself, but one saved without its stations leaves no waypoint behind, so the day map, the trip overview and the phone plan all drew the full road between the two hotels, and the phone showed it above and below the flight (#2476). With its stations the day was already right. - The fallback drive between the two hotels is no longer drawn when any such booking is on the day, located or not. A day without a booking keeps it. No line beats a wrong one. - The phone plan takes the evening hotel leg from the last drive that reaches the hotel, not the first, so an earlier drive to the same spot no longer stands in for the one that closes the day. - Google Maps and CoMaps exports of such a day, which could only ever describe that same drive, return nothing, and on the desktop and the phone the two buttons are left out whenever fewer than two stops remain, instead of doing nothing on a tap. A hotel stop planned by hand ahead of the flight already sorts behind it through the ride seating of #2474; a test now pins that for the days view as well.
This commit is contained in:
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
|
||||
import { dayCoMapsUrl, dayExportStops, dayGoogleMapsUrl } from './dayRoute'
|
||||
import type { Accommodation, Assignment, Day } from '../../../../types'
|
||||
|
||||
// FE-MOBILE-DAYROUTE-001 to FE-MOBILE-DAYROUTE-009
|
||||
// FE-MOBILE-DAYROUTE-001 to FE-MOBILE-DAYROUTE-011
|
||||
|
||||
const days = [
|
||||
{ id: 10, day_number: 1 },
|
||||
@@ -69,6 +69,25 @@ describe('dayExportStops', () => {
|
||||
const stops = dayExportStops(days[2], days, [farHome], [hotel], true)
|
||||
expect(stops.map(s => s.name)).toEqual(['Hotel Lutetia', 'Home'])
|
||||
})
|
||||
|
||||
// Day 2 checks out of one stay and into the next, with no stop of its own.
|
||||
const hotelA = { ...hotel, place_name: 'Hotel A', start_day_id: 10, end_day_id: 20 } as Accommodation
|
||||
const hotelB = { ...hotel, place_lat: 53.55, place_lng: 9.99, place_name: 'Hotel B', start_day_id: 20, end_day_id: 30 } as Accommodation
|
||||
|
||||
it('FE-MOBILE-DAYROUTE-010: a flight between the two stays leaves nothing to export (#2476)', () => {
|
||||
// Located or not, the flight is how the day gets from one hotel to the other; a
|
||||
// driving route between them is the stretch nobody drives.
|
||||
expect(dayExportStops(days[1], days, [], [hotelA, hotelB], true, true, true)).toEqual([])
|
||||
expect(dayExportStops(days[1], days, [], [hotelA, hotelB], true, false, true)).toEqual([])
|
||||
expect(dayGoogleMapsUrl(days[1], days, [], [hotelA, hotelB], true, false, true)).toBeNull()
|
||||
expect(dayCoMapsUrl(days[1], days, [], [hotelA, hotelB], true, 'driving', false, true)).toBeNull()
|
||||
})
|
||||
|
||||
it('FE-MOBILE-DAYROUTE-011: without a booking the move is still the drive from one stay to the next (#1297)', () => {
|
||||
expect(dayExportStops(days[1], days, [], [hotelA, hotelB], true).map(s => s.name)).toEqual(['Hotel A', 'Hotel B'])
|
||||
// A stop of its own keeps the day exportable even with the flight booked.
|
||||
expect(dayExportStops(days[1], days, [louvre], [hotelA, hotelB], true, true, true).map(s => s.name)).toContain('Louvre')
|
||||
})
|
||||
})
|
||||
|
||||
describe('day map links', () => {
|
||||
|
||||
@@ -66,7 +66,10 @@ export function optimizeDayOrder(
|
||||
* links that can label a pin with one. `dayHasCarrier` — a carrier transport
|
||||
* with a located endpoint on the day — keeps the no-time bookend default from
|
||||
* opening a leg out of a hotel only reached tonight or back into one already
|
||||
* left (#2157), same as the drawn route.
|
||||
* left (#2157), same as the drawn route. `dayHasCarrierBooking`, any carrier
|
||||
* booked on the day with or without coordinates, leaves a day without stops
|
||||
* with nothing to export: the hotels at either end are joined by that booking,
|
||||
* not by a road (#2476).
|
||||
*/
|
||||
export function dayExportStops(
|
||||
day: Day,
|
||||
@@ -75,8 +78,10 @@ export function dayExportStops(
|
||||
accommodations: Accommodation[],
|
||||
bookendFromAccommodation: boolean,
|
||||
dayHasCarrier?: boolean,
|
||||
dayHasCarrierBooking?: boolean,
|
||||
): NamedWaypoint[] {
|
||||
const located = dayAssignments.filter(a => a.place?.lat != null && a.place?.lng != null)
|
||||
if (located.length === 0 && dayHasCarrierBooking) return []
|
||||
const stops = located.map(a => ({ lat: a.place!.lat!, lng: a.place!.lng!, name: a.place!.name }))
|
||||
const bookends = bookendFromAccommodation ? getDayBookendHotels(day, days, accommodations) : null
|
||||
const firstStop = located[0]
|
||||
@@ -103,9 +108,10 @@ export function dayGoogleMapsUrl(
|
||||
accommodations: Accommodation[],
|
||||
bookendFromAccommodation: boolean,
|
||||
dayHasCarrier?: boolean,
|
||||
dayHasCarrierBooking?: boolean,
|
||||
): string | null {
|
||||
return generateGoogleMapsUrl(
|
||||
dayExportStops(day, days, dayAssignments, accommodations, bookendFromAccommodation, dayHasCarrier),
|
||||
dayExportStops(day, days, dayAssignments, accommodations, bookendFromAccommodation, dayHasCarrier, dayHasCarrierBooking),
|
||||
) || null
|
||||
}
|
||||
|
||||
@@ -118,9 +124,10 @@ export function dayCoMapsUrl(
|
||||
bookendFromAccommodation: boolean,
|
||||
profile: RouteProfileKey,
|
||||
dayHasCarrier?: boolean,
|
||||
dayHasCarrierBooking?: boolean,
|
||||
): string | null {
|
||||
return generateCoMapsUrl(
|
||||
dayExportStops(day, days, dayAssignments, accommodations, bookendFromAccommodation, dayHasCarrier),
|
||||
dayExportStops(day, days, dayAssignments, accommodations, bookendFromAccommodation, dayHasCarrier, dayHasCarrierBooking),
|
||||
profile,
|
||||
) || null
|
||||
}
|
||||
|
||||
@@ -282,8 +282,12 @@ export default function MPlanTimeline({ planner, shell }: MPlanTimelineProps) {
|
||||
<PlanAction icon={Ticket} label={t('mobileTrip.addBookingShort')} onClick={tl.addBooking} />
|
||||
<PlanAction icon={TrainFront} label={t('mobileTrip.addTransportShort')} onClick={tl.addTransport} />
|
||||
<PlanAction icon={Route} label={t('dayplan.optimize')} onClick={() => void tl.optimize()} />
|
||||
<PlanAction icon={GoogleMapsIcon} label={t('mobileTrip.googleMaps')} onClick={tl.exportGoogleMaps} />
|
||||
<PlanAction icon={Compass} label={t('mobileTrip.coMaps')} onClick={tl.exportCoMaps} />
|
||||
{tl.canExportRoute && (
|
||||
<>
|
||||
<PlanAction icon={GoogleMapsIcon} label={t('mobileTrip.googleMaps')} onClick={tl.exportGoogleMaps} />
|
||||
<PlanAction icon={Compass} label={t('mobileTrip.coMaps')} onClick={tl.exportCoMaps} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -199,7 +199,13 @@ export function hotelLegsForDay(
|
||||
const legAt = (a: Accommodation | undefined, end: 'from' | 'to'): HotelLeg | null => {
|
||||
if (!a || a.place_lat == null || a.place_lng == null) return null
|
||||
const coord: [number, number] = [a.place_lat, a.place_lng]
|
||||
const seg = routeSegments.find(s => sameCoord(end === 'from' ? s.from : s.to, coord))
|
||||
// The morning leg is the first segment leaving the hotel, the evening leg the
|
||||
// LAST one reaching it. Taking the first for both put an earlier drive that
|
||||
// happens to end on the evening hotel's spot under the day's end, instead of
|
||||
// the drive that closes the day (#2476).
|
||||
const seg = end === 'from'
|
||||
? routeSegments.find(s => sameCoord(s.from, coord))
|
||||
: [...routeSegments].reverse().find(s => sameCoord(s.to, coord))
|
||||
return seg ? { seg, name: accommodationName(a) } : null
|
||||
}
|
||||
return { top: legAt(morning, 'from'), bottom: legAt(evening, 'to') }
|
||||
|
||||
@@ -4,8 +4,8 @@ import { useRouteCalculation } from '../../../../hooks/useRouteCalculation'
|
||||
import { assignmentsApi, reservationsApi, weatherApi } from '../../../../api/client'
|
||||
import { usePluginStore } from '../../../../store/pluginStore'
|
||||
import { getDayBookendHotels } from '../../../../utils/dayOrder'
|
||||
import { getDisplayTimeForDay, getMergedItems, getTransportForDay, hasCarrierEndpointOnDay } from '../../../../utils/dayMerge'
|
||||
import { dayCoMapsUrl, dayGoogleMapsUrl, optimizeDayOrder } from '../lib/dayRoute'
|
||||
import { getDisplayTimeForDay, getMergedItems, getTransportForDay, hasCarrierEndpointOnDay, isCarrierTransport } from '../../../../utils/dayMerge'
|
||||
import { dayCoMapsUrl, dayExportStops, dayGoogleMapsUrl, optimizeDayOrder } from '../lib/dayRoute'
|
||||
import { buildTransitLeg, buildTransitNameIndex, type TransitLeg } from '../../../../components/Planner/transitLeg'
|
||||
import {
|
||||
buildPlanRows, breaksChronology, findUpNext, hotelChipsForDay, hotelLegsForDay, itemHasTime,
|
||||
@@ -60,6 +60,12 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
() => !!day && merged.some(it => it.type === 'transport' && hasCarrierEndpointOnDay(it.data, day.id)),
|
||||
[day, merged],
|
||||
)
|
||||
// Any carrier booked today, located or not. On a day without stops it is the move
|
||||
// itself, so the exports have no road to hand over (#2476).
|
||||
const dayHasCarrierBooking = useMemo(
|
||||
() => merged.some(it => it.type === 'transport' && isCarrierTransport(it.data)),
|
||||
[merged],
|
||||
)
|
||||
|
||||
// Travel-time connectors (walk · distance · drive between consecutive places)
|
||||
// are shown permanently on the mobile timeline. The planner's route instance
|
||||
@@ -318,25 +324,35 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
}
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, dayHasCarrier, tripActions, tripId, pushUndo, updateRouteForDay, toast, t])
|
||||
|
||||
// A route needs two ends. With fewer the map hand-offs would open a lone pin or
|
||||
// nothing at all, so the plan does not offer them (#2476).
|
||||
const canExportRoute = useMemo(
|
||||
() => !!day && dayExportStops(
|
||||
day, days, dayAssignments, tripAccommodations, settings.optimize_from_accommodation !== false,
|
||||
dayHasCarrier, dayHasCarrierBooking,
|
||||
).length >= 2,
|
||||
[day, days, dayAssignments, tripAccommodations, settings, dayHasCarrier, dayHasCarrierBooking],
|
||||
)
|
||||
|
||||
const exportGoogleMaps = useCallback(() => {
|
||||
if (!day) return
|
||||
// Bookend the exported route with the day's accommodation the same way the
|
||||
// drawn route does — only when the leg is real (#1372, #1465).
|
||||
const url = dayGoogleMapsUrl(
|
||||
day, days, dayAssignments, tripAccommodations, settings.optimize_from_accommodation !== false,
|
||||
dayHasCarrier,
|
||||
dayHasCarrier, dayHasCarrierBooking,
|
||||
)
|
||||
if (url) window.open(url, '_blank', 'noopener,noreferrer')
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, dayHasCarrier])
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, dayHasCarrier, dayHasCarrierBooking])
|
||||
|
||||
const exportCoMaps = useCallback(() => {
|
||||
if (!day) return
|
||||
const url = dayCoMapsUrl(
|
||||
day, days, dayAssignments, tripAccommodations, settings.optimize_from_accommodation !== false,
|
||||
day.default_transport_mode ?? routeProfile, dayHasCarrier,
|
||||
day.default_transport_mode ?? routeProfile, dayHasCarrier, dayHasCarrierBooking,
|
||||
)
|
||||
if (url) window.open(url, '_blank', 'noopener,noreferrer')
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, routeProfile, dayHasCarrier])
|
||||
}, [day, dayAssignments, days, tripAccommodations, settings, routeProfile, dayHasCarrier, dayHasCarrierBooking])
|
||||
|
||||
const renameDay = useCallback((title: string) => {
|
||||
if (!day) return
|
||||
@@ -408,7 +424,7 @@ export function useMPlanTimeline(planner: TripPlanner) {
|
||||
moveRow, removeAssignment, editAssignment, editTransport, openTransitJourney,
|
||||
moveRowTo,
|
||||
addPlace, addBooking, addTransport,
|
||||
optimize, exportGoogleMaps, exportCoMaps, renameDay, fullPlaceOf,
|
||||
optimize, canExportRoute, exportGoogleMaps, exportCoMaps, renameDay, fullPlaceOf,
|
||||
routeModeOptions, setLegMode, transitLegFor, planTransitLeg,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user