diff --git a/front/src/modules/timesStops/DurationCell.tsx b/front/src/modules/timesStops/DurationCell.tsx index c3397ba1c61..a02748d383a 100644 --- a/front/src/modules/timesStops/DurationCell.tsx +++ b/front/src/modules/timesStops/DurationCell.tsx @@ -395,18 +395,15 @@ export type DurationCellHandle = { focus: () => void; }; -const DurationCell = ({ - disabled, - clearButtonTitle, - ref, - ...props -}: CellContext & +type DurationCellProps = CellContext & Omit, 'onChange'> & { - onCommit?: (seconds: number | null, propagationMode: StopPropagationMode) => void; + onCommit?: (value: Duration | null, propagationMode: StopPropagationMode) => void; disabled?: boolean; clearButtonTitle?: string; ref?: React.Ref; - }) => { + }; + +const DurationCell = ({ disabled, clearButtonTitle, ref, ...props }: DurationCellProps) => { const { onCommit, getValue, row, table } = props || {}; const controlledValue = getValue(); const [state, dispatch] = useReducer(durationReducer, controlledValue, initialDurationState); @@ -458,7 +455,8 @@ const DurationCell = ({ const newSeconds = unitsToSeconds(state.units); const initialSeconds = controlledValue !== null ? Math.round(controlledValue.total('second')) : null; - if (newSeconds !== initialSeconds) onCommit?.(newSeconds, propagationMode); + const newValue = new Duration({ seconds: newSeconds }); + if (newSeconds !== initialSeconds) onCommit?.(newValue, propagationMode); } dispatch({ type: 'STOP_EDITING' }); }; diff --git a/front/src/modules/timesStops/TimeStopsTableWrapper.tsx b/front/src/modules/timesStops/TimeStopsTableWrapper.tsx index 515f67c0965..167f995899b 100644 --- a/front/src/modules/timesStops/TimeStopsTableWrapper.tsx +++ b/front/src/modules/timesStops/TimeStopsTableWrapper.tsx @@ -259,7 +259,7 @@ const TimeStopsTableWrapper = ({ rowId: singleEdit.rowId, field: 'stopDurationWithArrival', value: { - stop: update.value !== null ? new Duration({ seconds: update.value }) : null, + stop: update.value, arrival: editedRowArrivalEdit.value ?? propagationResult.updatedStartTime, }, } @@ -336,22 +336,22 @@ const TimeStopsTableWrapper = ({ const handleStopDurationChange = ( row: TimesStopsRowNew, - durationSeconds: number | null, + duration: Duration | null, propagationMode: StopPropagationMode ) => { const singleEdit: PendingEdit = { rowId: row.id, field: 'stopDuration', - value: durationSeconds !== null ? new Duration({ seconds: durationSeconds }) : null, + value: duration, }; commitEdit( buildEditsForStopDurationUpdate(singleEdit, { row, field: 'stopDuration', - value: durationSeconds, + value: duration, propagationMode, }), - () => updateStopDuration(row, durationSeconds, propagationMode) + () => updateStopDuration(row, duration, propagationMode) ); }; diff --git a/front/src/modules/timesStops/TimesStopsTable.tsx b/front/src/modules/timesStops/TimesStopsTable.tsx index ac5dd208832..631d5e80327 100644 --- a/front/src/modules/timesStops/TimesStopsTable.tsx +++ b/front/src/modules/timesStops/TimesStopsTable.tsx @@ -51,7 +51,7 @@ declare module '@tanstack/react-table' { ) => void; onStopDurationChange: ( row: TimesStopsRowNew, - durationSeconds: number | null, + duration: Duration | null, propagationMode: StopPropagationMode ) => void; onDepartureChange: ( @@ -113,7 +113,7 @@ type TimesStopsTableProps = { ) => void; onStopDurationChange: ( row: TimesStopsRowNew, - durationSeconds: number | null, + duration: Duration | null, propagationMode: StopPropagationMode ) => void; onDepartureChange: ( diff --git a/front/src/modules/timesStops/helpers/__tests__/stopDurationPropagation.spec.ts b/front/src/modules/timesStops/helpers/__tests__/stopDurationPropagation.spec.ts index a10a93cbac6..6939aa38b92 100644 --- a/front/src/modules/timesStops/helpers/__tests__/stopDurationPropagation.spec.ts +++ b/front/src/modules/timesStops/helpers/__tests__/stopDurationPropagation.spec.ts @@ -59,7 +59,7 @@ describe('propagateStopDuration', () => { { row: makeRow('PT5M'), field: 'stopDuration', - value: 900, + value: new Duration({ minutes: 15 }), propagationMode: 'atThisWaypoint', }, train @@ -70,7 +70,7 @@ describe('propagateStopDuration', () => { { row: { ...makeRow('PT5M'), pathStepId: null }, field: 'stopDuration', - value: 900, + value: new Duration({ minutes: 15 }), propagationMode: 'toDestination', }, train @@ -82,7 +82,12 @@ describe('propagateStopDuration', () => { const train = makeTrain('PT5M'); const row = makeRow('PT5M'); const result = propagateStopDuration( - { row, field: 'stopDuration', value: 900, propagationMode: 'toDestination' }, // +10min + { + row, + field: 'stopDuration', + value: new Duration({ minutes: 15 }), + propagationMode: 'toDestination', + }, // +10min train ); expect(result).toBeDefined(); @@ -101,7 +106,12 @@ describe('propagateStopDuration', () => { const train = makeTrain('PT5M'); const row = makeRow('PT5M'); const result = propagateStopDuration( - { row, field: 'stopDuration', value: 600, propagationMode: 'fromDeparture' }, // +5min + { + row, + field: 'stopDuration', + value: new Duration({ minutes: 10 }), + propagationMode: 'fromDeparture', + }, // +5min train ); expect(result).toBeDefined(); @@ -119,7 +129,12 @@ describe('propagateStopDuration', () => { const train = makeTrainWithoutOp11(); const row = makeRow(null); const result = propagateStopDuration( - { row, field: 'stopDuration', value: 600, propagationMode: 'fromDeparture' }, // +10min + { + row, + field: 'stopDuration', + value: new Duration({ minutes: 10 }), + propagationMode: 'fromDeparture', + }, // +10min train ); expect(result).toBeDefined(); diff --git a/front/src/modules/timesStops/helpers/stopDurationPropagation.ts b/front/src/modules/timesStops/helpers/stopDurationPropagation.ts index 03a31392aaa..6f2c4ee5a1d 100644 --- a/front/src/modules/timesStops/helpers/stopDurationPropagation.ts +++ b/front/src/modules/timesStops/helpers/stopDurationPropagation.ts @@ -39,7 +39,7 @@ export const propagateStopDuration = ( // Delta between the old and new stop duration — drives every shift below. const oldDuration = update.row.stopDuration ?? Duration.zero; - const newDuration = new Duration({ seconds: update.value }); + const newDuration = update.value; const delta = newDuration.sub(oldDuration); // The edited point's current schedule state, if it already has one. diff --git a/front/src/modules/timesStops/hooks/useUpdateTimesStopsTable.ts b/front/src/modules/timesStops/hooks/useUpdateTimesStopsTable.ts index 01d4ba583cc..1f098c4c746 100644 --- a/front/src/modules/timesStops/hooks/useUpdateTimesStopsTable.ts +++ b/front/src/modules/timesStops/hooks/useUpdateTimesStopsTable.ts @@ -168,16 +168,7 @@ const useUpdateTimesStopsTable = ( }; } - // Convert CellUpdate to OptimisticEdit (stopDuration: number → Duration) - let edit: Exclude; - if (update.field === 'stopDuration') { - edit = { - field: 'stopDuration', - value: update.value !== null ? new Duration({ seconds: update.value }) : null, - }; - } else { - edit = update; - } + const edit: Exclude = update; const newState = applyScheduleEdit( { arrival: update.row.requestedArrival, stop: update.row.stopDuration }, @@ -422,8 +413,8 @@ const useUpdateTimesStopsTable = ( ); const updateStopDuration = useCallback( - (row: TimesStopsRowNew, durationSeconds: number | null, propagationMode: StopPropagationMode) => - updateCell({ row, field: 'stopDuration', value: durationSeconds, propagationMode }), + (row: TimesStopsRowNew, duration: Duration | null, propagationMode: StopPropagationMode) => + updateCell({ row, field: 'stopDuration', value: duration, propagationMode }), [updateCell] ); diff --git a/front/src/modules/timesStops/types.ts b/front/src/modules/timesStops/types.ts index 9fd07f0b0e5..25881ee8356 100644 --- a/front/src/modules/timesStops/types.ts +++ b/front/src/modules/timesStops/types.ts @@ -134,7 +134,7 @@ export type ArrivalUpdate = { export type StopDurationUpdate = { row: TimesStopsRowNew; field: 'stopDuration'; - value: number | null; + value: Duration | null; propagationMode: StopPropagationMode; };