feat(tours): show the known SAC grades along a hike (MAP-03)

A hike in the planner, being edited or viewed as an import, now has an
"SAC grades" card. Switched on, it asks the router which OpenStreetMap
ways lie under the line (matched on foot, every grade of path open) and
the server reads their sac_scale through the Overpass mirrors, the same
trail-grades read the mountain bike grades use. The grades are drawn
along the route on the planner map in one ramp of a single hue, T1 to
T6, and listed by share and length; a row draws its class alone. Each
row names its source in a tooltip: the SAC hiking scale and the
sac_scale value OpenStreetMap wrote.

What is not known stays unknown and says why, never T1: a way without
a grade, a grade that names no single step (handed on as written), a
stretch with no way clearly under the tour's line, or a way that could
not be asked about. For imported tracks and stretches drawn by hand a
matched way only counts where it keeps within 25 m of the tour's own
line, so the original line is kept and nothing is guessed. The router's
own reading of the scale is not asked for, since it may be normalised.

The routing limit of a planned hike sits apart as a setting with its
own badge, and a known step above it is marked. Nothing about the tour,
its places or its days changes; switched off, the map is as it was.
No regional colour categories and no grade derived from slope, height
or trail markings.
This commit is contained in:
Maurice
2026-10-20 12:25:20 +02:00
parent ad2d653e9a
commit ea9e997338
63 changed files with 2327 additions and 108 deletions
@@ -23,6 +23,14 @@ vi.mock('../paddle/PaddleCheckCard', () => ({
),
}))
// MAP-03: the SAC card is its own suite's; here it only has to sit where the rails put it, with what they hand it.
vi.mock('../hike/SacGradesCard', () => ({
SacGradesCard: ({ route, routeCurrent, routingLimit }: { route: [number, number][] | null; routeCurrent?: boolean; routingLimit: number | null }) => (
<div data-testid="sac-grades-card" data-route={route ? route.length : 'none'} data-current={String(routeCurrent ?? true)}
data-limit={String(routingLimit)} />
),
}))
const tour: TourListItem = {
place_id: 42,
name: 'Saved ridge walk',
@@ -1015,3 +1023,33 @@ describe('a run in the planner rails (RUN-01)', () => {
expect(screen.getByTestId('tour-planner-unreachable')).toHaveTextContent('900 m')
})
})
describe('SAC grades in the planner rails (MAP-03)', () => {
it('MAP03-RAIL-001: a hike being edited carries the card with its line, whether it is planned now, and its routing limit', () => {
const { unmount } = render(<TourPlannerRail planner={planner({ mode: { type: 'new-draft' }, routeCurrent: true, maxHikingDifficulty: 3 })} />)
const card = screen.getByTestId('sac-grades-card')
expect(card).toHaveAttribute('data-route', '2')
expect(card).toHaveAttribute('data-current', 'true')
expect(card).toHaveAttribute('data-limit', '3')
unmount()
render(<TourPlannerRail planner={planner({ mode: { type: 'new-draft' }, routeCurrent: false })} />)
expect(screen.getByTestId('sac-grades-card')).toHaveAttribute('data-current', 'false')
})
it('MAP03-RAIL-002: a hike import carries it without a routing limit; a bike tour and a bike import do not', () => {
const geometry = JSON.stringify([[48, 11, 500], [48, 11.01, 550], [48, 11.02, 520]])
const imported = (tourType: 'hike' | 'bike') => planner({
readOnlyGpxTour: { tour: { ...tour, tour_type: tourType, has_waypoints: false }, routeGeometry: geometry },
readOnlyGpxAnalysis: analyzeRouteGeometry(geometry),
})
const hike = render(<TourPlannerRail planner={imported('hike')} />)
expect(screen.getByTestId('sac-grades-card')).toHaveAttribute('data-route', '3')
expect(screen.getByTestId('sac-grades-card')).toHaveAttribute('data-limit', 'null')
hike.unmount()
const bikeImport = render(<TourPlannerRail planner={imported('bike')} />)
expect(screen.queryByTestId('sac-grades-card')).toBeNull()
bikeImport.unmount()
render(<TourPlannerRail planner={planner({ mode: { type: 'new-draft' }, tourType: 'bike', isBike: true, routeCurrent: false })} />)
expect(screen.queryByTestId('sac-grades-card')).toBeNull()
})
})
@@ -53,6 +53,7 @@ import { BikeWaysCard } from '../bike/BikeWaysCard'
import { RunWaysCard } from '../run/RunWaysCard'
import { HorseRoutesCard } from '../horse/HorseRoutesCard'
import { RecordedRideCard } from '../horse/RecordedRideFacts'
import { SacGradesCard } from '../hike/SacGradesCard'
import { walkTimeFields } from '../walk/walkTimeFields'
const STATUS_KEY: Partial<Record<TourPlannerStatus, string>> = {
@@ -349,6 +350,9 @@ function GpxViewRail({
</p>
)}
</RailCard>
{tour.tour_type === 'hike' && (
<SacGradesCard tripId={planner.tripId} route={analysis?.routeCoordinates ?? null} routingLimit={null} />
)}
</div>
{tour.tour_type === 'kayak' && (
<div className="flex-none border-t border-edge-faint px-3 py-3">
@@ -470,6 +474,11 @@ export function TourPlannerRail({ planner,
<HorseRoutesCard planner={planner} />
{planner.tourType === 'hike' && (
<SacGradesCard tripId={planner.tripId} route={planner.route} routeCurrent={planner.routeCurrent}
routingLimit={planner.maxHikingDifficulty} />
)}
<TourPoiSearchCard planner={planner} />
<PaddleEditorCards planner={planner} locked={locked} checklist={paddleChecklist} />