Skip to content

Commit

Permalink
front: stdcm: display a message if a pathstep time is invalid
Browse files Browse the repository at this point in the history
Signed-off-by: SharglutDev <p.filimon75@gmail.com>
  • Loading branch information
SharglutDev committed Jan 7, 2025
1 parent a1ac8e9 commit 6555312
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 20 deletions.
2 changes: 2 additions & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
"stdcmErrors": {
"bothPointAreScheduled": "The calculation cannot take into account both an origin and a destination schedule. You have to choose one or the other:",
"infraNotLoaded": "Infrastructure is loading",
"invalidOriginTime": "Origin departure time is invalid",
"invalidDestinationTime": "Destination arrival time is invalid",
"missingLocation": "Missing location",
"noPaths": "Incompatibility with other train paths.",
"noResults": "No path found",
Expand Down
4 changes: 3 additions & 1 deletion front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"helpUs": "Aidez-nous à améliorer ST DCM",
"other": "Autre",
"reason": "Cette simulation ne répond pas à vos besoin car ...",
"startIncompatible": "Heure départ incompatible",
"startIncompatible": "Heure de départ incompatible",
"unqualifiedDriver": "Conducteur non habilité"
}
},
Expand All @@ -90,6 +90,8 @@
"stdcmErrors": {
"bothPointAreScheduled": "Le calcul ne peut pas prendre en compte à la fois un horaire d'origine et un horaire de destination. Il faut choisir l'un ou l'autre :",
"infraNotLoaded": "Infrastructure en cours de chargement",
"invalidOriginTime": "L'heure de départ de l'origine est invalide",
"invalidDestinationTime": "L'heure d'arrivée de la destination est invalide",
"missingLocation": "Localisation manquante",
"noPaths": "Incompatibilité avec d'autres sillons.",
"noResults": "Aucun sillon trouvé",
Expand Down
13 changes: 11 additions & 2 deletions front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ const StdcmConfig = ({
getProjectID,
getScenarioID,
getStudyID,
getSearchDatetimeWindow,
} = useOsrdConfSelectors() as StdcmConfSelectors;
const origin = useSelector(getStdcmOrigin);
const pathSteps = useSelector(getStdcmPathSteps);
const destination = useSelector(getStdcmDestination);
const projectID = useSelector(getProjectID);
const studyID = useSelector(getStudyID);
const scenarioID = useSelector(getScenarioID);
const searchDatetimeWindow = useSelector(getSearchDatetimeWindow);

const pathfinding = useStaticPathfinding(infra);
const formRef = useRef<HTMLDivElement>(null);
Expand All @@ -80,7 +82,13 @@ const StdcmConfig = ({

const startSimulation = () => {
const isPathfindingFailed = !!pathfinding && pathfinding.status !== 'success';
const formErrorsStatus = checkStdcmConfigErrors(isPathfindingFailed, pathSteps, t);
const formErrorsStatus = checkStdcmConfigErrors(
isPathfindingFailed,
pathSteps,
t,
searchDatetimeWindow,
{ simulationStarting: true }
);
if (pathfinding?.status === 'success' && !formErrorsStatus) {
launchStdcmRequest();
} else {
Expand All @@ -106,7 +114,8 @@ const StdcmConfig = ({
const formErrorsStatus = checkStdcmConfigErrors(
pathfinding.status !== 'success',
pathSteps,
t
t,
searchDatetimeWindow
);
setFormErrors(formErrorsStatus);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const StdcmDestination = ({ disabled = false }: StdcmConfigCardProps) => {
);

const onArrivalChange = ({ date, hours, minutes }: ScheduleConstraint) => {
console.log('change date', date, hours, minutes);
date.setHours(hours, minutes);
dispatch(
updateStdcmPathStep({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ const StdcmOpSchedule = ({
disabled={disabled}
value={arrivalTime}
readOnly={false}
// statusWithMessage={
// }
/>
<div className="mr-n2 pr-1">
<TolerancePicker
Expand Down
19 changes: 8 additions & 11 deletions front/src/applications/stdcm/components/StdcmWarningBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ const SHORT_TEXT_ERRORS = [
];

type StdcmWarningBoxProps = {
errorInfos: {
errorType: StdcmConfigErrorTypes;
errorDetails?: StdcmConfigErrors['errorDetails'];
};
errorInfos: StdcmConfigErrors;
removeOriginArrivalTime: () => void;
removeDestinationArrivalTime: () => void;
};

const StdcmWarningBox = ({
errorInfos: { errorType, errorDetails },
errorInfos,
removeOriginArrivalTime,
removeDestinationArrivalTime,
}: StdcmWarningBoxProps) => {
Expand All @@ -32,23 +29,23 @@ const StdcmWarningBox = ({
</span>
<p
className={cx('mb-0', {
'text-center': SHORT_TEXT_ERRORS.includes(errorType),
'text-justify': !SHORT_TEXT_ERRORS.includes(errorType),
'text-center': SHORT_TEXT_ERRORS.includes(errorInfos.errorType),
'text-justify': !SHORT_TEXT_ERRORS.includes(errorInfos.errorType),
})}
>
{t(`stdcmErrors.${errorType}`)}
{t(`stdcmErrors.${errorInfos.errorType}`)}
</p>
{errorType === 'bothPointAreScheduled' && errorDetails && (
{errorInfos.errorType === 'bothPointAreScheduled' && (
<div className="stdcm-warning-buttons">
<Button
type="button"
onClick={removeDestinationArrivalTime}
label={errorDetails.originTime}
label={errorInfos.errorDetails.originTime}
/>
<Button
type="button"
onClick={removeOriginArrivalTime}
label={errorDetails.destinationTime}
label={errorInfos.errorDetails.destinationTime}
/>
</div>
)}
Expand Down
14 changes: 10 additions & 4 deletions front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,18 @@ export enum StdcmConfigErrorTypes {
PATHFINDING_FAILED = 'pathfindingFailed',
BOTH_POINT_SCHEDULED = 'bothPointAreScheduled',
NO_SCHEDULED_POINT = 'noScheduledPoint',
INVALID_ORIGIN_TIME = 'invalidOriginTime',
INVALID_DESTINATION_TIME = 'invalidDestinationTime',
}

export type StdcmConfigErrors = {
errorType: StdcmConfigErrorTypes;
errorDetails?: { originTime: string; destinationTime: string };
};
export type StdcmConfigErrors =
| {
errorType: Exclude<StdcmConfigErrorTypes, StdcmConfigErrorTypes.BOTH_POINT_SCHEDULED>;
}
| {
errorType: StdcmConfigErrorTypes.BOTH_POINT_SCHEDULED;
errorDetails: { originTime: string; destinationTime: string };
};

export type ScheduleConstraint = {
date: Date;
Expand Down
33 changes: 31 additions & 2 deletions front/src/applications/stdcm/utils/checkStdcmConfigErrors.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { TFunction } from 'i18next';

import type { StdcmPathStep } from 'reducers/osrdconf/types';
import { dateToHHMMSS } from 'utils/date';
import { dateToHHMMSS, isArrivalDateInSearchTimeWindow } from 'utils/date';

import { StdcmConfigErrorTypes, ArrivalTimeTypes, type StdcmConfigErrors } from '../types';

const checkStdcmConfigErrors = (
pathfindingStateError: boolean,
pathSteps: StdcmPathStep[],
t: TFunction
t: TFunction,
searchDatetimeWindow?: { begin: Date; end: Date },
{ simulationStarting = false }: { simulationStarting?: boolean } = {}
): StdcmConfigErrors | undefined => {
if (pathSteps.some((step) => !step.location)) {
return { errorType: StdcmConfigErrorTypes.MISSING_LOCATION };
Expand All @@ -27,6 +29,33 @@ const checkStdcmConfigErrors = (
return { errorType: StdcmConfigErrorTypes.PATHFINDING_FAILED };
}

console.log(
'origin',
origin.arrival,
!origin.arrival || isArrivalDateInSearchTimeWindow(origin.arrival, searchDatetimeWindow)
);

if (
simulationStarting &&
origin.arrivalType === ArrivalTimeTypes.PRECISE_TIME &&
(!origin.arrival || isArrivalDateInSearchTimeWindow(origin.arrival, searchDatetimeWindow))
) {
return {
errorType: StdcmConfigErrorTypes.INVALID_ORIGIN_TIME,
};
}

if (
simulationStarting &&
destination.arrivalType === ArrivalTimeTypes.PRECISE_TIME &&
(!destination.arrival ||
isArrivalDateInSearchTimeWindow(destination.arrival, searchDatetimeWindow))
) {
return {
errorType: StdcmConfigErrorTypes.INVALID_DESTINATION_TIME,
};
}

const isOriginRespectDestinationSchedule =
origin.arrivalType === ArrivalTimeTypes.RESPECT_DESTINATION_SCHEDULE;

Expand Down

0 comments on commit 6555312

Please sign in to comment.