diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx index 4f46570a04f..5da7ce58cfc 100644 --- a/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx +++ b/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx @@ -1,9 +1,6 @@ -import { useMemo } from 'react'; - import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; -import { getTimesInfoFromDate } from 'applications/stdcm/utils'; import DestinationIcon from 'assets/pictures/mapMarkers/destination.svg'; import { useOsrdConfSelectors } from 'common/osrdContext'; import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors'; @@ -20,13 +17,6 @@ const StdcmDestination = ({ disabled = false }: StdcmConfigCardProps) => { const destination = useSelector(getStdcmDestination); - const { destinationArrival } = useMemo( - () => ({ - destinationArrival: getTimesInfoFromDate(destination.arrival), - }), - [destination] - ); - return ( { pathStepId={destination.id} disabled={disabled} /> - + ); }; diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx index 717becb169e..85491e1b87f 100644 --- a/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx +++ b/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx @@ -8,7 +8,7 @@ import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext'; import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf'; import type { StdcmPathStep } from 'reducers/osrdconf/types'; import { useAppDispatch } from 'store'; -import { formatDateString, isArrivalDateInSearchTimeWindow } from 'utils/date'; +import { dateToHHMMSS, formatDateString } from 'utils/date'; import { createStringSelectOptions } from 'utils/uiCoreHelpers'; import type { ArrivalTimeTypes, ScheduleConstraint } from '../../types'; @@ -16,30 +16,11 @@ import type { ArrivalTimeTypes, ScheduleConstraint } from '../../types'; type StdcmOpScheduleProps = { disabled: boolean; pathStep: Extract; - opTimingData?: { - date: Date; - arrivalDate: string; - arrivalTime: string; - arrivalTimeHours: number; - arrivalTimeMinutes: number; - }; opId: string; isOrigin?: boolean; }; -const defaultDate = (date?: Date) => { - const newDate = date ? new Date(date) : new Date(); - newDate.setHours(0, 0, 0); - return newDate; -}; - -const StdcmOpSchedule = ({ - disabled, - pathStep, - opTimingData, - opId, - isOrigin = false, -}: StdcmOpScheduleProps) => { +const StdcmOpSchedule = ({ disabled, pathStep, opId, isOrigin = false }: StdcmOpScheduleProps) => { const { t } = useTranslation('stdcm'); const dispatch = useAppDispatch(); @@ -47,21 +28,20 @@ const StdcmOpSchedule = ({ const { getSearchDatetimeWindow } = useOsrdConfSelectors(); const searchDatetimeWindow = useSelector(getSearchDatetimeWindow); - const { arrivalDate, arrivalTime, arrivalTimeHours, arrivalTimeMinutes } = useMemo(() => { - const isArrivalDateValid = - opTimingData?.arrivalDate && - isArrivalDateInSearchTimeWindow(opTimingData.date, searchDatetimeWindow); - + const { arrivalTime, arrivalTimeHours, arrivalTimeMinutes } = useMemo(() => { + if (!pathStep.arrival) { + return { + arrivalTime: undefined, + arrivalTimeHours: undefined, + arrivalTimeMinutes: undefined, + }; + } return { - arrivalDate: - opTimingData && isArrivalDateValid - ? opTimingData.date - : defaultDate(searchDatetimeWindow?.begin), - arrivalTime: opTimingData?.arrivalTime, - arrivalTimeHours: opTimingData?.arrivalTimeHours, - arrivalTimeMinutes: opTimingData?.arrivalTimeMinutes, + arrivalTime: dateToHHMMSS(pathStep.arrival, { withoutSeconds: true }), + arrivalTimeHours: pathStep.arrival.getHours(), + arrivalTimeMinutes: pathStep.arrival.getMinutes(), }; - }, [opTimingData, searchDatetimeWindow]); + }, [pathStep.arrival]); const tolerances = useMemo( () => ({ @@ -94,11 +74,12 @@ const StdcmOpSchedule = ({ ); const onArrivalChange = ({ date, hours, minutes }: ScheduleConstraint) => { - date.setHours(hours, minutes); + const newDate = new Date(date); + newDate.setHours(hours, minutes); dispatch( updateStdcmPathStep({ id: pathStep.id, - updates: { arrival: date }, + updates: { arrival: newDate }, }) ); }; @@ -137,7 +118,7 @@ const StdcmOpSchedule = ({ disabled, }} selectableSlot={selectableSlot} - value={arrivalDate} + value={pathStep.arrival} onDateChange={(e) => { onArrivalChange({ date: e, @@ -153,7 +134,11 @@ const StdcmOpSchedule = ({ hours={arrivalTimeHours} minutes={arrivalTimeMinutes} onTimeChange={({ hours, minutes }) => { - onArrivalChange({ date: arrivalDate, hours, minutes }); + onArrivalChange({ + date: pathStep.arrival || searchDatetimeWindow!.begin, + hours, + minutes, + }); }} disabled={disabled} value={arrivalTime} diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx index 8623b65fe84..63b760c2bac 100644 --- a/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx +++ b/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx @@ -1,9 +1,6 @@ -import { useMemo } from 'react'; - import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; -import { getTimesInfoFromDate } from 'applications/stdcm/utils'; import OriginIcon from 'assets/pictures/mapMarkers/start.svg'; import { useOsrdConfSelectors } from 'common/osrdContext'; import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors'; @@ -19,13 +16,6 @@ const StdcmOrigin = ({ disabled = false }: StdcmConfigCardProps) => { const { getStdcmOrigin } = useOsrdConfSelectors() as StdcmConfSelectors; const origin = useSelector(getStdcmOrigin); - const { originArrival } = useMemo( - () => ({ - originArrival: getTimesInfoFromDate(origin.arrival), - }), - [origin] - ); - return ( { pathStepId={origin.id} disabled={disabled} /> - + ); }; diff --git a/front/tests/utils/setup-utils.ts b/front/tests/utils/setup-utils.ts index de6bbc3af9d..6e81ea29a59 100644 --- a/front/tests/utils/setup-utils.ts +++ b/front/tests/utils/setup-utils.ts @@ -177,8 +177,8 @@ export async function createDataForTests(): Promise { const stdcmEnvironment = { infra_id: smallInfra.id, - search_window_begin: '2024-10-17T00:00:00Z', - search_window_end: '2024-10-18T23:59:59Z', + search_window_begin: '2024-10-17T00:00:01+02:00', + search_window_end: '2024-10-18T23:59:59+02:00', timetable_id: scenarioTrainSchedule.timetable_id, } as StdcmSearchEnvironment;