Skip to content

Commit e952eb8

Browse files
committed
front: manchette: display waypoints added with map click
1 parent 646486a commit e952eb8

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

front/public/locales/en/simulation.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"used": "used"
3535
},
3636
"projectionInProgress": "Projection in progress: {{ count }}/{{ total }} trains",
37+
"requestedPoint": "requested point {{ count }}",
3738
"reset": "Reset the chart",
3839
"resetTimer": "Reset timer",
3940
"rotate": "Rotate the chart",

front/public/locales/fr/simulation.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"used": "utilisée"
3535
},
3636
"projectionInProgress": "Projection en cours: {{ count }}/{{ total }} trains",
37+
"requestedPoint": "point demandé {{ count }}",
3738
"reset": "Réinitialiser le graphique",
3839
"resetTimer": "Réinitialiser le compteur",
3940
"rotate": "Pivoter le graphique",

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

+55-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { useEffect, useState } from 'react';
22

3+
import { useTranslation } from 'react-i18next';
4+
35
import { STDCM_TRAIN_ID } from 'applications/stdcm/consts';
46
import {
57
osrdEditoastApi,
68
type PathProperties,
79
type PostV2InfraByInfraIdPathPropertiesApiArg,
810
} from 'common/api/osrdEditoastApi';
11+
import { addElementAtIndex } from 'utils/array';
912

1013
const useGetProjectedTrainOperationalPoints = (
1114
trainIdUsedForProjection?: number,
1215
infraId?: number
1316
) => {
17+
const { t } = useTranslation('simulation');
1418
const [operationalPoints, setOperationalPoints] = useState<
1519
NonNullable<PathProperties['operational_points']>
1620
>([]);
1721

22+
const { data: trainScheduleUsedForProjection } =
23+
osrdEditoastApi.endpoints.getV2TrainScheduleById.useQuery(
24+
{
25+
id: trainIdUsedForProjection as number,
26+
},
27+
{
28+
skip: !trainIdUsedForProjection,
29+
}
30+
);
31+
1832
const { data: pathfindingResult } = osrdEditoastApi.endpoints.getV2TrainScheduleByIdPath.useQuery(
1933
{
2034
id: trainIdUsedForProjection as number,
@@ -30,7 +44,12 @@ const useGetProjectedTrainOperationalPoints = (
3044

3145
useEffect(() => {
3246
const getOperationalPoints = async () => {
33-
if (infraId && pathfindingResult && pathfindingResult.status === 'success') {
47+
if (
48+
infraId &&
49+
trainScheduleUsedForProjection &&
50+
pathfindingResult &&
51+
pathfindingResult.status === 'success'
52+
) {
3453
const pathPropertiesParams: PostV2InfraByInfraIdPathPropertiesApiArg = {
3554
infraId,
3655
props: ['operational_points'],
@@ -40,13 +59,44 @@ const useGetProjectedTrainOperationalPoints = (
4059
};
4160
const { operational_points } = await postPathProperties(pathPropertiesParams).unwrap();
4261

43-
setOperationalPoints(
44-
operational_points as NonNullable<PathProperties['operational_points']>
45-
);
62+
let operationalPointsWithAllWaypoints = operational_points as NonNullable<
63+
PathProperties['operational_points']
64+
>;
65+
// Check if there are vias added by map click and insert them in the operational points
66+
if (trainScheduleUsedForProjection.path.some((step) => 'track' in step)) {
67+
trainScheduleUsedForProjection.path.forEach((step, i) => {
68+
if ('track' in step) {
69+
const positionOnPath = pathfindingResult.path_item_positions[i];
70+
const indexToInsert = operationalPointsWithAllWaypoints.findIndex(
71+
(op) => op.position >= positionOnPath
72+
);
73+
74+
const formattedStep: NonNullable<PathProperties['operational_points']>[number] = {
75+
id: step.id,
76+
extensions: {
77+
identifier: {
78+
name: t('requestedPoint', { count: indexToInsert }),
79+
uic: 0,
80+
},
81+
},
82+
part: { track: step.track, position: step.offset },
83+
position: positionOnPath,
84+
};
85+
86+
operationalPointsWithAllWaypoints = addElementAtIndex(
87+
operationalPointsWithAllWaypoints,
88+
indexToInsert,
89+
formattedStep
90+
);
91+
}
92+
});
93+
}
94+
95+
setOperationalPoints(operationalPointsWithAllWaypoints);
4696
}
4797
};
4898
getOperationalPoints();
49-
}, [pathfindingResult, infraId]);
99+
}, [pathfindingResult, infraId, t]);
50100

51101
return operationalPoints;
52102
};

0 commit comments

Comments
 (0)