From 7fa8b3fe35ee12b95939942aa9e639e1530a9cdc Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 20 Oct 2026 22:54:57 +0200 Subject: [PATCH] fix(tours): keep the day menu items with the stage logic their views import The pair rule wants TourDayAddButton to import stageSpread; the items it builds belong there anyway. The addon manager test answers the Tours switches, so a failed list is the only thing that toasts. --- .../components/Admin/AddonManager.test.tsx | 6 ++- .../Tours/stages/TourDayAddButton.tsx | 2 +- .../components/Tours/stages/stageSpread.ts | 45 +++++++++++++++++ .../Tours/stages/tourDayHowItems.ts | 49 ------------------- client/src/components/Tours/tourParts.tsx | 2 +- 5 files changed, 52 insertions(+), 52 deletions(-) delete mode 100644 client/src/components/Tours/stages/tourDayHowItems.ts diff --git a/client/src/components/Admin/AddonManager.test.tsx b/client/src/components/Admin/AddonManager.test.tsx index 26781b73d..c5fc07f8c 100644 --- a/client/src/components/Admin/AddonManager.test.tsx +++ b/client/src/components/Admin/AddonManager.test.tsx @@ -78,7 +78,11 @@ beforeEach(() => { vi.spyOn(useAddonStore.getState(), 'loadAddons').mockResolvedValue(undefined); server.use( http.get('/api/admin/addons', () => HttpResponse.json({ addons: [] })), - http.get('/api/admin/tours-wanderer', () => HttpResponse.json({ enabled: false })) + http.get('/api/admin/tours-wanderer', () => HttpResponse.json({ enabled: false })), + // The Tours switches load beside the list; unanswered, each would toast the same error as a failed list. + http.get('/api/admin/tours-hiking-map', () => HttpResponse.json({ enabled: false })), + http.get('/api/admin/tours-cycle-map', () => HttpResponse.json({ enabled: false })), + http.get('/api/admin/tours-ski-routing', () => HttpResponse.json({ enabled: false })) ); }); diff --git a/client/src/components/Tours/stages/TourDayAddButton.tsx b/client/src/components/Tours/stages/TourDayAddButton.tsx index 7ded23cbe..0fddbb560 100644 --- a/client/src/components/Tours/stages/TourDayAddButton.tsx +++ b/client/src/components/Tours/stages/TourDayAddButton.tsx @@ -3,7 +3,7 @@ import type { MouseEvent } from 'react'; import { useTranslation } from '../../../i18n'; import { ContextMenu, useContextMenu } from '../../shared/ContextMenu'; import { DialogButton } from '../../shared/DialogShell'; -import { tourDayHowItems, type TourDayHowInput } from './tourDayHowItems'; +import { tourDayHowItems, type TourDayHowInput } from './stageSpread'; /** * The detail's "Add to day" for the day selected in the plan. A day tour goes diff --git a/client/src/components/Tours/stages/stageSpread.ts b/client/src/components/Tours/stages/stageSpread.ts index 034d59005..e303c1911 100644 --- a/client/src/components/Tours/stages/stageSpread.ts +++ b/client/src/components/Tours/stages/stageSpread.ts @@ -1,6 +1,10 @@ import type { TourListItem } from '@trek/shared'; +import { CalendarDays, CalendarRange } from 'lucide-react'; import type { useTranslation } from '../../../i18n'; import type { AssignmentsMap, Day } from '../../../types'; +import type { useContextMenu } from '../../shared/ContextMenu'; +import { dayMenuLabel } from '../tourDays'; +import type { TourDayAssignment } from '../useTourDayAssignment'; type Translate = ReturnType['t']; @@ -168,3 +172,44 @@ export function tourDayChoices({ count, fit, wholeFree }: TourDayChoiceFacts, t: }, ]; } + +type MenuItems = Parameters['open']>[1]; + +export interface TourDayHowInput { + placeId: number; + dayId: number; + days: Day[]; + /** The stages of the multi-day tour. */ + stageCount: number; + assignment: TourDayAssignment; +} + +/** + * MDT-02: the two ways a multi-day tour goes on a day, as menu items: whole, + * or a stage a day from it on, under the day they act on, so the step after + * the day menu still says which day was picked. Whole is greyed out on a day + * that holds the tour already, and says so; the stages say how many fit when + * the trip ends before them. + */ +export function tourDayHowItems(input: TourDayHowInput, t: Translate, locale: string): MenuItems { + const { placeId, dayId, days, stageCount, assignment } = input; + const facts = { + count: stageCount, + fit: stagesThatFit(days, dayId, stageCount), + wholeFree: !assignment.isOnDay(placeId, dayId), + }; + const ways = tourDayChoices(facts, t).map((choice) => { + const disabled = choice.disabled || !assignment.isAvailable(placeId, dayId, choice.how); + return { + label: choice.title, + // Greyed out with no reason reads as broken; the reason goes right under it. + hint: choice.disabled && choice.how === 'whole' ? choice.hint : undefined, + icon: choice.how === 'whole' ? CalendarDays : CalendarRange, + disabled, + onClick: () => void assignment.assign(placeId, dayId, choice.how), + }; + }); + const at = days.findIndex((day) => day.id === dayId); + if (at < 0) return ways; + return [{ label: dayMenuLabel(days[at], at, t, locale), heading: true }, ...ways]; +} diff --git a/client/src/components/Tours/stages/tourDayHowItems.ts b/client/src/components/Tours/stages/tourDayHowItems.ts deleted file mode 100644 index 21460733a..000000000 --- a/client/src/components/Tours/stages/tourDayHowItems.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { CalendarDays, CalendarRange } from 'lucide-react'; -import type { useTranslation } from '../../../i18n'; -import type { Day } from '../../../types'; -import type { useContextMenu } from '../../shared/ContextMenu'; -import { dayMenuLabel } from '../tourDays'; -import type { TourDayAssignment } from '../useTourDayAssignment'; -import { stagesThatFit, tourDayChoices } from './stageSpread'; - -type Translate = ReturnType['t']; -type MenuItems = Parameters['open']>[1]; - -export interface TourDayHowInput { - placeId: number; - dayId: number; - days: Day[]; - /** The stages of the multi-day tour. */ - stageCount: number; - assignment: TourDayAssignment; -} - -/** - * MDT-02: the two ways a multi-day tour goes on a day, as menu items: whole, - * or a stage a day from it on, under the day they act on, so the step after - * the day menu still says which day was picked. Whole is greyed out on a day - * that holds the tour already, and says so; the stages say how many fit when - * the trip ends before them. - */ -export function tourDayHowItems(input: TourDayHowInput, t: Translate, locale: string): MenuItems { - const { placeId, dayId, days, stageCount, assignment } = input; - const facts = { - count: stageCount, - fit: stagesThatFit(days, dayId, stageCount), - wholeFree: !assignment.isOnDay(placeId, dayId), - }; - const ways = tourDayChoices(facts, t).map((choice) => { - const disabled = choice.disabled || !assignment.isAvailable(placeId, dayId, choice.how); - return { - label: choice.title, - // Greyed out with no reason reads as broken; the reason goes right under it. - hint: choice.disabled && choice.how === 'whole' ? choice.hint : undefined, - icon: choice.how === 'whole' ? CalendarDays : CalendarRange, - disabled, - onClick: () => void assignment.assign(placeId, dayId, choice.how), - }; - }); - const at = days.findIndex((day) => day.id === dayId); - if (at < 0) return ways; - return [{ label: dayMenuLabel(days[at], at, t, locale), heading: true }, ...ways]; -} diff --git a/client/src/components/Tours/tourParts.tsx b/client/src/components/Tours/tourParts.tsx index a3e66575d..7ad46502f 100644 --- a/client/src/components/Tours/tourParts.tsx +++ b/client/src/components/Tours/tourParts.tsx @@ -18,7 +18,7 @@ import type { TourDayAssignment } from './useTourDayAssignment' import { useRailFold } from './railFold' import { tourDayRowIcon } from './tourDayRowIcon' import { SkiCornerMark } from './ski/skiMarks' -import { tourDayHowItems } from './stages/tourDayHowItems' +import { tourDayHowItems } from './stages/stageSpread' /** * A tour's tile in a list: its T-scale grade in place of the mountain, named in