Skip to content

Commit 97db6c4

Browse files
committed
front: display stdcm error message even when pathfinding is not called
Pathfinding is prevented when some validity checks don't pass, as for example when the user selects the same origin and destination. The error warning was only updated when pathfinging occurs, causing the user warnings not to be displayed when we could detect before launching the pathfinding that its request would be invalid. Update the warnings independently on whether the pathfinding actually happened so that invalid checks preventing the pathfinding also generate their user warnings.
1 parent f94837f commit 97db6c4

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx

+3-10
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ const StdcmConfig = ({
127127
const markersInfo = useMemo(() => extractMarkersInfo(pathSteps), [pathSteps]);
128128

129129
const startSimulation = () => {
130-
const isPathfindingFailed = !!pathfinding && pathfinding.status !== 'success';
131-
const formErrorsStatus = checkStdcmConfigErrors(isPathfindingFailed, pathSteps, t);
130+
const formErrorsStatus = checkStdcmConfigErrors(pathSteps, t, pathfinding?.status);
132131
if (pathfinding?.status === 'success' && !formErrorsStatus) {
133132
launchStdcmRequest();
134133
} else {
@@ -157,14 +156,8 @@ const StdcmConfig = ({
157156
};
158157

159158
useEffect(() => {
160-
if (pathfinding) {
161-
const formErrorsStatus = checkStdcmConfigErrors(
162-
pathfinding.status !== 'success',
163-
pathSteps,
164-
t
165-
);
166-
setFormErrors(formErrorsStatus);
167-
}
159+
const formErrorsStatus = checkStdcmConfigErrors(pathSteps, t, pathfinding?.status);
160+
setFormErrors(formErrorsStatus);
168161
}, [pathfinding, pathSteps, t]);
169162

170163
useEffect(() => {

front/src/applications/stdcm/utils/checkStdcmConfigErrors.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { dateToHHMMSS } from 'utils/date';
66
import { StdcmConfigErrorTypes, ArrivalTimeTypes, type StdcmConfigErrors } from '../types';
77

88
const checkStdcmConfigErrors = (
9-
pathfindingStateError: boolean,
109
pathSteps: StdcmPathStep[],
11-
t: TFunction
10+
t: TFunction,
11+
pathfindingStatus?: 'success' | 'failure'
1212
): StdcmConfigErrors | undefined => {
1313
if (pathSteps.some((step) => !step.location)) {
1414
return { errorType: StdcmConfigErrorTypes.MISSING_LOCATION };
@@ -30,7 +30,7 @@ const checkStdcmConfigErrors = (
3030
return { errorType: StdcmConfigErrorTypes.ZERO_LENGTH_PATH };
3131
}
3232

33-
if (pathfindingStateError) {
33+
if (pathfindingStatus && pathfindingStatus === 'failure') {
3434
return { errorType: StdcmConfigErrorTypes.PATHFINDING_FAILED };
3535
}
3636

0 commit comments

Comments
 (0)