diff --git a/front/src/modules/pathfinding/components/Itinerary/ModalSuggestedVias.tsx b/front/src/modules/pathfinding/components/Itinerary/ModalSuggestedVias.tsx index c4a864a8735..bf2b89955f9 100644 --- a/front/src/modules/pathfinding/components/Itinerary/ModalSuggestedVias.tsx +++ b/front/src/modules/pathfinding/components/Itinerary/ModalSuggestedVias.tsx @@ -9,7 +9,7 @@ import ModalBodySNCF from 'common/BootstrapSNCF/ModalSNCF/ModalBodySNCF'; import ModalFooterSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalFooterSNCF'; import ModalHeaderSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalHeaderSNCF'; import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext'; -import { isVia, matchPathStepAndOp } from 'modules/pathfinding/utils'; +import { isVia } from 'modules/pathfinding/utils'; import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types'; import { useAppDispatch } from 'store'; import { formatUicToCi } from 'utils/strings'; @@ -20,11 +20,10 @@ type ModalSuggestedViasProps = { const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => { const { upsertViaFromSuggestedOP, clearVias, removeVia } = useOsrdConfActions(); - const { getVias, getDestination, getPathSteps } = useOsrdConfSelectors(); + const { getVias, getDestination } = useOsrdConfSelectors(); const dispatch = useAppDispatch(); const vias = useSelector(getVias()); const destination = useSelector(getDestination); - const pathSteps = useSelector(getPathSteps); const { t } = useTranslation('operationalStudies/manageTrainSchedule'); const isOriginOrDestination = useCallback( @@ -33,12 +32,7 @@ const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => { [destination] ); - const removeViaFromPath = (op: SuggestedOP) => { - const pathStepToRemove = pathSteps.find((step) => step && matchPathStepAndOp(step, op)); - if (pathStepToRemove) { - dispatch(removeVia(pathStepToRemove.id)); - } - }; + const removeViaFromPath = (op: SuggestedOP) => dispatch(removeVia(op)); const formatOP = (op: SuggestedOP, idx: number, idxTrueVia: number) => { const isInVias = isVia(vias, op); diff --git a/front/src/reducers/osrdconf/osrdConfCommon/index.ts b/front/src/reducers/osrdconf/osrdConfCommon/index.ts index 43052873bb0..fbd803a6eba 100644 --- a/front/src/reducers/osrdconf/osrdConfCommon/index.ts +++ b/front/src/reducers/osrdconf/osrdConfCommon/index.ts @@ -22,6 +22,7 @@ import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors'; import type { OsrdConfState, PathStep } from 'reducers/osrdconf/types'; import { removeElementAtIndex } from 'utils/array'; import type { ArrayElement } from 'utils/types'; +import { matchPathStepAndOp } from 'modules/pathfinding/utils'; export const defaultCommonConf: OsrdConfState = { constraintDistribution: 'MARECO', @@ -87,7 +88,7 @@ interface CommonConfReducers extends InfraStateReducers reducer: CaseReducer>; prepare: PrepareAction; }; - ['removeVia']: CaseReducer>; + ['removeVia']: CaseReducer>; ['upsertViaFromSuggestedOP']: CaseReducer>; ['upsertSeveralViasFromSuggestedOP']: CaseReducer>; ['updateRollingStockComfort']: CaseReducer>; @@ -198,9 +199,9 @@ export function buildCommonConfReducers(): CommonConfRe state.powerRestriction = []; }, // Use this action in the suggested ops list, not the via list - removeVia(state: Draft, action: PayloadAction) { + removeVia(state: Draft, action: PayloadAction) { // Index takes count of the origin in the array - state.pathSteps = state.pathSteps.filter((step) => !step || step.id !== action.payload); + state.pathSteps = state.pathSteps.filter((step) => !step || matchPathStepAndOp(step, action.payload)); state.powerRestriction = []; }, // Use this action in the via list, not the suggested op list