mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
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.
This commit is contained in:
@@ -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 }))
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<typeof useTranslation>['t'];
|
||||
|
||||
@@ -168,3 +172,44 @@ export function tourDayChoices({ count, fit, wholeFree }: TourDayChoiceFacts, t:
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
type MenuItems = Parameters<ReturnType<typeof useContextMenu>['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];
|
||||
}
|
||||
|
||||
@@ -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<typeof useTranslation>['t'];
|
||||
type MenuItems = Parameters<ReturnType<typeof useContextMenu>['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];
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user