Skip to content

Commit 71808d1

Browse files
committed
fixup! fixup! front: manchette: display waypoints added with map click
1 parent 48f12d2 commit 71808d1

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

front/src/applications/operationalStudies/hooks/useScenarioData.ts

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ const useScenarioData = () => {
9292
[projectedTrainsById]
9393
);
9494

95+
const trainScheduleUsedForProjection = useMemo(
96+
() => trainSchedules?.find((trainSchedule) => trainSchedule.id === trainIdUsedForProjection),
97+
[trainIdUsedForProjection, trainSchedules]
98+
);
99+
95100
useEffect(() => {
96101
if (!rawTrainSchedules) {
97102
setTrainSchedules(undefined);
@@ -193,6 +198,7 @@ const useScenarioData = () => {
193198
infra: { infra, isInfraLoaded, reloadCount },
194199
trainScheduleSummaries,
195200
trainSchedules,
201+
trainScheduleUsedForProjection,
196202
trainIdUsedForProjection,
197203
projectedTrains,
198204
simulationResults,

front/src/applications/operationalStudies/views/v2/ScenarioV2.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const Scenario = () => {
9797
infra: { infra, isInfraLoaded, reloadCount },
9898
trainScheduleSummaries,
9999
trainSchedules,
100+
trainScheduleUsedForProjection,
100101
trainIdUsedForProjection,
101102
projectedTrains,
102103
simulationResults,
@@ -308,6 +309,7 @@ const Scenario = () => {
308309
collapsedTimetable={collapsedTimetable}
309310
spaceTimeData={projectedTrains}
310311
simulationResults={simulationResults}
312+
trainScheduleUsedForProjection={trainScheduleUsedForProjection}
311313
trainIdUsedForProjection={trainIdUsedForProjection}
312314
infraId={infraId}
313315
timetableTrainNb={timetable.train_ids.length}

front/src/applications/operationalStudies/views/v2/SimulationResultsV2.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useSelector } from 'react-redux';
88
import { Rnd } from 'react-rnd';
99

1010
import type { SimulationResults, TrainSpaceTimeData } from 'applications/operationalStudies/types';
11+
import type { TrainScheduleResult } from 'common/api/osrdEditoastApi';
1112
import SimulationWarpedMap from 'common/Map/WarpedMap/SimulationWarpedMap';
1213
import { getScaleDomainFromValuesV2 } from 'modules/simulationResult/components/ChartHelpers/getScaleDomainFromValues';
1314
import SimulationResultsMapV2 from 'modules/simulationResult/components/SimulationResultsMapV2';
@@ -33,6 +34,7 @@ type SimulationResultsV2Props = {
3334
collapsedTimetable: boolean;
3435
spaceTimeData?: TrainSpaceTimeData[];
3536
infraId?: number;
37+
trainScheduleUsedForProjection?: TrainScheduleResult;
3638
trainIdUsedForProjection?: number;
3739
simulationResults: SimulationResults;
3840
timetableTrainNb: number;
@@ -42,6 +44,7 @@ const SimulationResultsV2 = ({
4244
collapsedTimetable,
4345
spaceTimeData,
4446
infraId,
47+
trainScheduleUsedForProjection,
4548
trainIdUsedForProjection,
4649
simulationResults: {
4750
selectedTrainSchedule,
@@ -88,6 +91,7 @@ const SimulationResultsV2 = ({
8891
);
8992

9093
const projectedOperationalPoints = useGetProjectedTrainOperationalPoints(
94+
trainScheduleUsedForProjection,
9195
trainIdUsedForProjection,
9296
infraId
9397
);

front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts

+11-13
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import {
77
osrdEditoastApi,
88
type PathProperties,
99
type PostInfraByInfraIdPathPropertiesApiArg,
10+
type TrainScheduleResult,
1011
} from 'common/api/osrdEditoastApi';
1112
import { addElementAtIndex } from 'utils/array';
1213

1314
const useGetProjectedTrainOperationalPoints = (
15+
trainScheduleUsedForProjection?: TrainScheduleResult,
1416
trainIdUsedForProjection?: number,
1517
infraId?: number
1618
) => {
@@ -19,16 +21,6 @@ const useGetProjectedTrainOperationalPoints = (
1921
NonNullable<PathProperties['operational_points']>
2022
>([]);
2123

22-
const { data: trainScheduleUsedForProjection } =
23-
osrdEditoastApi.endpoints.getTrainScheduleById.useQuery(
24-
{
25-
id: trainIdUsedForProjection!,
26-
},
27-
{
28-
skip: !trainIdUsedForProjection,
29-
}
30-
);
31-
3224
const { data: pathfindingResult } = osrdEditoastApi.endpoints.getTrainScheduleByIdPath.useQuery(
3325
{
3426
id: trainIdUsedForProjection!,
@@ -59,11 +51,11 @@ const useGetProjectedTrainOperationalPoints = (
5951
};
6052
const { operational_points } = await postPathProperties(pathPropertiesParams).unwrap();
6153

62-
let operationalPointsWithAllWaypoints = operational_points as NonNullable<
63-
PathProperties['operational_points']
64-
>;
54+
let operationalPointsWithAllWaypoints = operational_points!;
55+
6556
// Check if there are vias added by map click and insert them in the operational points
6657
let waypointCounter = 1;
58+
6759
trainScheduleUsedForProjection.path.forEach((step, i) => {
6860
if (!('track' in step)) return;
6961

@@ -84,6 +76,12 @@ const useGetProjectedTrainOperationalPoints = (
8476
position: positionOnPath,
8577
};
8678

79+
// If we can't find any op position greater than the current step position, we add it at the end
80+
if (indexToInsert === -1) {
81+
operationalPointsWithAllWaypoints.push(formattedStep);
82+
return;
83+
}
84+
8785
operationalPointsWithAllWaypoints = addElementAtIndex(
8886
operationalPointsWithAllWaypoints,
8987
indexToInsert,

0 commit comments

Comments
 (0)