fix(tours): keep unknown actual tracks unknown and name every track a link replaces (ACT-01)

A tour detail that cannot be read (offline without a cached copy, or a server
error) no longer shows "No actual track yet" while the trip list names tracks
of the tour; the section says they could not be loaded and offers no link over
them.

The day a track was recorded on is the viewer's calendar day of its first time
stamp, not the UTC one, in the tour detail, the link dialog and the GPX
preview alike, through one helper.

Taking a tour off a day keeps its actual track without a day, so "no day" can
hold several. A change now starts on the track it was asked for, and the link
dialog names every track it replaces, as the server clears all of them. The
migration, repository, service and MCP texts say so.

The refusal for linking a tour to itself or a track with tracks of its own now
reads "This track cannot be linked to this tour", which is true of both, and
the offline helper of the tour cache sits above the doc of replaceTripTours
again.
This commit is contained in:
Maurice
2026-10-20 12:50:38 +02:00
parent d0cc6fc2f4
commit a8be1c5b45
46 changed files with 243 additions and 100 deletions
@@ -5,7 +5,6 @@ import { OFM_POSITRON } from '../../constants/mapDefaults';
import { useTileUrl } from '../../hooks/useTileUrl';
import { useTranslation } from '../../i18n';
import { useSettingsStore } from '../../store/settingsStore';
import { formatDate } from '../../utils/formatters';
import { formatDistance, formatElevation } from '../../utils/units';
import { MapViewAuto } from '../Map/MapViewAuto';
import { SoftPill } from '../Planner/planParts';
@@ -20,7 +19,7 @@ import {
fs,
NEUTRAL_TINT,
} from '../shared/DialogShell';
import { recordedMinutes } from './activity/tourActivityModel';
import { recordedDay, recordedMinutes } from './activity/tourActivityModel';
import { importFields, importMissing, useGpxImportChoices } from './gpxImportChoices';
import { GpxImportTypeSection } from './GpxImportTypeSection';
import { TourNotice } from './tourParts';
@@ -34,11 +33,12 @@ const BADGE =
function RecordedBadge({ track }: { track: GpxPreviewFile['tracks'][number] }) {
const { locale } = useTranslation();
const minutes = recordedMinutes(track.started_at, track.ended_at);
if (minutes === null || !track.started_at) return null;
const day = recordedDay(track.started_at, locale);
if (minutes === null || !day) return null;
return (
<span className={`${BADGE} gap-1`} data-testid="gpx-preview-recorded">
<Clock size={10} strokeWidth={2.2} className="flex-none text-content-faint" />
{formatDate(track.started_at.slice(0, 10), locale)}
{day}
<span className="text-content-faint">{formatPlannedTourDuration(minutes)}</span>
</span>
);
@@ -37,7 +37,7 @@ function assignment(overrides: Partial<TrackAssignment> = {}): TrackAssignment {
selected: 20,
choose: vi.fn(),
choice: watch,
replaces: null,
replaces: [],
gpxImport: {
importing: false,
preview: null,
@@ -93,7 +93,7 @@ describe('TourActivityDialog (ACT-01)', () => {
});
it('FE-ACT-DIALOG-003: nothing to link until a free recording is chosen; what it replaces is said', () => {
hook.assignment = assignment({ ready: false, choice: null, selected: null, replaces: 'Old export' });
hook.assignment = assignment({ ready: false, choice: null, selected: null, replaces: ['Old export'] });
const current = state();
show(current);
expect(screen.getByTestId('tour-activity-confirm')).toBeDisabled();
@@ -23,7 +23,7 @@ import { PillSelect } from '../../shared/dialogParts';
import TourGpxPreviewDialog from '../TourGpxPreviewDialog';
import { CardAction, TourMetricFields, TourNotice } from '../tourParts';
import { formatPlannedTourDuration, hikeSourceBadgeLabel } from '../tourPresentation';
import { recordedMinutes, type TourExecution, type TrackCandidate } from './tourActivityModel';
import { recordedDay, recordedMinutes, type TourExecution, type TrackCandidate } from './tourActivityModel';
import type { TourActivities } from './useTourActivities';
import { useTrackAssignment, type TrackAssignment } from './useTrackAssignment';
@@ -44,7 +44,7 @@ function CandidateRow({
const unit = useSettingsStore((store) => store.settings.distance_unit) ?? 'metric';
const { tour, takenBy } = candidate;
const minutes = recordedMinutes(tour.track_started_at, tour.track_ended_at);
const recordedOn = tour.track_started_at ? formatDate(tour.track_started_at.slice(0, 10), locale) : null;
const recordedOn = recordedDay(tour.track_started_at, locale);
return (
<button
type="button"
@@ -269,9 +269,9 @@ export default function TourActivityDialog({
>
<div className="flex flex-col gap-2">
<CandidateList assignment={assignment} />
{assignment.replaces && (
{assignment.replaces.length > 0 && (
<TourNotice tone="warning" icon={<AlertTriangle size={13} strokeWidth={2} />}>
{t('tours.activity.replaces', { name: assignment.replaces })}
{t('tours.activity.replaces', { name: assignment.replaces.join(', ') })}
</TourNotice>
)}
</div>
@@ -1,4 +1,4 @@
// FE-ACT-SECTION-001 to FE-ACT-SECTION-005
// FE-ACT-SECTION-001 to FE-ACT-SECTION-006
// ACT-01 in the tour's detail, rendered without the translation provider so
// every text reads as its key: the actual tracks with their own values marked
// as such, a time only where the track measured one, and the actions only for
@@ -45,6 +45,7 @@ function activity(overrides: Partial<TourActivity['metrics']> = {}, assignmentId
function state(overrides: Partial<TourActivities> = {}): TourActivities {
return {
activities: [activity()],
unavailable: false,
canEdit: true,
busy: false,
assigning: null,
@@ -94,7 +95,7 @@ describe('TourActivitySection (ACT-01)', () => {
fireEvent.click(screen.getByRole('button', { name: /tours.activity.assign$/ }));
expect(current.openAssign).toHaveBeenCalledWith();
fireEvent.click(screen.getByRole('button', { name: /tours.activity.change/ }));
expect(current.openAssign).toHaveBeenCalledWith({ assignmentId: 11 });
expect(current.openAssign).toHaveBeenCalledWith({ assignmentId: 11, activityId: 4 });
fireEvent.click(screen.getByRole('button', { name: /tours.activity.remove/ }));
expect(current.askRemove).toHaveBeenCalledWith(current.activities?.[0]);
@@ -132,4 +133,17 @@ describe('TourActivitySection (ACT-01)', () => {
const track = show(true, { ...tour, activity_of: 3 });
expect(track.container).toBeEmptyDOMElement();
});
it('FE-ACT-SECTION-006: tracks that could not be read are said to be unavailable, never shown as none, and nothing is linked over them', () => {
hook.state = state({ activities: [], unavailable: true });
const { unmount } = show();
expect(screen.getByRole('status')).toHaveTextContent('tours.activity.unavailable');
expect(screen.queryByTestId('tour-activity-empty')).toBeNull();
expect(screen.getByRole('button', { name: /tours.activity.assign$/ })).toBeDisabled();
unmount();
hook.state = state({ activities: [], unavailable: true, canEdit: false });
show(false);
expect(screen.getByText('tours.activity.unavailable')).toBeInTheDocument();
});
});
@@ -1,10 +1,9 @@
import type { TourActivity, TourListItem } from '@trek/shared';
import { CalendarDays, Clock, FileDown, Footprints, Plus, RefreshCw, Unlink } from 'lucide-react';
import { CalendarDays, Clock, CloudOff, FileDown, Footprints, Plus, RefreshCw, Unlink } from 'lucide-react';
import { useMemo } from 'react';
import { useTranslation } from '../../../i18n';
import { useSettingsStore } from '../../../store/settingsStore';
import type { AssignmentsMap, Day } from '../../../types';
import { formatDate } from '../../../utils/formatters';
import { BOX } from '../../Planner/bookings/bookingParts';
import { SoftPill } from '../../Planner/planParts';
import ConfirmDialog from '../../shared/ConfirmDialog';
@@ -12,10 +11,10 @@ import { DialogSection, fs } from '../../shared/DialogShell';
import ElevationProfile from '../../shared/ElevationProfile';
import { Tooltip } from '../../shared/Tooltip';
import { dayMenuLabel } from '../tourDays';
import { CardAction, TourMetricFields, type TourMetricField } from '../tourParts';
import { CardAction, TourMetricFields, TourNotice, type TourMetricField } from '../tourParts';
import { formatPlannedTourDuration } from '../tourPresentation';
import TourActivityDialog from './TourActivityDialog';
import { analysisOfLine, executionOf, executionsOf, type TourExecution } from './tourActivityModel';
import { analysisOfLine, executionOf, executionsOf, recordedDay, type TourExecution } from './tourActivityModel';
import { useTourActivities, type TourActivities } from './useTourActivities';
type Translate = (key: string, params?: Record<string, unknown>) => string;
@@ -50,7 +49,7 @@ function ActivityBadges({ activity, execution }: { activity: TourActivity; execu
const { t, locale } = useTranslation();
const dayLabel = execution.day ? t('dayplan.dayN', { n: execution.index + 1 }) : t('tours.activity.noDay');
const dayTitle = execution.day ? dayMenuLabel(execution.day, execution.index, t, locale) : dayLabel;
const recordedOn = activity.metrics.started_at ? formatDate(activity.metrics.started_at.slice(0, 10), locale) : null;
const recordedOn = recordedDay(activity.metrics.started_at, locale);
const source =
activity.track.file_name ?? t(activity.track.origin === 'wanderer' ? 'tours.badge.wanderer' : 'tours.badge.gpx');
return (
@@ -122,7 +121,7 @@ function ActivityCard({
<footer className="flex flex-wrap gap-1.5 border-t border-edge-faint px-2.5 py-2">
<CardAction
icon={<RefreshCw size={12} strokeWidth={2.2} />}
onClick={() => state.openAssign({ assignmentId: activity.assignment_id })}
onClick={() => state.openAssign({ assignmentId: activity.assignment_id, activityId: activity.id })}
disabled={state.busy}
>
{t('tours.activity.change')}
@@ -157,6 +156,32 @@ function NoActivity() {
);
}
/** What the section holds: the tracks, the empty place for one, or word that the tour's tracks could not be read. */
function ActivityList({ state, executions }: { state: TourActivities; executions: readonly TourExecution[] }) {
const { t } = useTranslation();
const activities = state.activities ?? [];
if (state.unavailable) {
return (
<TourNotice role="status" icon={<CloudOff size={13} strokeWidth={2} />}>
{t('tours.activity.unavailable')}
</TourNotice>
);
}
if (activities.length === 0) return <NoActivity />;
return (
<div className="flex flex-col gap-2">
{activities.map((activity) => (
<ActivityCard
key={activity.id}
activity={activity}
execution={executionOf(executions, activity.assignment_id)}
state={state}
/>
))}
</div>
);
}
interface TourActivitySectionProps {
tripId: number;
tour: TourListItem;
@@ -184,8 +209,10 @@ export default function TourActivitySection({
const { t } = useTranslation();
const executions = useMemo(() => executionsOf(tour.place_id, days, assignments), [assignments, days, tour.place_id]);
const state = useTourActivities({ tripId, tour, executions, canEdit, onToursChanged });
const { activities } = state;
if (activities === null || tour.activity_of != null || (activities.length === 0 && !canEdit)) return null;
const { activities, unavailable } = state;
if (activities === null || tour.activity_of != null || (activities.length === 0 && !canEdit && !unavailable)) {
return null;
}
return (
<DialogSection
className="flex-none"
@@ -197,7 +224,7 @@ export default function TourActivitySection({
<CardAction
icon={<Plus size={12} strokeWidth={2.2} />}
onClick={() => state.openAssign()}
disabled={state.busy}
disabled={state.busy || unavailable}
>
{t('tours.activity.assign')}
</CardAction>
@@ -206,20 +233,7 @@ export default function TourActivitySection({
)
}
>
{activities.length === 0 ? (
<NoActivity />
) : (
<div className="flex flex-col gap-2">
{activities.map((activity) => (
<ActivityCard
key={activity.id}
activity={activity}
execution={executionOf(executions, activity.assignment_id)}
state={state}
/>
))}
</div>
)}
<ActivityList state={state} executions={executions} />
{state.assigning && (
<TourActivityDialog
tripId={tripId}
@@ -1,9 +1,10 @@
// FE-ACT-MODEL-001 to FE-ACT-MODEL-008
// FE-ACT-MODEL-001 to FE-ACT-MODEL-009
// ACT-01, the pure half of a tour's actual tracks: its executions, the
// recordings that can be linked, the GPX preset, the time and the refusals.
import type { TourActivity, TourListItem } from '@trek/shared';
import { describe, expect, it } from 'vitest';
import type { Assignment, AssignmentsMap, Day } from '../../../types';
import { formatDate } from '../../../utils/formatters';
import {
analysisOfLine,
executionOf,
@@ -11,6 +12,7 @@ import {
importFieldsFor,
inDayOrder,
isRecording,
recordedDay,
recordedMinutes,
refusalOf,
trackCandidates,
@@ -144,4 +146,14 @@ describe('measures', () => {
expect(refusalOf(new Error('offline'))).toBeNull();
expect(refusalOf(null)).toBeNull();
});
it('FE-ACT-MODEL-009: the day recorded is the viewer’s calendar day of the first time, not the UTC one', () => {
// 22:30 UTC on the 1st is the morning of the 2nd in Tokyo and still the afternoon of the 1st in Los Angeles.
expect(recordedDay('2026-07-01T22:30:00Z', 'en', 'Asia/Tokyo')).toBe(formatDate('2026-07-02', 'en'));
expect(recordedDay('2026-07-01T22:30:00Z', 'en', 'America/Los_Angeles')).toBe(formatDate('2026-07-01', 'en'));
// 01:30 UTC on the 2nd is still the evening of the 1st in New York.
expect(recordedDay('2026-07-02T01:30:00Z', 'en', 'America/New_York')).toBe(formatDate('2026-07-01', 'en'));
expect(recordedDay(null, 'en')).toBeNull();
expect(recordedDay('nonsense', 'en')).toBeNull();
});
});
@@ -6,6 +6,7 @@ import {
type TourListItem,
} from '@trek/shared';
import type { AssignmentsMap, Day } from '../../../types';
import { formatDate } from '../../../utils/formatters';
import { analyzeRouteGeometry, type RouteGeometryAnalysis } from '../../../utils/routeGeometry';
/**
@@ -119,6 +120,21 @@ export function recordedMinutes(startedAt?: string | null, endedAt?: string | nu
return Number.isFinite(start) && Number.isFinite(end) && end > start ? Math.round((end - start) / 60_000) : null;
}
/**
* The day a track was recorded on, as the viewer's calendar reads its first
* time stamp: a hike started at 07:00 in Tokyo is that morning, not the UTC
* evening before. `timeZone` is only there for tests; null without a time.
*/
export function recordedDay(startedAt: string | null | undefined, locale: string, timeZone?: string): string | null {
const instant = startedAt ? new Date(startedAt) : null;
if (!instant || Number.isNaN(instant.getTime())) return null;
// en-CA writes the calendar day as YYYY-MM-DD, the form formatDate reads.
const day = new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(
instant
);
return formatDate(day, locale);
}
/** Why the server refused an assignment, when it named a reason this build knows; null for anything else. */
export function refusalOf(error: unknown): TourActivityRefusal | null {
const code = (error as { response?: { data?: { code?: unknown } } } | null)?.response?.data?.code;
@@ -1,4 +1,4 @@
// FE-ACT-HOOK-001 to FE-ACT-HOOK-005
// FE-ACT-HOOK-001 to FE-ACT-HOOK-006
// ACT-01: the actual tracks read with the tour's detail, linked from the
// dialog and unlinked after confirming, each write telling the lists and the
// user, and a refusal named in the user's words without changing anything.
@@ -59,10 +59,24 @@ describe('useTourActivities', () => {
await waitFor(() => expect(repo.detail).toHaveBeenCalledTimes(2));
});
it('FE-ACT-HOOK-002: a detail that cannot be had shows none', async () => {
it('FE-ACT-HOOK-002: a detail that cannot be had shows none while the list names none either', async () => {
repo.detail.mockRejectedValueOnce(new Error('offline'));
const { result } = render();
await waitFor(() => expect(result.current.activities).toEqual([]));
expect(result.current.unavailable).toBe(false);
});
it('FE-ACT-HOOK-006: a detail that cannot be had while the list names tracks says they are unavailable, not that there are none', async () => {
repo.detail.mockRejectedValueOnce(new Error('offline'));
const linked = { ...tour, activity_tracks: [{ id: 3, track_place_id: 22, assignment_id: null }] } as TourListItem;
const { result } = renderHook(() =>
useTourActivities({ tripId: 1, tour: linked, executions, canEdit: true, onToursChanged: vi.fn() })
);
await waitFor(() => expect(result.current.activities).toEqual([]));
expect(result.current.unavailable).toBe(true);
// Nothing can be replaced that could not be read.
act(() => result.current.openAssign());
expect(result.current.assigning).toBeNull();
});
it('FE-ACT-HOOK-003: links the confirmed track, takes the answer in, tells the lists and closes the dialog', async () => {
@@ -15,9 +15,14 @@ interface TourActivitiesOptions {
onToursChanged?: (placeIds: number[]) => Promise<void> | void;
}
/** Which execution the assignment dialog is open for: `undefined` lets it pick the first free one. */
/**
* Which execution the assignment dialog is open for: `undefined` lets it pick
* the first free one. `activityId` is the track a change starts from, as "no
* day" can hold several once the days they were on are gone.
*/
export interface AssignTarget {
assignmentId?: number | null;
activityId?: number;
}
/** The refs a list item names, so the detail is read again when another client changed them. */
@@ -31,14 +36,16 @@ function refsKey(tour: TourListItem): string {
* the two changes the user can make: open the assignment for an execution,
* and take a recording off after confirming it. Both writes are online only,
* as the GPX import a recording comes through is; a refused one says why and
* changes nothing.
* changes nothing. A detail that cannot be read is not taken for an empty one:
* while the list names tracks of the tour, they are said to be unavailable.
*/
export function useTourActivities({ tripId, tour, executions, canEdit, onToursChanged }: TourActivitiesOptions) {
const { t } = useTranslation();
const toast = useToast();
const placeId = tour.place_id;
const refs = refsKey(tour);
const [loaded, setLoaded] = useState<{ placeId: number; activities: TourActivity[] } | null>(null);
// `activities: null` is a detail that could not be read, apart from one without tracks.
const [loaded, setLoaded] = useState<{ placeId: number; activities: TourActivity[] | null } | null>(null);
const [assigning, setAssigning] = useState<AssignTarget | null>(null);
const [removing, setRemoving] = useState<TourActivity | null>(null);
const [busy, setBusy] = useState(false);
@@ -50,17 +57,20 @@ export function useTourActivities({ tripId, tour, executions, canEdit, onToursCh
if (!controller.signal.aborted) setLoaded({ placeId, activities: detail.activities ?? [] });
},
() => {
if (!controller.signal.aborted) setLoaded({ placeId, activities: [] });
if (!controller.signal.aborted) setLoaded({ placeId, activities: null });
}
);
return () => controller.abort();
// `refs` is the list's word that the recordings changed elsewhere.
}, [tripId, placeId, refs]);
const current = loaded?.placeId === placeId ? loaded : null;
const activities = useMemo(
() => (loaded?.placeId === placeId ? inDayOrder(loaded.activities, executions) : null),
[executions, loaded, placeId]
() => (current ? inDayOrder(current.activities ?? [], executions) : null),
[current, executions]
);
// The list knows the tour has tracks, the detail that would show them did not come.
const unavailable = current !== null && current.activities === null && (tour.activity_tracks?.length ?? 0) > 0;
/** One write, its answer taken in, the lists told and the user too; false when it was refused. */
const apply = useCallback(
@@ -109,13 +119,15 @@ export function useTourActivities({ tripId, tour, executions, canEdit, onToursCh
}, [apply, busy, canEdit, placeId, removing, tripId]);
return {
/** Null while the detail loads. */
/** Null while the detail loads; empty, with `unavailable`, when it could not be read. */
activities,
/** The tour has tracks the detail could not be read for, so none can be shown or replaced. */
unavailable,
canEdit,
busy,
assigning,
openAssign: (target: AssignTarget = {}) => {
if (canEdit) setAssigning(target);
if (canEdit && !unavailable) setAssigning(target);
},
closeAssign: () => {
if (!busy) setAssigning(null);
@@ -1,4 +1,4 @@
// FE-ACT-ASSIGN-001 to FE-ACT-ASSIGN-004
// FE-ACT-ASSIGN-001 to FE-ACT-ASSIGN-005
// ACT-01, the link dialog's state: the day it starts on, the recordings of the
// trip to choose from, what a choice replaces, and a recording imported here
// chosen for the user but never linked by itself.
@@ -6,6 +6,7 @@ import { act, renderHook, waitFor } from '@testing-library/react';
import type { TourActivity, TourListItem } from '@trek/shared';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { TourExecution } from './tourActivityModel';
import type { AssignTarget } from './useTourActivities';
import { useTrackAssignment } from './useTrackAssignment';
const repo = vi.hoisted(() => ({ list: vi.fn() }));
@@ -41,7 +42,7 @@ beforeEach(() => {
repo.list.mockResolvedValue({ tours: [tour, recording(20, 'Watch'), recording(21, 'Phone', { activity_of: 99 })] });
});
function render(activities: TourActivity[], target: { assignmentId?: number | null } = {}, onToursChanged = vi.fn()) {
function render(activities: TourActivity[], target: AssignTarget = {}, onToursChanged = vi.fn()) {
return renderHook(() =>
useTrackAssignment({ tripId: 1, tour, executions, activities, target, canEdit: true, onToursChanged })
);
@@ -56,7 +57,7 @@ describe('useTrackAssignment', () => {
expect(asked.result.current.assignmentId).toBe(31);
// A change starts on the track the day has, which therefore replaces nothing.
expect(asked.result.current.selected).toBe(21);
expect(asked.result.current.replaces).toBeNull();
expect(asked.result.current.replaces).toEqual([]);
await waitFor(() => expect(asked.result.current.candidates).not.toBeNull());
});
@@ -79,10 +80,20 @@ describe('useTrackAssignment', () => {
const { result } = render([linked(11, 21, 'Phone')], { assignmentId: 11 });
await waitFor(() => expect(result.current.candidates).not.toBeNull());
act(() => result.current.choose(20));
expect(result.current.replaces).toBe('Phone');
expect(result.current.replaces).toEqual(['Phone']);
act(() => result.current.chooseExecution(null));
expect(result.current.execution.day).toBeNull();
expect(result.current.replaces).toBeNull();
expect(result.current.replaces).toEqual([]);
});
it('FE-ACT-ASSIGN-005: "no day" left with several tracks once their days went: a change starts on the one asked for and names every one it replaces', async () => {
const noDay = [linked(null, 20, 'Watch'), linked(null, 21, 'Phone'), linked(11, 22, 'Bike computer')];
const { result } = render(noDay, { assignmentId: null, activityId: 21 });
await waitFor(() => expect(result.current.candidates).not.toBeNull());
expect(result.current.selected).toBe(21);
expect(result.current.replaces).toEqual(['Watch']);
act(() => result.current.choose(40));
expect(result.current.replaces).toEqual(['Watch', 'Phone']);
});
it('FE-ACT-ASSIGN-004: a recording imported here is chosen and the list read again; the lists are told', async () => {
@@ -9,7 +9,7 @@ interface TrackAssignmentOptions {
tripId: number;
tour: TourListItem;
executions: readonly TourExecution[];
/** The recordings the tour has now, to preset a change and to say what a choice replaces. */
/** The recordings the tour has now, to preset a change and to name what a choice replaces. */
activities: readonly TourActivity[];
target: AssignTarget;
canEdit: boolean;
@@ -46,8 +46,11 @@ export function useTrackAssignment({
const [assignmentId, setAssignmentId] = useState<number | null>(() =>
startingExecution(executions, activities, target)
);
const current = activities.find((activity) => activity.assignment_id === assignmentId) ?? null;
const [selected, setSelected] = useState<number | null>(() => current?.track.place_id ?? null);
const onExecution = activities.filter((activity) => activity.assignment_id === assignmentId);
const [selected, setSelected] = useState<number | null>(() => {
const changed = onExecution.find((activity) => activity.id === target.activityId) ?? onExecution[0];
return changed?.track.place_id ?? null;
});
const [tours, setTours] = useState<TourListItem[] | null>(null);
const [reads, setReads] = useState(0);
@@ -80,8 +83,11 @@ export function useTrackAssignment({
const candidates = useMemo(() => (tours ? trackCandidates(tours, tour.place_id) : null), [tour.place_id, tours]);
const choice = candidates?.find((candidate) => candidate.tour.place_id === selected) ?? null;
// A recording the execution has now, other than the one chosen, gives way to it.
const replaces = current && current.track.place_id !== selected ? current.track.name : null;
// Every recording the execution has now, other than the one chosen, gives way to it: a day has
// one, "no day" can have several once the days they were on are gone, and the server clears them all.
const replaces = onExecution
.filter((activity) => activity.track.place_id !== selected)
.map((activity) => activity.track.name);
return {
executions,
@@ -93,6 +99,7 @@ export function useTrackAssignment({
selected,
choose: setSelected,
choice,
/** The names of the tracks linking replaces; empty when it replaces none. */
replaces,
gpxImport,
importFields: importFieldsFor(tour),