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: fix pathfinding success message persistence #5927

Merged
merged 1 commit into from
Nov 30, 2023
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 @@ -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