diff --git a/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts b/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts
index b3aa7edccc3..da8989f3aab 100644
--- a/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts
+++ b/front/src/modules/simulationResult/components/SpaceTimeChart/useGetProjectedTrainOperationalPoints.ts
@@ -1,6 +1,8 @@
import { useEffect, useState } from 'react';
+import { omit } from 'lodash';
import { useTranslation } from 'react-i18next';
+import { useSelector } from 'react-redux';
import { upsertMapWaypointsInOperationalPoints } from 'applications/operationalStudies/helpers/upsertMapWaypointsInOperationalPoints';
import { STDCM_TRAIN_ID } from 'applications/stdcm/consts';
@@ -9,6 +11,7 @@ import {
type PathProperties,
type TrainScheduleResult,
} from 'common/api/osrdEditoastApi';
+import { useOsrdConfSelectors } from 'common/osrdContext';
const useGetProjectedTrainOperationalPoints = (
trainScheduleUsedForProjection?: TrainScheduleResult,
@@ -16,9 +19,14 @@ const useGetProjectedTrainOperationalPoints = (
infraId?: number
) => {
const { t } = useTranslation('simulation');
+ const { getTimetableID } = useOsrdConfSelectors();
+ const timetableId = useSelector(getTimetableID);
+
const [operationalPoints, setOperationalPoints] = useState<
NonNullable
>([]);
+ const [filteredOperationalPoints, setFilteredOperationalPoints] =
+ useState>(operationalPoints);
const { data: pathfindingResult } = osrdEditoastApi.endpoints.getTrainScheduleByIdPath.useQuery(
{
@@ -50,18 +58,32 @@ const useGetProjectedTrainOperationalPoints = (
operational_points!,
t
);
- const operationalPointsWithUniqueIds = operationalPointsWithAllWaypoints.map((op, i) => ({
+ let operationalPointsWithUniqueIds = operationalPointsWithAllWaypoints.map((op, i) => ({
...op,
id: `${op.id}-${op.position}-${i}`,
}));
setOperationalPoints(operationalPointsWithUniqueIds);
+
+ // Check if there are saved manchettes in localStorage for the current timetable and path
+ const simplifiedPath = trainScheduleUsedForProjection.path.map((waypoint) =>
+ omit(waypoint, ['id', 'deleted'])
+ );
+ const stringifiedSavedWaypoints = localStorage.getItem(
+ `${timetableId}-${JSON.stringify(simplifiedPath)}`
+ );
+ if (stringifiedSavedWaypoints) {
+ operationalPointsWithUniqueIds = JSON.parse(stringifiedSavedWaypoints) as NonNullable<
+ PathProperties['operational_points']
+ >;
+ }
+ setFilteredOperationalPoints(operationalPointsWithUniqueIds);
}
};
getOperationalPoints();
}, [pathfindingResult, infraId, t]);
- return operationalPoints;
+ return { operationalPoints, filteredOperationalPoints, setFilteredOperationalPoints };
};
export default useGetProjectedTrainOperationalPoints;
diff --git a/front/src/modules/simulationResult/types.ts b/front/src/modules/simulationResult/types.ts
index 4f62028d5f4..205869ad5f2 100644
--- a/front/src/modules/simulationResult/types.ts
+++ b/front/src/modules/simulationResult/types.ts
@@ -12,6 +12,7 @@ import type {
PathProperties,
PathfindingResultSuccess,
RollingStockWithLiveries,
+ TrainScheduleBase,
TrainScheduleResult,
} from 'common/api/osrdEditoastApi';
import type { ArrayElement } from 'utils/types';
@@ -33,3 +34,11 @@ export type ProjectionData = {
geometry: PathProperties['geometry'];
allTrainsProjected: boolean;
};
+
+export type WaypointsModalData = {
+ filteredOperationalPoints: NonNullable;
+ setFilteredOperationalPoints: (
+ waypoints: NonNullable
+ ) => void;
+ projectedTrainPath: TrainScheduleBase['path'];
+};
diff --git a/front/src/modules/study/components/AddOrEditStudyModal.tsx b/front/src/modules/study/components/AddOrEditStudyModal.tsx
index fab3d2b24a4..73df111d20c 100644
--- a/front/src/modules/study/components/AddOrEditStudyModal.tsx
+++ b/front/src/modules/study/components/AddOrEditStudyModal.tsx
@@ -10,7 +10,7 @@ import { useNavigate, useParams } from 'react-router-dom';
import { STUDY_STATES, STUDY_TYPES, studyStates } from 'applications/operationalStudies/consts';
import studyLogo from 'assets/pictures/views/studies.svg';
import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
-import type { StudyCreateForm } from 'common/api/osrdEditoastApi';
+import type { ScenarioWithDetails, StudyCreateForm } from 'common/api/osrdEditoastApi';
import ChipsSNCF from 'common/BootstrapSNCF/ChipsSNCF';
import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import { ConfirmModal } from 'common/BootstrapSNCF/ModalSNCF';
@@ -21,6 +21,7 @@ import { ModalContext } from 'common/BootstrapSNCF/ModalSNCF/ModalProvider';
import SelectImprovedSNCF from 'common/BootstrapSNCF/SelectImprovedSNCF';
import TextareaSNCF from 'common/BootstrapSNCF/TextareaSNCF';
import { useOsrdConfActions } from 'common/osrdContext';
+import { cleanScenarioLocalStorage } from 'modules/scenario/helpers/utils';
import { checkStudyFields, createSelectOptions } from 'modules/study/utils';
import { setFailure, setSuccess } from 'reducers/main';
import { useAppDispatch } from 'store';
@@ -34,9 +35,10 @@ export interface StudyForm extends StudyCreateForm {
id?: number;
}
-type Props = {
+type AddOrEditStudyModalProps = {
editionMode?: boolean;
study?: StudyForm;
+ scenarios?: ScenarioWithDetails[];
};
type StudyParams = {
@@ -57,7 +59,7 @@ const emptyStudy: StudyForm = {
tags: [],
};
-export default function AddOrEditStudyModal({ editionMode, study }: Props) {
+const AddOrEditStudyModal = ({ editionMode, study, scenarios }: AddOrEditStudyModalProps) => {
const { t } = useTranslation(['operationalStudies/study', 'translation']);
const { closeModal, isOpen } = useContext(ModalContext);
const [currentStudy, setCurrentStudy] = useState(study || emptyStudy);
@@ -151,6 +153,13 @@ export default function AddOrEditStudyModal({ editionMode, study }: Props) {
})
.unwrap()
.then(() => {
+ if (scenarios) {
+ // For each scenario in the study, clean the local storage if a manchette is saved
+ scenarios.forEach((scenario) => {
+ cleanScenarioLocalStorage(scenario.timetable_id);
+ });
+ }
+
dispatch(
setSuccess({
title: t('studyDeleted'),
@@ -492,4 +501,6 @@ export default function AddOrEditStudyModal({ editionMode, study }: Props) {
);
-}
+};
+
+export default AddOrEditStudyModal;