@@ -5,11 +5,17 @@ import cx from 'classnames';
5
5
import { useTranslation } from 'react-i18next' ;
6
6
import { useSelector } from 'react-redux' ;
7
7
8
+ import useStdcmForm from 'applications/stdcm/hooks/useStdcmForm' ;
8
9
import { extractMarkersInfo } from 'applications/stdcm/utils' ;
9
10
import DefaultBaseMap from 'common/Map/DefaultBaseMap' ;
10
11
import { useOsrdConfSelectors } from 'common/osrdContext' ;
11
12
import useInfraStatus from 'modules/pathfinding/hooks/useInfraStatus' ;
12
- import { resetMargins , restoreStdcmConfig , updateStdcmPathStep } from 'reducers/osrdconf/stdcmConf' ;
13
+ import {
14
+ resetMargins ,
15
+ restoreStdcmConfig ,
16
+ updateStdcmPathStep ,
17
+ addStdcmSimulation ,
18
+ } from 'reducers/osrdconf/stdcmConf' ;
13
19
import {
14
20
getStdcmDestination ,
15
21
getStdcmOrigin ,
@@ -44,19 +50,23 @@ declare global {
44
50
type StdcmConfigProps = {
45
51
isDebugMode : boolean ;
46
52
isPending : boolean ;
47
- launchStdcmRequest : ( ) => Promise < void > ;
48
53
retainedSimulationIndex ?: number ;
49
54
showBtnToLaunchSimulation : boolean ;
55
+ skipPathfindingStatusMessage : boolean ;
56
+ launchStdcmRequest : ( ) => Promise < void > ;
50
57
cancelStdcmRequest : ( ) => void ;
58
+ setSkipPathfindingStatusMessage : ( value : boolean ) => void ;
51
59
} ;
52
60
53
61
const StdcmConfig = ( {
54
62
isDebugMode,
55
63
isPending,
56
- launchStdcmRequest,
57
64
retainedSimulationIndex,
58
65
showBtnToLaunchSimulation,
66
+ skipPathfindingStatusMessage,
67
+ setSkipPathfindingStatusMessage,
59
68
cancelStdcmRequest,
69
+ launchStdcmRequest,
60
70
} : StdcmConfigProps ) => {
61
71
const { t } = useTranslation ( 'stdcm' ) ;
62
72
const launchButtonRef = useRef < HTMLDivElement > ( null ) ;
@@ -81,13 +91,16 @@ const StdcmConfig = ({
81
91
82
92
const [ formErrors , setFormErrors ] = useState < StdcmConfigErrors > ( ) ;
83
93
94
+ const currentSimulationInputs = useStdcmForm ( ) ;
95
+
84
96
const disabled = isPending || retainedSimulationIndex !== undefined ;
85
97
86
98
const markersInfo = useMemo ( ( ) => extractMarkersInfo ( pathSteps ) , [ pathSteps ] ) ;
87
99
88
- const startSimulation = ( ) => {
100
+ const startSimulation = async ( ) => {
89
101
const formErrorsStatus = checkStdcmConfigErrors ( pathSteps , t , pathfinding ?. status ) ;
90
102
if ( pathfinding ?. status === 'success' && ! formErrorsStatus ) {
103
+ dispatch ( addStdcmSimulation ( currentSimulationInputs ) ) ;
91
104
launchStdcmRequest ( ) ;
92
105
} else {
93
106
// The console error is only for debugging the user tests (temporary)
@@ -101,12 +114,15 @@ const StdcmConfig = ({
101
114
updateStdcmPathStep ( { id : origin . id , updates : { arrivalType : ArrivalTimeTypes . ASAP } } )
102
115
) ;
103
116
} ;
117
+
104
118
const removeDestinationArrivalTime = ( ) => {
105
119
dispatch (
106
120
updateStdcmPathStep ( { id : destination . id , updates : { arrivalType : ArrivalTimeTypes . ASAP } } )
107
121
) ;
108
122
} ;
109
123
124
+ const onItineraryChange = ( ) => setSkipPathfindingStatusMessage ( false ) ;
125
+
110
126
const getStatusMessage = ( ) => {
111
127
if ( isPathFindingLoading ) {
112
128
return t ( 'pathfindingStatus.calculating' ) ;
@@ -141,14 +157,14 @@ const StdcmConfig = ({
141
157
} , [ ] ) ;
142
158
143
159
useEffect ( ( ) => {
144
- if ( isPathFindingLoading ) {
160
+ if ( ! skipPathfindingStatusMessage && isPathFindingLoading ) {
145
161
setShowMessage ( true ) ;
146
162
}
147
163
148
164
if ( pathfinding ?. status === 'failure' ) {
149
165
setShowMessage ( false ) ;
150
166
}
151
- } , [ isPathFindingLoading , pathfinding ?. status ] ) ;
167
+ } , [ isPathFindingLoading , pathfinding ?. status , skipPathfindingStatusMessage ] ) ;
152
168
153
169
useLayoutEffect ( ( ) => {
154
170
const handleAnimationEnd = ( ) => {
@@ -185,9 +201,13 @@ const StdcmConfig = ({
185
201
</ div >
186
202
< div className = "stdcm__separator" />
187
203
< div ref = { formRef } className = "stdcm-simulation-itinerary" >
188
- < StdcmOrigin disabled = { disabled } />
189
- < StdcmVias disabled = { disabled } />
190
- < StdcmDestination disabled = { disabled } />
204
+ < StdcmOrigin disabled = { disabled } onItineraryChange = { onItineraryChange } />
205
+ < StdcmVias
206
+ disabled = { disabled }
207
+ skipAnimation = { skipPathfindingStatusMessage }
208
+ onItineraryChange = { onItineraryChange }
209
+ />
210
+ < StdcmDestination disabled = { disabled } onItineraryChange = { onItineraryChange } />
191
211
< StdcmLinkedTrainSearch
192
212
disabled = { disabled }
193
213
linkedTrainType = "posterior"
0 commit comments