diff --git a/front/src/applications/operationalStudies/__tests__/upsertMapWaypointsInOperationalPoints.spec.ts b/front/src/applications/operationalStudies/__tests__/upsertMapWaypointsInOperationalPoints.spec.ts index 9a72ba29fc3..ed14abf427f 100644 --- a/front/src/applications/operationalStudies/__tests__/upsertMapWaypointsInOperationalPoints.spec.ts +++ b/front/src/applications/operationalStudies/__tests__/upsertMapWaypointsInOperationalPoints.spec.ts @@ -53,7 +53,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => { position: 7746000, }, position: 9246000, - weight: null, + weight: 100, }, { id: 'Mid_West_station', @@ -112,7 +112,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => { position: 6481000, }, position: 0, - weight: null, + weight: 100, }, { id: 'Mid_West_station', @@ -142,7 +142,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => { position: 679000, }, position: 4198000, - weight: null, + weight: 100, }, { id: '3', @@ -157,7 +157,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => { position: 883000, }, position: 4402000, - weight: null, + weight: 100, }, ]); }); @@ -186,7 +186,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => { position: 6481000, }, position: 0, - weight: null, + weight: 100, }, { id: '2', @@ -201,7 +201,7 @@ describe('upsertMapWaypointsInOperationalPoints', () => { position: 4733000, }, position: 1748000, - weight: null, + weight: 100, }, ]); }); diff --git a/front/src/applications/operationalStudies/helpers/upsertMapWaypointsInOperationalPoints.ts b/front/src/applications/operationalStudies/helpers/upsertMapWaypointsInOperationalPoints.ts index c276fe07bf9..44ec00ed667 100644 --- a/front/src/applications/operationalStudies/helpers/upsertMapWaypointsInOperationalPoints.ts +++ b/front/src/applications/operationalStudies/helpers/upsertMapWaypointsInOperationalPoints.ts @@ -5,6 +5,8 @@ import type { PathfindingResultSuccess, TrainScheduleResult } from 'common/api/o import type { OperationalPoint } from '../types'; +const HIGHEST_PRIORITY_WEIGHT = 100; + /** * Check if the train path used waypoints added by map click and add them to the operational points */ @@ -18,35 +20,56 @@ export const upsertMapWaypointsInOperationalPoints = ( return path.reduce( (operationalPointsWithAllWaypoints, step, i) => { - if (!('track' in step)) return operationalPointsWithAllWaypoints; - - const positionOnPath = pathItemsPositions[i]; - const indexToInsert = operationalPointsWithAllWaypoints.findIndex( - (op) => op.position >= positionOnPath - ); - - const formattedStep: OperationalPoint = { - id: step.id, - extensions: { - identifier: { - name: t('requestedPoint', { count: waypointCounter }), - uic: 0, - }, - }, - part: { track: step.track, position: step.offset }, - position: positionOnPath, - weight: null, - }; - - waypointCounter += 1; - - // If we can't find any op position greater than the current step position, we add it at the end - if (indexToInsert === -1) { - operationalPointsWithAllWaypoints.push(formattedStep); - } else { - operationalPointsWithAllWaypoints.splice(indexToInsert, 0, formattedStep); + if ('uic' in step) { + const matchedIndex = operationalPointsWithAllWaypoints.findIndex( + (op) => + 'uic' in step && + 'secondary_code' in step && + step.uic === op.extensions?.identifier?.uic && + step.secondary_code === op.extensions?.sncf?.ch + ); + + if (matchedIndex !== -1) { + // Replace the operational point at its original index with updated weight + operationalPointsWithAllWaypoints[matchedIndex] = { + ...operationalPointsWithAllWaypoints[matchedIndex], + weight: HIGHEST_PRIORITY_WEIGHT, + }; + } + + return operationalPointsWithAllWaypoints; } + if ('track' in step) { + const positionOnPath = pathItemsPositions[i]; + const indexToInsert = operationalPointsWithAllWaypoints.findIndex( + (op) => op.position >= positionOnPath + ); + + const formattedStep: OperationalPoint = { + id: step.id, + extensions: { + identifier: { + name: t('requestedPoint', { count: waypointCounter }), + uic: 0, + }, + }, + part: { track: step.track, position: step.offset }, + position: positionOnPath, + weight: HIGHEST_PRIORITY_WEIGHT, + }; + + waypointCounter += 1; + + // If we can't find any op position greater than the current step position, we add it at the end + if (indexToInsert === -1) { + operationalPointsWithAllWaypoints.push(formattedStep); + } else { + operationalPointsWithAllWaypoints.splice(indexToInsert, 0, formattedStep); + } + + return operationalPointsWithAllWaypoints; + } return operationalPointsWithAllWaypoints; }, [...operationalPoints] diff --git a/front/src/modules/simulationResult/components/ManchetteWithSpaceTimeChart/ManchetteWithSpaceTimeChart.tsx b/front/src/modules/simulationResult/components/ManchetteWithSpaceTimeChart/ManchetteWithSpaceTimeChart.tsx index e8fb53ff5b8..d94abc46862 100644 --- a/front/src/modules/simulationResult/components/ManchetteWithSpaceTimeChart/ManchetteWithSpaceTimeChart.tsx +++ b/front/src/modules/simulationResult/components/ManchetteWithSpaceTimeChart/ManchetteWithSpaceTimeChart.tsx @@ -190,6 +190,7 @@ const ManchetteWithSpaceTimeChartWrapper = ({ position: waypoint.position, name: waypoint.extensions?.identifier?.name, secondaryCode: waypoint.extensions?.sncf?.ch, + weight: waypoint.weight ?? 0, })); }, [waypointsPanelData, operationalPoints]); diff --git a/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts b/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts index 66f5f7121de..6bdbb26cf59 100644 --- a/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts +++ b/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts @@ -78,11 +78,12 @@ const useGetProjectedTrainOperationalPoints = ( >; } else { // If the manchette hasn't been saved, we want to display by default only - // the waypoints with CH BV/00/'' and the ones added by map click + // the waypoints with CH BV/00/'' and the path steps (origin, destination, vias) operationalPointsWithUniqueIds = operationalPointsWithUniqueIds.filter((op) => - op.extensions?.sncf ? isStation(op.extensions.sncf.ch) : true + op.extensions?.sncf ? isStation(op.extensions.sncf.ch) || op.weight === 100 : true ); } + setFilteredOperationalPoints(operationalPointsWithUniqueIds); } };