@@ -22,7 +22,11 @@ import { getSelectedTrainId } from 'reducers/simulationResults/selectors';
22
22
import { getShowPacedTrains } from 'reducers/user/userSelectors' ;
23
23
import { useAppDispatch } from 'store' ;
24
24
import { castErrorToFailure } from 'utils/error' ;
25
- import { formatTrainScheduleIdToEditoastTrainId , isTrainSchedule } from 'utils/trainId' ;
25
+ import {
26
+ formatPacedTrainIdToEditoastTrainId ,
27
+ formatTrainScheduleIdToEditoastTrainId ,
28
+ isTrainSchedule ,
29
+ } from 'utils/trainId' ;
26
30
27
31
import FilterPanel from './FilterPanel' ;
28
32
import type { TimetableFilters , TimetableItemWithDetails } from './types' ;
@@ -101,6 +105,7 @@ const TimetableToolbar = ({
101
105
) ;
102
106
103
107
const [ deleteTrainSchedules ] = osrdEditoastApi . endpoints . deleteTrainSchedule . useMutation ( ) ;
108
+ const [ deletePacedTrains ] = osrdEditoastApi . endpoints . deletePacedTrain . useMutation ( ) ;
104
109
105
110
const toggleFilterPanel = ( ) => {
106
111
setIsFilterPanelOpen ( ! isFilterPanelOpen ) ;
@@ -118,31 +123,37 @@ const TimetableToolbar = ({
118
123
const handleTrainsDelete = async ( ) => {
119
124
const itemsCount = selectedTimetableItemIds . length ;
120
125
121
- // TODO Paced train : Adapt this to handle delete paced trains in issue https://github.com/OpenRailAssociation/osrd/issues/10615
126
+ // TODO Paced train : Adapt this to handle paced trains selection in issue https://github.com/OpenRailAssociation/osrd/issues/11054
122
127
if ( selectedTrainId && selectedTimetableItemIds . includes ( selectedTrainId as TrainScheduleId ) ) {
123
128
// we need to set selectedTrainId to undefined, otherwise just after the delete,
124
129
// some unvalid rtk calls are dispatched (see rollingstock request in SimulationResults)
125
130
dispatch ( updateSelectedTrainId ( undefined ) ) ;
126
131
}
127
132
128
- // TODO Paced train : Adapt this to handle delete paced trains in issue https://github.com/OpenRailAssociation/osrd/issues/10615
129
133
const editoastSelectedTrainScheduleIds = selectedTrainScheduleIds . map ( ( id ) =>
130
134
formatTrainScheduleIdToEditoastTrainId ( id )
131
135
) ;
136
+ const editoastSelectedPacedTrainIds = selectedPacedTrainIds . map ( ( id ) =>
137
+ formatPacedTrainIdToEditoastTrainId ( id )
138
+ ) ;
132
139
133
- await deleteTrainSchedules ( { body : { ids : editoastSelectedTrainScheduleIds } } )
134
- . unwrap ( )
135
- . then ( ( ) => {
136
- removeTrains ( selectedTrainScheduleIds ) ;
140
+ if ( showPacedTrains ) {
141
+ try {
142
+ if ( editoastSelectedPacedTrainIds . length > 0 ) {
143
+ await deleteTrainSchedules ( { body : { ids : editoastSelectedTrainScheduleIds } } ) . unwrap ( ) ;
144
+ }
145
+ if ( editoastSelectedPacedTrainIds . length > 0 ) {
146
+ await deletePacedTrains ( { body : { ids : editoastSelectedPacedTrainIds } } ) . unwrap ( ) ;
147
+ }
148
+ removeTrains ( selectedTimetableItemIds ) ;
137
149
dispatch (
138
150
setSuccess ( {
139
- title : t ( 'timetable.trainsSelectionDeletedCount ' , { count : itemsCount } ) ,
151
+ title : t ( 'timetable.itemsSelectionDeletedCount ' , { count : itemsCount } ) ,
140
152
text : '' ,
141
153
} )
142
154
) ;
143
- } )
144
- . catch ( ( e ) => {
145
- // TODO Paced train : Adapt this to handle delete paced trains in issue https://github.com/OpenRailAssociation/osrd/issues/10615
155
+ } catch ( e ) {
156
+ // TODO Paced train : Adapt this to handle paced trains selection in issue https://github.com/OpenRailAssociation/osrd/issues/11054
146
157
if (
147
158
selectedTrainId &&
148
159
selectedTimetableItemIds . includes ( selectedTrainId as TrainScheduleId )
@@ -151,7 +162,30 @@ const TimetableToolbar = ({
151
162
} else {
152
163
dispatch ( setFailure ( castErrorToFailure ( e ) ) ) ;
153
164
}
154
- } ) ;
165
+ }
166
+ // TODO Paced trains : remove the else in https://github.com/OpenRailAssociation/osrd/issues/10791
167
+ } else {
168
+ await deleteTrainSchedules ( { body : { ids : editoastSelectedTrainScheduleIds } } )
169
+ . unwrap ( )
170
+ . then ( ( ) => {
171
+ dispatch (
172
+ setSuccess ( {
173
+ title : t ( 'timetable.trainsSelectionDeletedCount' , { count : itemsCount } ) ,
174
+ text : '' ,
175
+ } )
176
+ ) ;
177
+ } )
178
+ . catch ( ( e ) => {
179
+ if (
180
+ selectedTrainId &&
181
+ selectedTimetableItemIds . includes ( selectedTrainId as TrainScheduleId )
182
+ ) {
183
+ dispatch ( updateSelectedTrainId ( selectedTrainId ) ) ;
184
+ } else {
185
+ dispatch ( setFailure ( castErrorToFailure ( e ) ) ) ;
186
+ }
187
+ } ) ;
188
+ }
155
189
} ;
156
190
157
191
// TODO Paced train : Adapt this to handle export paced trains in issue https://github.com/OpenRailAssociation/osrd/issues/10614
0 commit comments