Skip to content

Commit 6115d6a

Browse files
committed
fixup! front: reorganize actions related to pathSteps
1 parent c0fa560 commit 6115d6a

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

front/src/modules/pathfinding/components/Itinerary/ModalSuggestedVias.tsx

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ModalBodySNCF from 'common/BootstrapSNCF/ModalSNCF/ModalBodySNCF';
99
import ModalFooterSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalFooterSNCF';
1010
import ModalHeaderSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalHeaderSNCF';
1111
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
12-
import { isVia, matchPathStepAndOp } from 'modules/pathfinding/utils';
12+
import { isVia } from 'modules/pathfinding/utils';
1313
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
1414
import { useAppDispatch } from 'store';
1515
import { formatUicToCi } from 'utils/strings';
@@ -20,11 +20,10 @@ type ModalSuggestedViasProps = {
2020

2121
const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => {
2222
const { upsertViaFromSuggestedOP, clearVias, removeVia } = useOsrdConfActions();
23-
const { getVias, getDestination, getPathSteps } = useOsrdConfSelectors();
23+
const { getVias, getDestination } = useOsrdConfSelectors();
2424
const dispatch = useAppDispatch();
2525
const vias = useSelector(getVias());
2626
const destination = useSelector(getDestination);
27-
const pathSteps = useSelector(getPathSteps);
2827
const { t } = useTranslation('operationalStudies/manageTrainSchedule');
2928

3029
const isOriginOrDestination = useCallback(
@@ -33,12 +32,7 @@ const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => {
3332
[destination]
3433
);
3534

36-
const removeViaFromPath = (op: SuggestedOP) => {
37-
const pathStepToRemove = pathSteps.find((step) => step && matchPathStepAndOp(step, op));
38-
if (pathStepToRemove) {
39-
dispatch(removeVia(pathStepToRemove.id));
40-
}
41-
};
35+
const removeViaFromPath = (op: SuggestedOP) => dispatch(removeVia(op));
4236

4337
const formatOP = (op: SuggestedOP, idx: number, idxTrueVia: number) => {
4438
const isInVias = isVia(vias, op);

front/src/reducers/osrdconf/osrdConfCommon/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors';
2222
import type { OsrdConfState, PathStep } from 'reducers/osrdconf/types';
2323
import { removeElementAtIndex } from 'utils/array';
2424
import type { ArrayElement } from 'utils/types';
25+
import { matchPathStepAndOp } from 'modules/pathfinding/utils';
2526

2627
export const defaultCommonConf: OsrdConfState = {
2728
constraintDistribution: 'MARECO',
@@ -87,7 +88,7 @@ interface CommonConfReducers<S extends OsrdConfState> extends InfraStateReducers
8788
reducer: CaseReducer<S, PayloadAction<S['pathSteps']>>;
8889
prepare: PrepareAction<S['pathSteps']>;
8990
};
90-
['removeVia']: CaseReducer<S, PayloadAction<string>>;
91+
['removeVia']: CaseReducer<S, PayloadAction<SuggestedOP>>;
9192
['upsertViaFromSuggestedOP']: CaseReducer<S, PayloadAction<SuggestedOP>>;
9293
['upsertSeveralViasFromSuggestedOP']: CaseReducer<S, PayloadAction<SuggestedOP[]>>;
9394
['updateRollingStockComfort']: CaseReducer<S, PayloadAction<S['rollingStockComfort']>>;
@@ -198,9 +199,9 @@ export function buildCommonConfReducers<S extends OsrdConfState>(): CommonConfRe
198199
state.powerRestriction = [];
199200
},
200201
// Use this action in the suggested ops list, not the via list
201-
removeVia(state: Draft<S>, action: PayloadAction<string>) {
202+
removeVia(state: Draft<S>, action: PayloadAction<SuggestedOP>) {
202203
// Index takes count of the origin in the array
203-
state.pathSteps = state.pathSteps.filter((step) => !step || step.id !== action.payload);
204+
state.pathSteps = state.pathSteps.filter((step) => !step || matchPathStepAndOp(step, action.payload));
204205
state.powerRestriction = [];
205206
},
206207
// Use this action in the via list, not the suggested op list

0 commit comments

Comments
 (0)