mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 01:44:13 +00:00
fix(planner): a booked hotel stays in the place list when road trip stops are hidden in Days
Since 4.3.0 every lodging booking types its place as 'hotel', and 'hotel' is one of the road trip stop types. With "Show in Days too" switched off, Days dropped every such place from the trip's place list, so a hotel vanished from the sidebar, from the booking's own place picker and from the Days map the moment it was booked, and a click on it in the day list found nothing. Nothing was deleted: road trip mode kept showing it. Days now leaves out only road trip stops nobody booked. A lodging place stays, and so does any place a stay or a booking points at, on the desktop and on the phone. Trips planned on 4.3.1 show their hotels again without any change to their data. An imported GPX or KML track is no longer offered as the place of a stay, in the booking form, the day's hotel picker and the phone's sheets. A stay that already names a track keeps showing it.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { resolvePoolAssignmentId } from './tripPlannerModel'
|
||||
import { placesForDays, resolvePoolAssignmentId } from './tripPlannerModel'
|
||||
import { buildAssignment, buildPlace } from '../../../tests/helpers/factories'
|
||||
|
||||
describe('resolvePoolAssignmentId', () => {
|
||||
@@ -23,3 +23,35 @@ describe('resolvePoolAssignmentId', () => {
|
||||
expect(resolvePoolAssignmentId(assignments, 7)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('placesForDays', () => {
|
||||
const town = buildPlace({ id: 1, stop_type: null })
|
||||
const hotel = buildPlace({ id: 2, stop_type: 'hotel' })
|
||||
const pump = buildPlace({ id: 3, stop_type: 'fuel' })
|
||||
const brauhaus = buildPlace({ id: 4, stop_type: 'restaurant' })
|
||||
const campsite = buildPlace({ id: 5, stop_type: 'campsite' })
|
||||
const all = [town, hotel, pump, brauhaus, campsite]
|
||||
const none = { accommodations: [], reservations: [] }
|
||||
|
||||
it('FE-TP-MODEL-001: hands the list back untouched while road trip stops show in Days', () => {
|
||||
expect(placesForDays(all, false, none)).toBe(all)
|
||||
})
|
||||
|
||||
it('FE-TP-MODEL-002: leaves out every road trip stop nobody booked, but never a lodging', () => {
|
||||
// The hotel's booking may be gone; the 'hotel' type it stamped on the place is not.
|
||||
expect(placesForDays(all, true, none).map(p => p.id)).toEqual([1, 2])
|
||||
})
|
||||
|
||||
it('FE-TP-MODEL-003: keeps the place a stay is at, whatever type it carries', () => {
|
||||
const kept = placesForDays(all, true, { accommodations: [{ place_id: 5 }, { place_id: null }], reservations: [] })
|
||||
expect(kept.map(p => p.id)).toEqual([1, 2, 5])
|
||||
})
|
||||
|
||||
it('FE-TP-MODEL-004: keeps the place a booking names, directly or through its stay', () => {
|
||||
const kept = placesForDays(all, true, {
|
||||
accommodations: [],
|
||||
reservations: [{ place_id: 4 }, { accommodation_place_id: 5 }, { place_id: null, accommodation_place_id: null }],
|
||||
})
|
||||
expect(kept.map(p => p.id)).toEqual([1, 2, 4, 5])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,8 +4,42 @@
|
||||
* the FE "page = wiring container + data hook" convention (see PATTERN.md).
|
||||
*/
|
||||
|
||||
import { isServiceStopType } from '../../components/Roadtrip/roadtripModel'
|
||||
import type { Assignment } from '../../types'
|
||||
|
||||
/** What a stay or a booking says about the place it is for. */
|
||||
export interface BookedPlaceSources {
|
||||
accommodations: { place_id?: number | null }[]
|
||||
reservations: { place_id?: number | null; accommodation_place_id?: number | null }[]
|
||||
}
|
||||
|
||||
/**
|
||||
* The trip's places as Days shows them.
|
||||
*
|
||||
* With "Show in Days too" switched off, a place typed as a road trip stop (a pump, a
|
||||
* rest area, a campsite) belongs to the drive and stays out of Days, list and map alike.
|
||||
* A place a stay or a booking points at is not such a stop, whatever its type says, and
|
||||
* neither is lodging: every lodging booking types its place as 'hotel', the type stays
|
||||
* after the booking is gone, and dropping it took the booked hotel out of the place
|
||||
* list, the booking's own place picker and the Days map the moment it was booked.
|
||||
*/
|
||||
export function placesForDays<P extends { id: number; stop_type?: string | null }>(
|
||||
places: P[],
|
||||
hideRoadtripStops: boolean,
|
||||
{ accommodations, reservations }: BookedPlaceSources,
|
||||
): P[] {
|
||||
if (!hideRoadtripStops) return places
|
||||
const booked = new Set<number>()
|
||||
for (const stay of accommodations) {
|
||||
if (stay.place_id != null) booked.add(stay.place_id)
|
||||
}
|
||||
for (const reservation of reservations) {
|
||||
if (reservation.place_id != null) booked.add(reservation.place_id)
|
||||
if (reservation.accommodation_place_id != null) booked.add(reservation.accommodation_place_id)
|
||||
}
|
||||
return places.filter(place => !isServiceStopType(place.stop_type) || place.stop_type === 'hotel' || booked.has(place.id))
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the day-assignment to use when a place is edited from the Places pool,
|
||||
* where no day is in context. Times live per day-assignment (#1247), so we can
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { roadtripPreferencesRepo } from '../../repo/roadtripPreferencesRepo'
|
||||
// FE-TP-ROAD-001 to FE-TP-ROAD-153
|
||||
// FE-TP-ROAD-001 to FE-TP-ROAD-154
|
||||
import React from 'react'
|
||||
import { renderHook, act, waitFor } from '@testing-library/react'
|
||||
import { TranslationProvider } from '../../i18n/TranslationContext'
|
||||
@@ -2293,6 +2293,38 @@ it('preserves exclusive service stops when reordering the visible Days stops', a
|
||||
expect(actions.reorderAssignments).toHaveBeenCalledWith(42, 5, [13, 12, 11])
|
||||
})
|
||||
|
||||
it('FE-TP-ROAD-154: a place a booking points at stays in Days while road trip stops are hidden there', async () => {
|
||||
// Every lodging booking types its place as 'hotel', and 'hotel' is a road trip stop
|
||||
// type. With "Show in Days too" off, Days dropped the booked hotel from the place list,
|
||||
// from the booking's own place picker and from the map the moment it was booked.
|
||||
const town = buildPlace({ id: 101, name: 'Cologne' })
|
||||
const hotel = buildPlace({ id: 102, name: 'Cologne Cathedral', stop_type: 'hotel' })
|
||||
const pump = buildPlace({ id: 103, name: 'Pump', stop_type: 'fuel' })
|
||||
const brauhaus = buildPlace({ id: 104, name: 'Brauhaus', stop_type: 'restaurant' })
|
||||
const campsite = buildPlace({ id: 105, name: 'Camping Rhein', stop_type: 'campsite' })
|
||||
seedTrip({
|
||||
places: [town, hotel, pump, brauhaus, campsite],
|
||||
days: [buildDay({ id: 5 }), buildDay({ id: 6 })],
|
||||
reservations: [
|
||||
buildReservation({ id: 9, type: 'restaurant', place_id: 104, day_id: 5 }),
|
||||
buildReservation({ id: 10, type: 'hotel', accommodation_id: 8, accommodation_place_id: 105 }),
|
||||
],
|
||||
})
|
||||
vi.mocked(accommodationRepo.list).mockResolvedValue({
|
||||
accommodations: [{ id: 7, trip_id: 42, place_id: 102, start_day_id: 5, end_day_id: 6, reservation_title: null }],
|
||||
} as never)
|
||||
useSettingsStore.setState(s => ({ settings: { ...s.settings, roadtrip_service_stops_in_days: false } }))
|
||||
const { result } = await renderRoadtrip()
|
||||
|
||||
act(() => result.current.toggleRoadtripMode())
|
||||
|
||||
// The pump nobody booked stays a road trip stop, out of Days.
|
||||
await waitFor(() => expect(result.current.places.map(p => p.id)).toEqual([101, 102, 104, 105]))
|
||||
// Road trip mode keeps every place, as before.
|
||||
act(() => result.current.toggleRoadtripMode())
|
||||
expect(result.current.places.map(p => p.id)).toEqual([101, 102, 103, 104, 105])
|
||||
})
|
||||
|
||||
/**
|
||||
* The phone's own way into the drive.
|
||||
*
|
||||
|
||||
@@ -67,7 +67,7 @@ import type { Accommodation, Assignment, TripMember, Day, Place, Reservation } f
|
||||
import { OFM_POSITRON, DEFAULT_MAP_LAT, DEFAULT_MAP_LNG, DEFAULT_MAP_ZOOM } from '../../constants/mapDefaults'
|
||||
import { useTileUrl } from '../../hooks/useTileUrl'
|
||||
import { applyStayStops } from '../../store/stayStops'
|
||||
import { resolvePoolAssignmentId } from './tripPlannerModel'
|
||||
import { placesForDays, resolvePoolAssignmentId } from './tripPlannerModel'
|
||||
import { isDeepLinkableTripTab, TRIP_TAB_LABEL_KEYS } from '../../constants/tripTabs'
|
||||
import { isRoutableReservation } from '../../utils/reservationRoutes'
|
||||
import {
|
||||
@@ -175,7 +175,6 @@ export function useTripPlanner() {
|
||||
Object.entries(storedAssignments).map(([dayId, visits]) => [dayId, visits.filter(v => !hidden(v))]),
|
||||
)
|
||||
}, [roadtripMode, roadtripSettings.roadtrip_service_stops_in_days, storedAssignments])
|
||||
const places = useMemo(() => roadtripMode || roadtripSettings.roadtrip_service_stops_in_days !== false ? allPlaces : allPlaces.filter(place => !isServiceStopType(place.stop_type)), [roadtripMode, roadtripSettings.roadtrip_service_stops_in_days, allPlaces])
|
||||
const toggleRoadtripMode = useCallback(() => {
|
||||
setRoadtripMode(prev => {
|
||||
const next = !prev
|
||||
@@ -185,6 +184,12 @@ export function useTripPlanner() {
|
||||
}, [tripId])
|
||||
const [collabFeatures, setCollabFeatures] = useState<{ chat: boolean; notes: boolean; links: boolean; polls: boolean; whatsnext: boolean }>({ chat: true, notes: true, links: true, polls: true, whatsnext: true })
|
||||
const [tripAccommodations, setTripAccommodations] = useState<Accommodation[]>([])
|
||||
const places = useMemo(
|
||||
() => (roadtripMode
|
||||
? allPlaces
|
||||
: placesForDays(allPlaces, roadtripSettings.roadtrip_service_stops_in_days === false, { accommodations: tripAccommodations, reservations })),
|
||||
[roadtripMode, roadtripSettings.roadtrip_service_stops_in_days, allPlaces, tripAccommodations, reservations],
|
||||
)
|
||||
const [allowedFileTypes, setAllowedFileTypes] = useState<string | null>(null)
|
||||
const [tripMembers, setTripMembers] = useState<TripMember[]>([])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user