Skip to content

Commit

Permalink
fixup! front: reorganize actions related to pathSteps
Browse files Browse the repository at this point in the history
  • Loading branch information
clarani committed Dec 2, 2024
1 parent c0fa560 commit 6115d6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions front/src/reducers/osrdconf/osrdConfCommon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -87,7 +88,7 @@ interface CommonConfReducers<S extends OsrdConfState> extends InfraStateReducers
reducer: CaseReducer<S, PayloadAction<S['pathSteps']>>;
prepare: PrepareAction<S['pathSteps']>;
};
['removeVia']: CaseReducer<S, PayloadAction<string>>;
['removeVia']: CaseReducer<S, PayloadAction<SuggestedOP>>;
['upsertViaFromSuggestedOP']: CaseReducer<S, PayloadAction<SuggestedOP>>;
['upsertSeveralViasFromSuggestedOP']: CaseReducer<S, PayloadAction<SuggestedOP[]>>;
['updateRollingStockComfort']: CaseReducer<S, PayloadAction<S['rollingStockComfort']>>;
Expand Down Expand Up @@ -198,9 +199,9 @@ export function buildCommonConfReducers<S extends OsrdConfState>(): CommonConfRe
state.powerRestriction = [];
},
// Use this action in the suggested ops list, not the via list
removeVia(state: Draft<S>, action: PayloadAction<string>) {
removeVia(state: Draft<S>, action: PayloadAction<SuggestedOP>) {
// 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
Expand Down

0 comments on commit 6115d6a

Please sign in to comment.