From 61b0210ea7d39d6cea51e88c884d6cf66793a93b Mon Sep 17 00:00:00 2001 From: romainvalls Date: Wed, 9 Oct 2024 18:12:23 +0200 Subject: [PATCH] front: add shortslip distance checkbox in timestops Signed-off-by: romainvalls --- front/public/locales/en/timesStops.json | 1 + front/public/locales/fr/timesStops.json | 1 + .../modules/timesStops/TimesStopsInput.tsx | 4 ++-- front/src/modules/timesStops/helpers/utils.ts | 24 +++++++++++-------- .../timesStops/hooks/useTimeStopsColumns.ts | 7 ++++++ front/src/modules/timesStops/types.ts | 1 + 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/front/public/locales/en/timesStops.json b/front/public/locales/en/timesStops.json index 7c21612df65..38037be4da6 100644 --- a/front/public/locales/en/timesStops.json +++ b/front/public/locales/en/timesStops.json @@ -9,6 +9,7 @@ "noPathLoaded": "No path loaded", "realMargin": "Real margin", "receptionOnClosedSignal": "Reception on Closed Signal", + "shortSlipDistance": "Short Slip Distance", "stopTime": "Stopping Time (s)", "theoreticalMargin": "Theoretical Margin", "theoreticalMarginPlaceholder": "% or min/100km", diff --git a/front/public/locales/fr/timesStops.json b/front/public/locales/fr/timesStops.json index bb09abff5c8..f12db5cc2b8 100644 --- a/front/public/locales/fr/timesStops.json +++ b/front/public/locales/fr/timesStops.json @@ -9,6 +9,7 @@ "noPathLoaded": "Aucun chemin chargé", "realMargin": "Marge réelle", "receptionOnClosedSignal": "Réception sur signal fermé", + "shortSlipDistance": "Faible glissement", "stopTime": "Temps d'arrêt (s)", "theoreticalMargin": "Marge théorique", "theoreticalMarginPlaceholder": "% ou min/100km", diff --git a/front/src/modules/timesStops/TimesStopsInput.tsx b/front/src/modules/timesStops/TimesStopsInput.tsx index ec39867ca85..24dd9ffd38b 100644 --- a/front/src/modules/timesStops/TimesStopsInput.tsx +++ b/front/src/modules/timesStops/TimesStopsInput.tsx @@ -126,11 +126,11 @@ const TimesStopsInput = ({ allWaypoints, startTime, pathSteps }: TimesStopsInput } else { const newVias = updatedRows .filter((row, index) => !isEqual(row, rows[index])) - .map(({ onStopSignal, arrival, departure, ...row }) => ({ + .map(({ shortSlipDistance, onStopSignal, arrival, departure, ...row }) => ({ ...row, arrival: durationSinceStartTime(startTime, arrival), departure: durationSinceStartTime(startTime, departure), - receptionSignal: onStopSignalToReceptionSignal(onStopSignal), + receptionSignal: onStopSignalToReceptionSignal(onStopSignal, shortSlipDistance), })); dispatch(upsertSeveralViasFromSuggestedOP(newVias)); } diff --git a/front/src/modules/timesStops/helpers/utils.ts b/front/src/modules/timesStops/helpers/utils.ts index 0b301130b7e..732a908eab8 100644 --- a/front/src/modules/timesStops/helpers/utils.ts +++ b/front/src/modules/timesStops/helpers/utils.ts @@ -86,13 +86,15 @@ export const formatSuggestedViasToRowVias = ( ? { time: departureTime } : undefined; const { receptionSignal: _opReceptionSignal, ...filteredOp } = op; + const { shortSlipDistance, onStopSignal } = receptionSignalToSignalBooleans(receptionSignal); return { ...filteredOp, isMarginValid, arrival: formattedArrival, departure: formattedDeparture, - onStopSignal: receptionSignalToOnStopSignal(receptionSignal), + onStopSignal, name: name || t('waypoint', { id: filteredOp.opId }), + shortSlipDistance, stopFor, theoreticalMargin, isWaypoint: op.isWaypoint || pathStep !== undefined, @@ -303,26 +305,28 @@ export function calculateStepTimeAndDays( /** Convert onStopSignal boolean to receptionSignal enum */ export function onStopSignalToReceptionSignal( - onStopSignal: boolean | undefined + onStopSignal?: boolean, + shortSlipDistance?: boolean ): ReceptionSignal | undefined { if (isNil(onStopSignal)) { return undefined; } if (onStopSignal === true) { - return 'STOP'; + return shortSlipDistance ? 'SHORT_SLIP_STOP' : 'STOP'; } return 'OPEN'; } /** Convert receptionSignal enum to onStopSignal boolean */ -export function receptionSignalToOnStopSignal( - receptionSignal: ReceptionSignal | undefined -): boolean | undefined { +export function receptionSignalToSignalBooleans(receptionSignal?: ReceptionSignal) { if (isNil(receptionSignal)) { - return undefined; + return { shortSlipDistance: undefined, onStopSignal: undefined }; + } + if (receptionSignal === 'STOP') { + return { shortSlipDistance: false, onStopSignal: true }; } - if (receptionSignal === 'STOP' || receptionSignal === 'SHORT_SLIP_STOP') { - return true; + if (receptionSignal === 'SHORT_SLIP_STOP') { + return { shortSlipDistance: true, onStopSignal: true }; } - return false; + return { shortSlipDistance: false, onStopSignal: false }; } diff --git a/front/src/modules/timesStops/hooks/useTimeStopsColumns.ts b/front/src/modules/timesStops/hooks/useTimeStopsColumns.ts index 20d8fc99c89..c3be22924c9 100644 --- a/front/src/modules/timesStops/hooks/useTimeStopsColumns.ts +++ b/front/src/modules/timesStops/hooks/useTimeStopsColumns.ts @@ -116,6 +116,13 @@ export const useTimeStopsColumns = ( disabled: ({ rowData, rowIndex }) => isOutputTable || (rowIndex !== allWaypoints.length - 1 && !rowData.stopFor), }, + { + ...keyColumn('shortSlipDistance', checkboxColumn as Partial>), + title: t('shortSlipDistance'), + ...fixedWidth(94), + disabled: ({ rowData, rowIndex }) => + isOutputTable || (rowIndex !== allWaypoints.length - 1 && !rowData.onStopSignal), + }, { ...keyColumn( 'theoreticalMargin', diff --git a/front/src/modules/timesStops/types.ts b/front/src/modules/timesStops/types.ts index 52ed2b95c33..afdb10d28c8 100644 --- a/front/src/modules/timesStops/types.ts +++ b/front/src/modules/timesStops/types.ts @@ -19,6 +19,7 @@ export type TimeStopsRow = { departure?: TimeExtraDays; // value asked by user stopFor?: string | null; // value asked by user onStopSignal?: boolean; + shortSlipDistance?: boolean; theoreticalMargin?: string; // value asked by user theoreticalMarginSeconds?: string;