Skip to content

Commit

Permalink
front: display stdcm error message even when pathfinding is not called
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Loup Federico <[email protected]>
  • Loading branch information
Sh099078 committed Jan 22, 2025
1 parent dbfe2ac commit c014f83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
13 changes: 3 additions & 10 deletions front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ const StdcmConfig = ({
const markersInfo = useMemo(() => extractMarkersInfo(pathSteps), [pathSteps]);

const startSimulation = () => {
const isPathfindingFailed = !!pathfinding && pathfinding.status !== 'success';
const formErrorsStatus = checkStdcmConfigErrors(isPathfindingFailed, pathSteps, t);
const formErrorsStatus = checkStdcmConfigErrors(pathSteps, t, pathfinding?.status);
if (pathfinding?.status === 'success' && !formErrorsStatus) {
launchStdcmRequest();
} else {
Expand Down Expand Up @@ -157,14 +156,8 @@ const StdcmConfig = ({
};

useEffect(() => {
if (pathfinding) {
const formErrorsStatus = checkStdcmConfigErrors(
pathfinding.status !== 'success',
pathSteps,
t
);
setFormErrors(formErrorsStatus);
}
const formErrorsStatus = checkStdcmConfigErrors(pathSteps, t, pathfinding?.status);
setFormErrors(formErrorsStatus);
}, [pathfinding, pathSteps, t]);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions front/src/applications/stdcm/utils/checkStdcmConfigErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { dateToHHMMSS } from 'utils/date';
import { StdcmConfigErrorTypes, ArrivalTimeTypes, type StdcmConfigErrors } from '../types';

const checkStdcmConfigErrors = (
pathfindingStateError: boolean,
pathSteps: StdcmPathStep[],
t: TFunction
t: TFunction,
pathfindingStatus?: 'success' | 'failure'
): StdcmConfigErrors | undefined => {
if (pathSteps.some((step) => !step.location)) {
return { errorType: StdcmConfigErrorTypes.MISSING_LOCATION };
Expand All @@ -30,7 +30,7 @@ const checkStdcmConfigErrors = (
return { errorType: StdcmConfigErrorTypes.ZERO_LENGTH_PATH };
}

if (pathfindingStateError) {
if (pathfindingStatus && pathfindingStatus === 'failure') {
return { errorType: StdcmConfigErrorTypes.PATHFINDING_FAILED };
}

Expand Down

0 comments on commit c014f83

Please sign in to comment.