feat(places): planned pool filter + hotel-transfer day routing (#1666)

* fix(dayplan): expose route tools on a hotel-to-hotel transfer day (#1297)

* feat(places): add a Planned filter to the places pool (sidebar, map, mobile)

* fix(places): stretch the mobile pool filter chips to fill the row
This commit is contained in:
Maurice
2026-07-23 21:28:00 +02:00
committed by GitHub
parent c5360be242
commit 8855b5581d
32 changed files with 169 additions and 30 deletions
@@ -210,6 +210,48 @@ describe('DayPlanSidebar', () => {
expect(screen.queryByRole('button', { name: 'Open in Google Maps' })).not.toBeInTheDocument()
})
// ── #1297: route tools for a hotel-to-hotel transfer day with no stops ───────
it('FE-PLANNER-DAYPLAN-005d: route tools show for a two-hotel transfer day with no places (#1297)', () => {
const dayA = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
const dayTransfer = buildDay({ id: 11, date: '2025-06-02', title: 'Day 2' })
const dayB = buildDay({ id: 12, date: '2025-06-03', title: 'Day 3' })
// Check out of hotel A (slept there) and into hotel B on the same day — two distinct
// located hotels, zero places. The map draws A → B, so the tools must be reachable.
const accommodations = [
{ id: 1, start_day_id: 10, end_day_id: 11, place_lat: 48.85, place_lng: 2.35 },
{ id: 2, start_day_id: 11, end_day_id: 12, place_lat: 51.50, place_lng: -0.12 },
]
render(<DayPlanSidebar {...makeDefaultProps({
days: [dayA, dayTransfer, dayB], accommodations: accommodations as any, selectedDayId: 11,
})} />)
expect(screen.getByRole('button', { name: 'Open in Google Maps' })).toBeInTheDocument()
})
it('FE-PLANNER-DAYPLAN-005e: no route tools on a same-hotel rest day with no places (#1297 guard)', () => {
const dayA = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
const dayRest = buildDay({ id: 11, date: '2025-06-02', title: 'Day 2' })
const dayC = buildDay({ id: 12, date: '2025-06-03', title: 'Day 3' })
// One hotel spanning all three days: the middle day has morning === evening, so there is
// no transfer leg to draw and the tools stay hidden.
const accommodations = [{ id: 1, start_day_id: 10, end_day_id: 12, place_lat: 48.85, place_lng: 2.35 }]
render(<DayPlanSidebar {...makeDefaultProps({
days: [dayA, dayRest, dayC], accommodations: accommodations as any, selectedDayId: 11,
})} />)
expect(screen.queryByRole('button', { name: 'Open in Google Maps' })).not.toBeInTheDocument()
})
it('FE-PLANNER-DAYPLAN-005f: no route tools on a plain arrival day with no places (#1297 guard)', () => {
const dayArrive = buildDay({ id: 11, date: '2025-06-02', title: 'Day 1' })
const dayNext = buildDay({ id: 12, date: '2025-06-03', title: 'Day 2' })
// Only a check-in today (no hotel slept in last night, no places): morning === evening,
// so there is no hotel → hotel leg and the tools stay hidden.
const accommodations = [{ id: 2, start_day_id: 11, end_day_id: 12, place_lat: 51.50, place_lng: -0.12 }]
render(<DayPlanSidebar {...makeDefaultProps({
days: [dayArrive, dayNext], accommodations: accommodations as any, selectedDayId: 11,
})} />)
expect(screen.queryByRole('button', { name: 'Open in Google Maps' })).not.toBeInTheDocument()
})
// ── Day expansion/collapse ──────────────────────────────────────────────
it('FE-PLANNER-DAYPLAN-006: days are expanded by default', () => {
@@ -1448,7 +1448,21 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
(routeBookends?.morning?.place_lat != null && routeBookends?.morning?.place_lng != null) ||
(routeBookends?.evening?.place_lat != null && routeBookends?.evening?.place_lng != null)
)
const routeToolsRoutable = da.length >= 2 || (loc != null && hasRouteBookend)
// Transfer day with no stops at all: you check out of one hotel and into another, so
// the map already draws a hotel → hotel leg (see the transfer branch in
// useRouteCalculation) even with zero places. Mirror that exact gate here — two
// distinct bookend hotels you actually slept in / sleep in tonight — so the route
// tools appear when you click the day (#1297). A same-hotel rest day or a plain
// arrival/departure day has morning === evening and stays excluded.
const transferMorning = routeBookends?.morning
const transferEvening = routeBookends?.evening
const hasHotelTransfer = !!(
routeBookends?.morningIsSleptHere && routeBookends?.eveningIsOvernight &&
transferMorning?.place_lat != null && transferMorning?.place_lng != null &&
transferEvening?.place_lat != null && transferEvening?.place_lng != null &&
(transferMorning.place_lat !== transferEvening.place_lat || transferMorning.place_lng !== transferEvening.place_lng)
)
const routeToolsRoutable = da.length >= 2 || (loc != null && hasRouteBookend) || hasHotelTransfer
// Is this day's inline route currently on? Mobile toggles it per day (its
// own expandedRouteDayIds entry); desktop uses the global Route toggle on
// the selected day (#1374).
@@ -2444,7 +2458,7 @@ const DayPlanSidebar = React.memo(function DayPlanSidebar(props: DayPlanSidebarP
)}
</div>
{/* Routen-Werkzeuge (ausgewählter Tag, 2+ Orte — oder 1 Ort mit Hotel-Bookend, #1330) */}
{/* Routen-Werkzeuge (ausgewählter Tag, 2+ Orte — oder 1 Ort mit Hotel-Bookend #1330 — oder Hotel-zu-Hotel-Transfertag ohne Orte #1297) */}
{(isSelected || (showRouteToolsWhenExpanded && isExpanded)) && routeToolsRoutable && (
<div style={{ padding: '10px 16px 12px', borderTop: '1px solid var(--border-faint)', display: 'flex', flexDirection: 'column', gap: 7 }}>
<div style={{ display: 'flex', gap: 6, alignItems: 'stretch' }}>
@@ -242,6 +242,18 @@ describe('Filter tabs', () => {
await user.click(screen.getByRole('button', { name: /Unplanned/i }));
expect(screen.getByText(/All places are planned/i)).toBeInTheDocument();
});
it('FE-PLANNER-SIDEBAR-019b: "Planned" filter shows only planned places', () => {
const planned = buildPlace({ name: 'Planned Place' });
const unplanned = buildPlace({ name: 'Unplanned Place' });
const assignments = { '1': [buildAssignment({ place: planned, day_id: 1 })] };
// Seed the pool filter directly: the tab label resolves from @trek/shared, but the
// filter behaviour (only day-assigned places survive) is what this guards.
seedStore(useTripStore, { placesFilter: 'planned' });
render(<PlacesSidebar {...defaultProps} places={[planned, unplanned]} assignments={assignments} />);
expect(screen.getByText('Planned Place')).toBeInTheDocument();
expect(screen.queryByText('Unplanned Place')).not.toBeInTheDocument();
});
});
// ── Search ────────────────────────────────────────────────────────────────────
@@ -86,13 +86,15 @@ export function PlacesHeader(S: SidebarState) {
const counts = {
all: baseFiltered.length,
unplanned: baseFiltered.filter(p => !plannedIds.has(p.id)).length,
planned: baseFiltered.filter(p => plannedIds.has(p.id)).length,
tracks: baseFiltered.filter(p => p.route_geometry).length,
}
const tabs = ([
{ id: 'all', label: t('places.all') },
{ id: 'unplanned', label: t('places.unplanned') },
{ id: 'planned', label: t('places.planned') },
hasTracks ? { id: 'tracks', label: t('places.filterTracks') } : null,
] as const).filter(Boolean) as Array<{ id: 'all' | 'unplanned' | 'tracks'; label: string }>
] as const).filter(Boolean) as Array<{ id: 'all' | 'unplanned' | 'planned' | 'tracks'; label: string }>
return (
<div style={{ display: 'flex', gap: 6, marginBottom: 8, flexWrap: 'wrap' }}>
{tabs.map(f => {
@@ -201,6 +201,7 @@ export function usePlacesSidebar(props: PlacesSidebarProps) {
const filtered = useMemo(() => {
const list = places.filter(p => {
if (filter === 'unplanned' && plannedIds.has(p.id)) return false
if (filter === 'planned' && !plannedIds.has(p.id)) return false
if (filter === 'tracks' && !p.route_geometry) return false
if (categoryFilters.size > 0) {
if (p.category_id == null) {