diff --git a/front/public/locales/en/stdcm.json b/front/public/locales/en/stdcm.json index cd1e8f267af..4cf9b3a82dc 100644 --- a/front/public/locales/en/stdcm.json +++ b/front/public/locales/en/stdcm.json @@ -77,8 +77,15 @@ "origin": "Origin", "preciseTime": "precise time", "stopFor": "Minimum stop time", + "stopType": { + "driverSwitch": "driver switch", + "passageTime":"passage time", + "serviceStop": "service stop" + }, "time": "Time", "tolerance": "Tolerance", - "vias": "Intermediate OP" + "type": "Type", + "vias": "Intermediate OP", + "warningMinStopTime": "The driver switch stop time must be at least 3 minutes." } } diff --git a/front/public/locales/fr/stdcm.json b/front/public/locales/fr/stdcm.json index 5e4363ff9bd..5c6f0ebc19c 100644 --- a/front/public/locales/fr/stdcm.json +++ b/front/public/locales/fr/stdcm.json @@ -77,8 +77,15 @@ "origin": "Origine", "preciseTime": "horaire précis", "stopFor": "Temps d'arrêt minimum", + "stopType": { + "driverSwitch": "relève conducteur", + "passageTime":"passage", + "serviceStop": "arrêt de service" + }, "time": "Heure", "tolerance": "Tolérance", - "vias": "PR intermédiaire" + "type": "Type", + "vias": "PR intermédiaire", + "warningMinStopTime": "Le temps d'arrêt d'une relève conducteur est d'au moins 3 minutes." } } diff --git a/front/src/applications/stdcmV2/components/StdcmInputVia.tsx b/front/src/applications/stdcmV2/components/StdcmInputVia.tsx index 009567604d2..5a74e967dab 100644 --- a/front/src/applications/stdcmV2/components/StdcmInputVia.tsx +++ b/front/src/applications/stdcmV2/components/StdcmInputVia.tsx @@ -1,4 +1,4 @@ -import { useState, useMemo } from 'react'; +import { useState, useMemo, useEffect } from 'react'; import { Input } from '@osrd-project/ui-core'; import { debounce } from 'lodash'; @@ -7,10 +7,14 @@ import { useTranslation } from 'react-i18next'; import type { PathStep } from 'reducers/osrdconf/types'; import { ISO8601Duration2sec } from 'utils/timeManipulation'; +import { StdcmStopTypes } from '../types'; + const StdcmInputVia = ({ + stopType, pathStep, updatePathStepStopTime, }: { + stopType: StdcmStopTypes; pathStep: PathStep; updatePathStepStopTime: (stopTime: string) => void; }) => { @@ -20,27 +24,61 @@ const StdcmInputVia = ({ pathStep.stopFor ? `${ISO8601Duration2sec(pathStep.stopFor) / 60}` : '' ); + const [showWarning, setShowWarning] = useState(false); + const debounceUpdatePathStepStopTime = useMemo( () => debounce((value) => updatePathStepStopTime(value), 500), [] ); + useEffect(() => { + let newStopTime = pathStepStopTime; + let warning = false; + + const isDriverSwitch = stopType === StdcmStopTypes.DRIVER_SWITCH; + const isPassageTime = stopType === StdcmStopTypes.PASSAGE_TIME; + const isServiceStop = stopType === StdcmStopTypes.SERVICE_STOP; + + if (isPassageTime && pathStepStopTime !== '0') { + newStopTime = '0'; + } else if (isDriverSwitch) { + const stopTimeValue = Number(pathStepStopTime); + if (stopTimeValue === 0) { + newStopTime = '3'; + } else if (stopTimeValue < 3) { + warning = true; + } + } else if (isServiceStop && pathStepStopTime !== '0') { + newStopTime = ''; + } + + if (newStopTime !== pathStepStopTime) { + setPathStepStopTime(newStopTime); + updatePathStepStopTime(newStopTime); + } + + setShowWarning(warning); + }, [stopType, pathStepStopTime]); + return ( -
- { - // TODO: Find a better way to prevent user from entering decimal values - const value = e.target.value.replace(/[\D.,]/g, ''); - setPathStepStopTime(value); - debounceUpdatePathStepStopTime(value); - }} - value={pathStepStopTime} - trailingContent="minutes" - /> -
+ stopType !== StdcmStopTypes.PASSAGE_TIME && ( +
+ { + // TODO: Find a better way to prevent user from entering decimal values + const value = e.target.value.replace(/[\D.,]/g, ''); + setPathStepStopTime(value); + debounceUpdatePathStepStopTime(value); + }} + value={pathStepStopTime} + trailingContent="minutes" + /> + {showWarning &&
{t('trainPath.warningMinStopTime')}
} +
+ ) ); }; diff --git a/front/src/applications/stdcmV2/components/StdcmStopType.tsx b/front/src/applications/stdcmV2/components/StdcmStopType.tsx new file mode 100644 index 00000000000..edbe6a1f910 --- /dev/null +++ b/front/src/applications/stdcmV2/components/StdcmStopType.tsx @@ -0,0 +1,33 @@ +import { Select } from '@osrd-project/ui-core'; +import { useTranslation } from 'react-i18next'; + +import type { StdcmStopTypes } from '../types'; + +type StdcmStopTypeProps = { + stopTypes: StdcmStopTypes; + onStdcmStopTypesChange: (arrivalType: StdcmStopTypes) => void; +}; + +const StdcmStopType = ({ stopTypes, onStdcmStopTypesChange }: StdcmStopTypeProps) => { + const { t } = useTranslation('stdcm'); + + return ( +
+