Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: fix row deletion in timestop input table #9739

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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
6 changes: 5 additions & 1 deletion front/src/modules/timesStops/TimesStopsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
durationSinceStartTime,
formatSuggestedViasToRowVias,
onStopSignalToReceptionSignal,
normalizeNullablesInRow,
updateDaySinceDeparture,
updateRowTimesAndMargin,
} from './helpers/utils';
Expand Down Expand Up @@ -125,7 +126,10 @@ const TimesStopsInput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInput
setRows(newRows);
} else {
const newVias = updatedRows
.filter((row, index) => !isEqual(row, rows[index]))
.filter(
(row, index) =>
!isEqual(normalizeNullablesInRow(row), normalizeNullablesInRow(rows[index]))
)
.map(({ shortSlipDistance, onStopSignal, arrival, departure, ...row }) => ({
...row,
arrival: durationSinceStartTime(startTime, arrival),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('updateRowTimesAndMargin', () => {
name: 'Gr',
arrival: undefined,
isMarginValid: true,
onStopSignal: false,
onStopSignal: undefined,
theoreticalMargin: '0%',
});
});
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('updateRowTimesAndMargin', () => {
departure: undefined,
stopFor: undefined,
isMarginValid: true,
onStopSignal: false,
onStopSignal: undefined,
});
});
});
Expand Down
21 changes: 20 additions & 1 deletion front/src/modules/timesStops/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ export function updateRowTimesAndMargin(
newRowData.stopFor = undefined;
}
}
if (!newRowData.stopFor && op.fromRowIndex !== allWaypointsLength - 1) {
if (
!newRowData.stopFor &&
newRowData.onStopSignal &&
op.fromRowIndex !== allWaypointsLength - 1
) {
newRowData.onStopSignal = false;
}
newRowData.isMarginValid = !(
Expand All @@ -213,6 +217,21 @@ export function updateRowTimesAndMargin(
return newRowData;
}

/**
* This function is called before comparing rows to prevent a change from undefined to null (or the reverse)
* from being treated as an actual update of a row (otherwise changes would occur on deletion of an undefined field)
*/
export function normalizeNullablesInRow(row: TimesStopsInputRow): TimesStopsInputRow {
const normalizedRow = { ...row };
if (normalizedRow.stopFor === null) {
normalizedRow.stopFor = undefined;
}
if (normalizedRow.theoreticalMargin === null) {
normalizedRow.theoreticalMargin = undefined;
}
return normalizedRow;
}

/**
* This function goes through the whole array of path waypoints
* and updates the number of days since departure.
Expand Down
Loading