mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
feat(tours): show a multi-day tour's stages in the list and put each on a day
A multi-day tour in the planner's list of the trip's tours now unfolds into its stages (MDT-02), so the stages can be seen together and fitted into the trip without leaving the one route they are cut from. - The fold beside a multi-day tour lists its stages in route order, each from stop to stop with its distance, climb, descent and moving time, read off the saved tour the way the planner reads them, and below them what the whole tour adds up to. A value no stage tells is left out, a total some stages do not tell is marked as at least that much and says for how many, and a stage whose route is not planned yet says so. - Each stage has its own day: a pill opens the trip's days, moves the stage to another one or takes it off again. A stage without a day shows a dashed "No day" pill. A day holds a tour, or one of its stages, once, and a stage is on one day at most; the plan's own offline path writes it. - A stage opens in the planner: the tour opens as any tour does and the stage is shown once its points are in. - The day plan names the stage a day holds with its own figures, and the day's route runs to that stage's start and on from its end; the trip map draws that stretch only. The tour list still counts a tour once, however many days hold it or its stages. - A saved change that takes a stage away (its stage end gone, the tour a day tour again, back to the recorded track) takes it off its day in the same write and tells every client; the planner says so before the save. - REST and the assign_place_to_day tool take the stage by the key of the stop it starts at, with the same checks; list_tours names the stops between the stages and the stage each day holds. A day assignment remembers its stage by that key (migration 046010); every assignment made before holds the whole tour, as it did.
This commit is contained in:
@@ -12,6 +12,7 @@ import type { Day } from '../../../types'
|
||||
import { publishTourFerrataCrossings } from '../../../store/tourFerrataCrossingStore'
|
||||
import { TourPlannerRail, TourPlannerToursRail } from './TourPlannerPanels'
|
||||
import { hikePlannerDefaults } from '../../../../tests/helpers/tourPlannerStub'
|
||||
import { tourRepo } from '../../../repo/tourRepo'
|
||||
|
||||
vi.mock('../../../../../server/src/config', () => { throw new Error('Config initialization is forbidden in client tests') })
|
||||
vi.mock('../../../../../server/src/db/database', () => { throw new Error('Legacy database imports are forbidden in client tests') })
|
||||
@@ -127,6 +128,17 @@ beforeEach(() => {
|
||||
})
|
||||
|
||||
describe('TourPlannerToursRail', () => {
|
||||
it('MDT-02: a multi-day tour unfolds its stages in the list, a day tour has nothing to unfold', async () => {
|
||||
vi.spyOn(tourRepo, 'detail').mockResolvedValue({ tour, waypoints: [] })
|
||||
const hutToHut = { ...tour, place_id: 43, name: 'Hut to hut', stage_count: 2 }
|
||||
render(<TourPlannerToursRail planner={planner({ mode: { type: 'new-draft' } })} tours={[tour, hutToHut]} {...railProps} />)
|
||||
expect(screen.getAllByRole('button', { name: 'Show stages' })).toHaveLength(1)
|
||||
expect(screen.queryByTestId('tour-stage-overview')).toBeNull()
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Show stages' }))
|
||||
expect(screen.getByTestId('tour-stage-overview')).toHaveAttribute('id', 'tour-stages-43')
|
||||
expect(screen.getByRole('button', { name: 'Hide stages' })).toHaveAttribute('aria-expanded', 'true')
|
||||
})
|
||||
|
||||
it('RS-02: keeps calculated Walking time visible in the right Tour metrics rail', () => {
|
||||
render(<TourPlannerToursRail planner={planner({
|
||||
mode: { type: 'new-draft' }, durationSeconds: 4800,
|
||||
|
||||
@@ -32,9 +32,13 @@ import type { SkiClassification } from '../ski/useSkiClassification'
|
||||
import { TourTypeFields } from './TourTypeFields'
|
||||
import TourWaypointList from './TourWaypointList'
|
||||
import { TourStageLossNotice } from '../stages/TourStageLossNotice'
|
||||
import { TourStageDayNotice } from '../stages/TourStageDayNotice'
|
||||
import { TourStageModeField } from '../stages/TourStageModeField'
|
||||
import { TourStagesSection } from '../stages/TourStagesSection'
|
||||
import { stageBoundariesM } from '../stages/tourStages'
|
||||
import { TourStageOverview } from '../stages/TourStageOverview'
|
||||
import { useTourStageRail } from '../stages/useTourStageRail'
|
||||
import { useTripStore } from '../../../store/tripStore'
|
||||
import type { DistanceIndexedProfileSample, RouteProfileFocus } from '../../../utils/routeGeometry'
|
||||
import type { TourPlannerController, TourPlannerStatus } from './useTourPlanner'
|
||||
import { useTourPermissions, type TourPermissionProps } from '../useTourPermissions'
|
||||
@@ -473,6 +477,7 @@ export function TourPlannerRail({ planner,
|
||||
<UnreachableNotice planner={planner} />
|
||||
|
||||
<TourStageLossNotice planner={planner} />
|
||||
<TourStageDayNotice planner={planner} />
|
||||
|
||||
<TourWaypointList planner={planner} canEdit={canEdit} isSaving={isSaving} tourPlaceIds={tourPlaceIds} />
|
||||
|
||||
@@ -731,12 +736,28 @@ function plannerTimeFields(planner: TourPlannerController, t: Translate): TourMe
|
||||
]
|
||||
}
|
||||
|
||||
/** MDT-02: the id of a tour's unfolded stages, which its fold button controls. */
|
||||
const stageListId = (tour: TourListItem) => `tour-stages-${tour.place_id}`
|
||||
|
||||
/** The fold of a multi-day tour's row in the list; none for a day tour. */
|
||||
function stagesFold(tour: TourListItem, rail: ReturnType<typeof useTourStageRail>, t: (key: string) => string) {
|
||||
if ((tour.stage_count ?? 0) < 2) return undefined
|
||||
const expanded = rail.isUnfolded(tour.place_id)
|
||||
return {
|
||||
expanded,
|
||||
onToggle: () => rail.toggle(tour.place_id),
|
||||
label: t(expanded ? 'tours.stages.fold' : 'tours.stages.unfold'),
|
||||
controls: stageListId(tour),
|
||||
}
|
||||
}
|
||||
|
||||
export function TourPlannerToursRail({ planner, tours, days, loading, onAssignToDay, onViewGpxTour, onDeleteTour,
|
||||
gpxImport, onTakenOver, canEdit: editPermission, canAssign: assignPermission }: TourPlannerToursRailProps) {
|
||||
const { canEdit, canAssign } = useTourPermissions({ canEdit: editPermission ?? planner.canEdit, canAssign: assignPermission ?? planner.canAssign })
|
||||
const { t } = useTranslation()
|
||||
const toast = useToast()
|
||||
const distanceUnit = useSettingsStore(state => state.settings.distance_unit)
|
||||
const tripId = useTripStore(state => state.trip?.id)
|
||||
const [pendingTour, setPendingTour] = useState<TourListItem | null>(null)
|
||||
const dayAssignment = useTourDayAssignment({ canAssign, onAssignToDay })
|
||||
// STA-01: one filter for the list and the summary above it, the same as the plan's tour list.
|
||||
@@ -776,6 +797,8 @@ export function TourPlannerToursRail({ planner, tours, days, loading, onAssignTo
|
||||
}
|
||||
selectTour(tour)
|
||||
}
|
||||
// MDT-02: a multi-day tour unfolds its stages here, and a stage opens in the planner.
|
||||
const stageRail = useTourStageRail(planner, requestOpenTour)
|
||||
|
||||
const tourTimeFields = plannerTimeFields(planner, t)
|
||||
|
||||
@@ -835,6 +858,7 @@ export function TourPlannerToursRail({ planner, tours, days, loading, onAssignTo
|
||||
disabled={isSaving}
|
||||
selected={(planner.mode.type === 'edit-saved' || planner.mode.type === 'view-gpx') && planner.mode.placeId === tour.place_id}
|
||||
onSelect={requestOpenTour}
|
||||
fold={stagesFold(tour, stageRail, t)}
|
||||
action={((canAssign && days.length > 0) || (canEdit && onDeleteTour)) ? (
|
||||
<>
|
||||
{canAssign && days.length > 0 && (
|
||||
@@ -860,7 +884,12 @@ export function TourPlannerToursRail({ planner, tours, days, loading, onAssignTo
|
||||
)}
|
||||
</>
|
||||
) : undefined}
|
||||
/>
|
||||
>
|
||||
{stageRail.isUnfolded(tour.place_id) && (tour.stage_count ?? 0) > 1 && (
|
||||
<TourStageOverview id={stageListId(tour)} tripId={tripId} tour={tour} days={days} canAssign={canAssign}
|
||||
onOpenStage={isSaving ? undefined : stageRail.openStage} />
|
||||
)}
|
||||
</TourListRow>
|
||||
))}
|
||||
</TourListCard>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user