Skip to content

Commit

Permalink
front: fix update pathfinding when changing rolling stock
Browse files Browse the repository at this point in the history
  - As the hook usePathfinding were only in the Itinerary tab, the
    pathfinding was not updated when rolling stock was changed

Signed-off-by: Uriel Sautron <uriel.sautron@gmail.com>
  • Loading branch information
Uriel-Sautron committed Nov 6, 2024
1 parent c3d0409 commit 8b4abd1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Tabs from 'common/Tabs';
import IncompatibleConstraints from 'modules/pathfinding/components/IncompatibleConstraints';
import Itinerary from 'modules/pathfinding/components/Itinerary/Itinerary';
import getPathVoltages from 'modules/pathfinding/helpers/getPathVoltages';
import { usePathfinding } from 'modules/pathfinding/hooks/usePathfinding';
import { upsertPathStepsInOPs } from 'modules/pathfinding/utils';
import PowerRestrictionsSelector from 'modules/powerRestriction/components/PowerRestrictionsSelector';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
Expand Down Expand Up @@ -44,6 +45,8 @@ const ManageTrainSchedule = ({ trainIdToEdit }: ManageTrainScheduleProps) => {

const [pathProperties, setPathProperties] = useState<ManageTrainSchedulePathProperties>();

const { pathfindingState, infraInfos } = usePathfinding(setPathProperties, pathProperties);

const { speedLimitByTag, speedLimitsByTags, dispatchUpdateSpeedLimitByTag } =
useStoreDataForSpeedLimitByTagSelector();

Expand Down Expand Up @@ -117,7 +120,12 @@ const ManageTrainSchedule = ({ trainIdToEdit }: ManageTrainScheduleProps) => {
content: (
<div className="osrd-config-item-container-map" data-testid="map">
<div className="floating-itinerary">
<Itinerary pathProperties={pathProperties} setPathProperties={setPathProperties} />
<Itinerary
pathProperties={pathProperties}
setPathProperties={setPathProperties}
pathfindingState={pathfindingState}
infraInfos={infraInfos}
/>
</div>
<Map pathProperties={pathProperties}>
<IncompatibleConstraints pathProperties={pathProperties} />
Expand Down
15 changes: 14 additions & 1 deletion front/src/modules/pathfinding/components/Itinerary/Itinerary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import type { InfraWithState } from 'common/api/osrdEditoastApi';
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
import { computeBBoxViewport } from 'common/Map/WarpedMap/core/helpers';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import Tipped from 'common/Tipped';
import Pathfinding from 'modules/pathfinding/components/Pathfinding/Pathfinding';
import TypeAndPath from 'modules/pathfinding/components/Pathfinding/TypeAndPath';
import type { PathfindingState } from 'modules/pathfinding/types';
import { setWarning } from 'reducers/main';
import { updateViewport } from 'reducers/map';
import { getMap } from 'reducers/map/selectors';
Expand All @@ -29,12 +31,19 @@ type ItineraryProps = {
pathProperties?: ManageTrainSchedulePathProperties;
setPathProperties: (pathProperties?: ManageTrainSchedulePathProperties) => void;
shouldManageStopDuration?: boolean;
pathfindingState: PathfindingState;
infraInfos: {
infra: InfraWithState | undefined;
reloadCount: number;
};
};

const Itinerary = ({
pathProperties,
setPathProperties,
shouldManageStopDuration,
pathfindingState,
infraInfos,
}: ItineraryProps) => {
const { getPathSteps, getOrigin, getDestination, getPowerRestriction } = useOsrdConfSelectors();
const { updatePathSteps } = useOsrdConfActions();
Expand Down Expand Up @@ -98,7 +107,11 @@ const Itinerary = ({
return (
<div className="osrd-config-item">
<div className="mb-2 d-flex">
<Pathfinding pathProperties={pathProperties} setPathProperties={setPathProperties} />
<Pathfinding
pathProperties={pathProperties}
pathfindingState={pathfindingState}
infraInfos={infraInfos}
/>
<button
type="button"
className="btn btn-sm btn-only-icon btn-white px-3 ml-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@ import { useSelector } from 'react-redux';
import InfraLoadingState from 'applications/operationalStudies/components/Scenario/InfraLoadingState';
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import infraLogo from 'assets/pictures/components/tracks.svg';
import type { InfraWithState } from 'common/api/osrdEditoastApi';
import { Spinner } from 'common/Loaders';
import { useOsrdConfSelectors } from 'common/osrdContext';
import { usePathfinding } from 'modules/pathfinding/hooks/usePathfinding';
import type { PathfindingState } from 'modules/pathfinding/types';
import { useStoreDataForRollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector';
import { conditionalStringConcat, formatKmValue } from 'utils/strings';

import { InfraHardError, InfraSoftError } from './InfraError';

type PathfindingProps = {
pathProperties?: ManageTrainSchedulePathProperties;
setPathProperties: (pathProperties?: ManageTrainSchedulePathProperties) => void;
pathfindingState: PathfindingState;
infraInfos: {
infra: InfraWithState | undefined;
reloadCount: number;
};
};

const Pathfinding = ({ pathProperties, setPathProperties }: PathfindingProps) => {
const Pathfinding = ({ pathProperties, pathfindingState, infraInfos }: PathfindingProps) => {
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);

const { getOrigin, getDestination } = useOsrdConfSelectors();
const origin = useSelector(getOrigin, isEqual);
const destination = useSelector(getDestination, isEqual);
const { rollingStock } = useStoreDataForRollingStockSelector();

const {
pathfindingState,
infraInfos: { infra, reloadCount },
} = usePathfinding(setPathProperties, pathProperties);
const { infra, reloadCount } = infraInfos;

const missingElements = conditionalStringConcat([
[!origin, t('origin')],
Expand Down
4 changes: 3 additions & 1 deletion front/src/modules/pathfinding/hooks/usePathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ export const usePathfinding = (
matchPathStepAndOp(step, suggestedOp)
);

const theoreticalMargin = i === 0 ? '0%' : step.theoreticalMargin;
const theoreticalMargin =
i === 0 ? step.theoreticalMargin || '0%' : step.theoreticalMargin;

const stopFor = i === pathSteps.length - 1 && !step.stopFor ? '0' : step.stopFor;
const stopType =
i === pathSteps.length - 1 && !step.stopFor ? undefined : step.stopType;
Expand Down

0 comments on commit 8b4abd1

Please sign in to comment.