From 32d4a79461b2a6dce827c87701e33271ea30ea14 Mon Sep 17 00:00:00 2001 From: Clara Ni Date: Tue, 24 Dec 2024 14:52:48 +0100 Subject: [PATCH] front: setting power restrictions do not remove PathSteps When manipulating power restrictions, the pathSteps without any constraints (stop, arrival time or margin) were cleaned. This was the expected behaviour before, because we could not have pathSteps without constraints. As the expected behaviour has changed (we now authorize pathSteps without constraints), the pathSteps created from the power restrictions selector have a new flag and may be cleaned if they are not linked anymore to a power restrictions and have no constraints. The other pathSteps will not be cleaned. Signed-off-by: Clara Ni --- .../modules/powerRestriction/helpers/createPathStep.ts | 2 ++ .../src/reducers/osrdconf/operationalStudiesConf/utils.ts | 2 +- front/src/reducers/osrdconf/types.ts | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/front/src/modules/powerRestriction/helpers/createPathStep.ts b/front/src/modules/powerRestriction/helpers/createPathStep.ts index bced6fd396f..3a0f2b7ea0a 100644 --- a/front/src/modules/powerRestriction/helpers/createPathStep.ts +++ b/front/src/modules/powerRestriction/helpers/createPathStep.ts @@ -75,6 +75,7 @@ const createPathStep = ( ...trackOffset, // TODO: we should return the offset in mm once it is stored in mm in the store offset: mmToM(trackOffset.offset), + isFromPowerRestriction: true, }; }; @@ -124,6 +125,7 @@ export const createCutAtPathStep = ( id: nextId(), positionOnPath: cutAtPosition, coordinates: coordinatesAtCut, + isFromPowerRestriction: true, ...trackOffset, // TODO: we should return the offset in mm once it is stored in mm in the store offset: mmToM(trackOffset.offset), diff --git a/front/src/reducers/osrdconf/operationalStudiesConf/utils.ts b/front/src/reducers/osrdconf/operationalStudiesConf/utils.ts index 1566eeb3f1f..c9e025a5902 100644 --- a/front/src/reducers/osrdconf/operationalStudiesConf/utils.ts +++ b/front/src/reducers/osrdconf/operationalStudiesConf/utils.ts @@ -95,7 +95,7 @@ export const cleanPathSteps = ( powerRestrictions: PowerRestriction[] ): PathStep[] => pathSteps.reduce((acc, pathStep, index) => { - if (index === 0 || index === pathSteps.length - 1) { + if (index === 0 || index === pathSteps.length - 1 || !pathStep.isFromPowerRestriction) { acc.push(pathStep); return acc; } diff --git a/front/src/reducers/osrdconf/types.ts b/front/src/reducers/osrdconf/types.ts index b65c347f8a8..7e64bd2ed66 100644 --- a/front/src/reducers/osrdconf/types.ts +++ b/front/src/reducers/osrdconf/types.ts @@ -89,6 +89,14 @@ export type PathStep = PathItemLocation & { trackNumber: number; }; isInvalid?: boolean; + /** Flag specifying whether the pathStep was created from the power restriction selector or not + * + * If true, the pathStep might be cleaned if its power restriction is removed (except if it has time, stop or margin constraints) + * + * This flag will only work if the user has not saved its change. Once the change is saved, the flag will be removed and the pathStep + * will become permanent. + */ + isFromPowerRestriction?: boolean; }; export type StdcmPathStep = {