Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions front/src/modules/timesStops/DurationCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,15 @@ export type DurationCellHandle = {
focus: () => void;
};

const DurationCell = ({
disabled,
clearButtonTitle,
ref,
...props
}: CellContext<TimesStopsRowNew, Duration | null> &
type DurationCellProps = CellContext<TimesStopsRowNew, Duration | null> &
Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> & {
onCommit?: (seconds: number | null, propagationMode: StopPropagationMode) => void;
onCommit?: (value: Duration | null, propagationMode: StopPropagationMode) => void;
disabled?: boolean;
clearButtonTitle?: string;
ref?: React.Ref<DurationCellHandle>;
}) => {
};

const DurationCell = ({ disabled, clearButtonTitle, ref, ...props }: DurationCellProps) => {
const { onCommit, getValue, row, table } = props || {};
const controlledValue = getValue();
const [state, dispatch] = useReducer(durationReducer, controlledValue, initialDurationState);
Expand Down Expand Up @@ -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' });
};
Expand Down
10 changes: 5 additions & 5 deletions front/src/modules/timesStops/TimeStopsTableWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down Expand Up @@ -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)
);
};

Expand Down
4 changes: 2 additions & 2 deletions front/src/modules/timesStops/TimesStopsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ declare module '@tanstack/react-table' {
) => void;
onStopDurationChange: (
row: TimesStopsRowNew,
durationSeconds: number | null,
duration: Duration | null,
propagationMode: StopPropagationMode
) => void;
onDepartureChange: (
Expand Down Expand Up @@ -113,7 +113,7 @@ type TimesStopsTableProps = {
) => void;
onStopDurationChange: (
row: TimesStopsRowNew,
durationSeconds: number | null,
duration: Duration | null,
propagationMode: StopPropagationMode
) => void;
onDepartureChange: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('propagateStopDuration', () => {
{
row: makeRow('PT5M'),
field: 'stopDuration',
value: 900,
value: new Duration({ minutes: 15 }),
propagationMode: 'atThisWaypoint',
},
train
Expand All @@ -70,7 +70,7 @@ describe('propagateStopDuration', () => {
{
row: { ...makeRow('PT5M'), pathStepId: null },
field: 'stopDuration',
value: 900,
value: new Duration({ minutes: 15 }),
propagationMode: 'toDestination',
},
train
Expand All @@ -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
Comment on lines +85 to +90

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I know that the conversion is good, but i found that the +10min commentary is a bit misleading as we pass minutes: 15 to Duration

train
);
expect(result).toBeDefined();
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

train
);
expect(result).toBeDefined();
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

train
);
expect(result).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 3 additions & 12 deletions front/src/modules/timesStops/hooks/useUpdateTimesStopsTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,7 @@ const useUpdateTimesStopsTable = (
};
}

// Convert CellUpdate to OptimisticEdit (stopDuration: number → Duration)
let edit: Exclude<OptimisticEdit, { field: 'powerRestriction' }>;
if (update.field === 'stopDuration') {
edit = {
field: 'stopDuration',
value: update.value !== null ? new Duration({ seconds: update.value }) : null,
};
} else {
edit = update;
}
const edit: Exclude<OptimisticEdit, { field: 'powerRestriction' }> = update;

const newState = applyScheduleEdit(
{ arrival: update.row.requestedArrival, stop: update.row.stopDuration },
Expand Down Expand Up @@ -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]
);

Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/timesStops/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export type ArrivalUpdate = {
export type StopDurationUpdate = {
row: TimesStopsRowNew;
field: 'stopDuration';
value: number | null;
value: Duration | null;
propagationMode: StopPropagationMode;
};

Expand Down
Loading