Skip to content

Commit

Permalink
front: fix pathfinding success message persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
Math-R committed Nov 30, 2023
1 parent 9a4e4a3 commit 74dbdee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function ManageTrainSchedule() {
content: (
<div className="osrd-config-item-container-map" data-testid="map">
<span className="floating-itinerary">
<Itinerary />
<Itinerary path={pathFinding} />
</span>
<Map />
</div>
Expand Down
29 changes: 15 additions & 14 deletions front/src/common/Pathfinding/Pathfinding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function init({

interface PathfindingProps {
zoomToFeature: (lngLat: Position, id?: undefined, source?: undefined) => void;
path?: Path;
}

export function getPathfindingQuery({
Expand Down Expand Up @@ -257,7 +258,7 @@ export function getPathfindingQuery({
return null;
}

function Pathfinding({ zoomToFeature }: PathfindingProps) {
function Pathfinding({ zoomToFeature, path }: PathfindingProps) {
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
const [pathfindingRequest, setPathfindingRequest] =
useState<ReturnType<typeof postPathfinding>>();
Expand Down Expand Up @@ -293,7 +294,6 @@ function Pathfinding({ zoomToFeature }: PathfindingProps) {
}
);
const [reloadInfra] = osrdEditoastApi.usePostInfraByIdLoadMutation();

useEffect(() => {
if (reloadCount <= 5 && infra && infra.state === 'TRANSIENT_ERROR') {
setTimeout(() => {
Expand Down Expand Up @@ -518,23 +518,24 @@ function Pathfinding({ zoomToFeature }: PathfindingProps) {
? displayInfraSoftError()
: infra.state === 'ERROR' && displayInfraHardError())}

{isPathFindingActive ? (
{!pathfindingState.error && !pathfindingState.running && path && origin && destination && (
<div className="content pathfinding-done">
<span className="lead">
<GoCheckCircle />
</span>
<span className="flex-grow-1">{t('pathfindingDone')}</span>
<small className="text-secondary">
{geojson?.length && formatKmValue(geojson?.length / 1000, 3)}
</small>
</div>
)}

{!path && isPathFindingActive ? (
<div className={`content pathfinding-none ${infra && infra.state !== 'CACHED' && 'mt-2'}`}>
{t('pathfindingNoState')}
</div>
) : (
<>
{pathfindingState.done && !pathfindingState.error && (
<div className="content pathfinding-done">
<span className="lead">
<GoCheckCircle />
</span>
<span className="flex-grow-1">{t('pathfindingDone')}</span>
<small className="text-secondary">
{geojson?.length && formatKmValue(geojson?.length / 1000, 3)}
</small>
</div>
)}
{pathfindingState.error && (
<div
className={`content pathfinding-error ${infra && infra.state !== 'CACHED' && 'mt-2'}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import { getMap } from 'reducers/map/selectors';
import Pathfinding from 'common/Pathfinding/Pathfinding';
import TypeAndPath from 'common/Pathfinding/TypeAndPath';
import { GoRocket } from 'react-icons/go';
import { Path } from 'common/api/osrdEditoastApi';

function Itinerary() {
type ItineraryProps = {
path?: Path;
};

function Itinerary({ path }: ItineraryProps) {
const origin = useSelector(getOrigin);
const destination = useSelector(getDestination);
const vias = useSelector(getVias);
Expand Down Expand Up @@ -93,7 +98,7 @@ function Itinerary() {
return (
<div className="osrd-config-item">
<div className="mb-2 d-flex">
<Pathfinding zoomToFeature={zoomToFeature} />
<Pathfinding zoomToFeature={zoomToFeature} path={path} />
<button
type="button"
className="btn btn-sm btn-only-icon btn-white px-3 ml-2"
Expand Down

0 comments on commit 74dbdee

Please sign in to comment.