Skip to content

Commit bee6d0e

Browse files
committed
front: fix track_name on timetable for imported train
Signed-off-by: aschantraine <[email protected]>
1 parent f35ef05 commit bee6d0e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

front/src/modules/timesStops/helpers/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
PathItemLocation,
1414
ReceptionSignal,
1515
TrackReference,
16+
TrackSection,
1617
} from 'common/api/osrdEditoastApi';
1718
import type { TimeString } from 'common/types';
1819
import { matchPathStepAndOp } from 'modules/pathfinding/utils';
@@ -351,9 +352,15 @@ export function receptionSignalToSignalBooleans(receptionSignal?: ReceptionSigna
351352
return { shortSlipDistance: false, onStopSignal: false };
352353
}
353354

354-
export const getTrackReferenceLabel = (trackReference?: TrackReference | null) => {
355+
export const getTrackReferenceLabel = (
356+
trackSections: Record<string, TrackSection>,
357+
trackReference?: TrackReference | null
358+
) => {
355359
if (!trackReference) return undefined;
356-
return 'track_id' in trackReference ? trackReference.track_id : trackReference.track_name;
360+
if ('track_name' in trackReference) return trackReference.track_name;
361+
return (
362+
trackSections[trackReference.track_id]?.extensions?.sncf?.track_name ?? trackReference.track_id
363+
);
357364
};
358365

359366
export const getOperationalPointName = (

front/src/modules/timesStops/hooks/useOutputTableData.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ const useOutputTableData = (
3939

4040
const trackIds = useMemo(() => {
4141
const path = selectedTrain?.path || [];
42-
const trackIdsInPathSteps = path.flatMap((step) => ('track' in step ? [step.track] : []));
42+
const trackIdsInPathSteps = path.flatMap((step) => [
43+
...('track' in step ? [step.track] : []),
44+
...('track_reference' in step && step.track_reference && 'track_id' in step.track_reference
45+
? [step.track_reference.track_id]
46+
: []),
47+
]);
4348
const trackIdsOnPath = (operationalPointsOnPath || []).map((op) => op.part.track);
4449
return [...trackIdsInPathSteps, ...trackIdsOnPath];
4550
}, [selectedTrain?.path, operationalPointsOnPath]);
@@ -80,7 +85,7 @@ const useOutputTableData = (
8085
const trackName =
8186
'track' in pathStep
8287
? trackSections[pathStep.track]?.extensions?.sncf?.track_name
83-
: getTrackReferenceLabel(pathStep.track_reference);
88+
: getTrackReferenceLabel(trackSections, pathStep.track_reference);
8489

8590
const schedule = scheduleByAt[pathStep.id];
8691
const computedArrival = simulatedPathItemTimes

0 commit comments

Comments
 (0)