Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: simplify usePathfinding #9901

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const useSetupItineraryForTrainUpdate = (
const pathSteps = itinerary?.pathSteps;

if (pathSteps) {
dispatch(updatePathSteps({ pathSteps }));
dispatch(updatePathSteps(pathSteps));
}

if (itinerary?.pathProperties) {
Expand Down
2 changes: 0 additions & 2 deletions front/src/applications/stdcm/hooks/useStaticPathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const useStaticPathfinding = (infra?: InfraWithState) => {
const payload = getPathfindingQuery({
infraId: infra.id,
rollingStock,
origin: pathStepsLocations.at(0) || null,
destination: pathStepsLocations.at(-1) || null,
pathSteps: pathStepsLocations,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Itinerary = ({
shouldManageStopDuration,
}: ItineraryProps) => {
const { getPathSteps, getOrigin, getDestination, getPowerRestriction } = useOsrdConfSelectors();
const { updatePathSteps } = useOsrdConfActions();
const { reverseItinerary, deleteItinerary } = useOsrdConfActions();
const origin = useSelector(getOrigin);
const destination = useSelector(getDestination);
const pathSteps = useSelector(getPathSteps);
Expand Down Expand Up @@ -80,15 +80,14 @@ const Itinerary = ({
};

const inverseOD = () => {
const revertedPathSteps = [...pathSteps].reverse();
notifyRestrictionResetWarning();
dispatch(updatePathSteps({ pathSteps: revertedPathSteps, resetPowerRestrictions: true }));
dispatch(reverseItinerary());
};

const resetPathfinding = () => {
setPathProperties(undefined);
notifyRestrictionResetWarning();
dispatch(updatePathSteps({ pathSteps: [null, null], resetPowerRestrictions: true }));
dispatch(deleteItinerary());
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { useCallback } from 'react';

import { Dash, Plus, Trash } from '@osrd-project/ui-icons';
import cx from 'classnames';
import { compact } from 'lodash';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

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,12 +19,11 @@ type ModalSuggestedViasProps = {
};

const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => {
const { updatePathSteps, upsertViaFromSuggestedOP, clearVias } = useOsrdConfActions();
const { getVias, getDestination, getPathSteps } = useOsrdConfSelectors();
const { upsertViaFromSuggestedOP, clearVias, removeVia } = useOsrdConfActions();
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 @@ -34,14 +32,7 @@ const ModalSuggestedVias = ({ suggestedVias }: ModalSuggestedViasProps) => {
[destination]
);

const removeViaFromPath = (op: SuggestedOP) => {
const updatedPathSteps = compact(pathSteps).filter((step) => !matchPathStepAndOp(step, op));
dispatch(
updatePathSteps({
pathSteps: updatedPathSteps,
})
);
};
const removeViaFromPath = (op: SuggestedOP) => dispatch(removeVia(op));

const formatOP = (op: SuggestedOP, idx: number, idxTrueVia: number) => {
const isInVias = isVia(vias, op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const TypeAndPath = ({ setDisplayTypeAndPath }: TypeAndPathProps) => {
const { getRollingStockID } = useOsrdConfSelectors();
const rollingStockId = useSelector(getRollingStockID);

const { updatePathSteps } = useOsrdConfActions();
const { replaceItinerary } = useOsrdConfActions();

const [searchResults, setSearchResults] = useState<SearchResultItemOperationalPoint[]>([]);
const [searchState, setSearch] = useState('');
Expand Down Expand Up @@ -172,7 +172,7 @@ const TypeAndPath = ({ setDisplayTypeAndPath }: TypeAndPathProps) => {
id: nextId(),
}));

dispatch(updatePathSteps({ pathSteps }));
dispatch(replaceItinerary(pathSteps));
setDisplayTypeAndPath(false);
}
};
Expand Down
Loading
Loading