From 519147cca886abbcb25aec207d60ad444eea9df1 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 5 Dec 2024 15:19:01 +0100 Subject: [PATCH] front: stop putting path step IDs in SuggestedOP.opId The opId field was (ab)used for track offset waypoints: we were putting path step IDs in there. Instead, make opId optional and add a new field for the path step ID. This paves the way for simplifying SuggestedOP/PathStep matching: we'll be able to use pathStepId instead of trying to match with a random subset of uic/trigram/secondary_code/kp/positionOnPath and friends. Signed-off-by: Simon Ser --- .../stdcm/utils/formatSimulationReportSheet.ts | 2 +- front/src/modules/pathfinding/utils.ts | 11 +++++------ front/src/modules/timesStops/helpers/utils.ts | 6 ++---- .../modules/timesStops/hooks/useOutputTableData.ts | 2 +- front/src/modules/timesStops/types.ts | 3 ++- .../components/ManageTrainSchedule/types.ts | 3 ++- .../osrdconf/osrdConfCommon/__tests__/utils.ts | 2 +- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts b/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts index 033cc95d050..8b2585fd0b2 100644 --- a/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts +++ b/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts @@ -136,7 +136,7 @@ export function getOperationalPointsWithTimes( const stopEndTime = computeStopDepartureTime(formattedTime, durationToString); return { - opId: op.opId, + opId: op.opId!, positionOnPath: op.positionOnPath, time: formattedTime, name: op.name, diff --git a/front/src/modules/pathfinding/utils.ts b/front/src/modules/pathfinding/utils.ts index db91fbed8e9..e9478b5bbfa 100644 --- a/front/src/modules/pathfinding/utils.ts +++ b/front/src/modules/pathfinding/utils.ts @@ -94,7 +94,7 @@ export const upsertPathStepsInOPs = (ops: SuggestedOP[], pathSteps: PathStep[]): // We check only for pathSteps added by map click if ('track' in step) { const formattedStep: SuggestedOP = { - opId: step.id, + pathStepId: step.id, positionOnPath: step.positionOnPath!, offsetOnTrack: step.offset, track: step.track, @@ -124,6 +124,7 @@ export const upsertPathStepsInOPs = (ops: SuggestedOP[], pathSteps: PathStep[]): if (matchPathStepAndOp(step, op) && op.kp === step.kp) { return { ...op, + pathStepId: step.id, stopFor, arrival, receptionSignal, @@ -141,14 +142,12 @@ export const pathStepMatchesOp = ( pathStep: PathStep, op: Pick< SuggestedOP, - 'opId' | 'uic' | 'ch' | 'trigram' | 'track' | 'offsetOnTrack' | 'name' | 'kp' + 'pathStepId' | 'opId' | 'uic' | 'ch' | 'trigram' | 'track' | 'offsetOnTrack' | 'name' | 'kp' >, withKP = false ) => { if (!matchPathStepAndOp(pathStep, op)) { - // TODO: we abuse the PathStep.id field here, the backend also sets it to an - // ID which has nothing to do with OPs - return pathStep.id === op.opId; + return pathStep.id === op.pathStepId; } if ('uic' in pathStep) { return withKP ? pathStep.kp === op.kp : pathStep.name === op.name; @@ -168,7 +167,7 @@ export const isVia = ( vias: PathStep[], op: Pick< SuggestedOP, - 'opId' | 'uic' | 'ch' | 'trigram' | 'track' | 'offsetOnTrack' | 'name' | 'kp' + 'pathStepId' | 'opId' | 'uic' | 'ch' | 'trigram' | 'track' | 'offsetOnTrack' | 'name' | 'kp' >, { withKP = false } = {} ) => vias.some((via) => pathStepMatchesOp(via, op, withKP)); diff --git a/front/src/modules/timesStops/helpers/utils.ts b/front/src/modules/timesStops/helpers/utils.ts index dc9c65faf7d..90b664a66bd 100644 --- a/front/src/modules/timesStops/helpers/utils.ts +++ b/front/src/modules/timesStops/helpers/utils.ts @@ -26,9 +26,7 @@ import { TableType, type TimeExtraDays, type TimesStopsInputRow } from '../types const matchPathStepAndOpWithKP = (step: PathStep, op: SuggestedOP) => { if (!matchPathStepAndOp(step, op)) { - // TODO: we abuse the PathStep.id field here, the backend also sets it to an - // ID which has nothing to do with OPs - return step.id === op.opId; + return step.id === op.pathStepId; } // We match the kp in case two OPs have the same uic+ch (can happen when the // infra is imported) @@ -101,7 +99,7 @@ export const formatSuggestedViasToRowVias = ( arrival: formattedArrival, departure: formattedDeparture, onStopSignal, - name: name || t('waypoint', { id: filteredOp.opId }), + name: name || t('waypoint', { id: filteredOp.pathStepId }), shortSlipDistance, stopFor, theoreticalMargin, diff --git a/front/src/modules/timesStops/hooks/useOutputTableData.ts b/front/src/modules/timesStops/hooks/useOutputTableData.ts index 4f3a710e85e..b3a43513c9d 100644 --- a/front/src/modules/timesStops/hooks/useOutputTableData.ts +++ b/front/src/modules/timesStops/hooks/useOutputTableData.ts @@ -84,7 +84,7 @@ const useOutputTableData = ( : false; return { - opId: pathStep.id, + pathStepId: pathStep.id, name: t('waypoint', { id: pathStep.id }), ch: undefined, isWaypoint: true, diff --git a/front/src/modules/timesStops/types.ts b/front/src/modules/timesStops/types.ts index fc2d1720c4c..5f2cab20624 100644 --- a/front/src/modules/timesStops/types.ts +++ b/front/src/modules/timesStops/types.ts @@ -10,7 +10,8 @@ export type TimeExtraDays = { }; export type TimesStopsRow = { - opId: string; + pathStepId?: string; + opId?: string; name?: string; ch?: string; trackName?: string; diff --git a/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts b/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts index 99dc031339d..6d590006fd2 100644 --- a/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts +++ b/front/src/modules/trainschedule/components/ManageTrainSchedule/types.ts @@ -4,7 +4,8 @@ import type { ReceptionSignal, TrainScheduleBase } from 'common/api/osrdEditoast import type { IsoDurationString } from 'common/types'; export type SuggestedOP = { - opId: string; + pathStepId?: string; + opId?: string; name?: string; uic?: number; ch?: string; diff --git a/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts b/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts index 48d974ddec0..3a883cbe0a3 100644 --- a/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts +++ b/front/src/reducers/osrdconf/osrdConfCommon/__tests__/utils.ts @@ -417,7 +417,7 @@ const testCommonConfReducers = (slice: OperationalStudiesConfSlice | StdcmConfSl }); const newVia: SuggestedOP = { - opId: 'lemans', + pathStepId: 'lemans', track: '60ca8dda-6667-11e3-81ff-01f464e0362d', offsetOnTrack: 426.443, positionOnPath: 200,