@@ -22,7 +22,7 @@ const useGetProjectedTrainOperationalPoints = (
22
22
const { data : trainScheduleUsedForProjection } =
23
23
osrdEditoastApi . endpoints . getTrainScheduleById . useQuery (
24
24
{
25
- id : trainIdUsedForProjection as number ,
25
+ id : trainIdUsedForProjection ! ,
26
26
} ,
27
27
{
28
28
skip : ! trainIdUsedForProjection ,
@@ -31,8 +31,8 @@ const useGetProjectedTrainOperationalPoints = (
31
31
32
32
const { data : pathfindingResult } = osrdEditoastApi . endpoints . getTrainScheduleByIdPath . useQuery (
33
33
{
34
- id : trainIdUsedForProjection as number ,
35
- infraId : infraId as number ,
34
+ id : trainIdUsedForProjection ! ,
35
+ infraId : infraId ! ,
36
36
} ,
37
37
{
38
38
skip : ! trainIdUsedForProjection || ! infraId || trainIdUsedForProjection === STDCM_TRAIN_ID ,
@@ -63,34 +63,35 @@ const useGetProjectedTrainOperationalPoints = (
63
63
PathProperties [ 'operational_points' ]
64
64
> ;
65
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
- ) ;
66
+ let waypointCounter = 1 ;
67
+ trainScheduleUsedForProjection . path . forEach ( ( step , i ) => {
68
+ if ( ! ( 'track' in step ) ) return ;
73
69
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
- } ;
70
+ const positionOnPath = pathfindingResult . path_item_positions [ i ] ;
71
+ const indexToInsert = operationalPointsWithAllWaypoints . findIndex (
72
+ ( op ) => op . position >= positionOnPath
73
+ ) ;
85
74
86
- operationalPointsWithAllWaypoints = addElementAtIndex (
87
- operationalPointsWithAllWaypoints ,
88
- indexToInsert ,
89
- formattedStep
90
- ) ;
91
- }
92
- } ) ;
93
- }
75
+ const formattedStep : NonNullable < PathProperties [ 'operational_points' ] > [ number ] = {
76
+ id : step . id ,
77
+ extensions : {
78
+ identifier : {
79
+ name : t ( 'requestedPoint' , { count : waypointCounter } ) ,
80
+ uic : 0 ,
81
+ } ,
82
+ } ,
83
+ part : { track : step . track , position : step . offset } ,
84
+ position : positionOnPath ,
85
+ } ;
86
+
87
+ operationalPointsWithAllWaypoints = addElementAtIndex (
88
+ operationalPointsWithAllWaypoints ,
89
+ indexToInsert ,
90
+ formattedStep
91
+ ) ;
92
+
93
+ waypointCounter += 1 ;
94
+ } ) ;
94
95
95
96
setOperationalPoints ( operationalPointsWithAllWaypoints ) ;
96
97
}
0 commit comments