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

lmr: add messages during pathfinding and when its done #10282

Merged
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
4 changes: 4 additions & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
},
"noCorrespondingResults": "No results matching your search.",
"notificationTitle": "Phase 1: from D-7 to D-1 5pm, on the Perrigny-Miramas axis.",
"pathfindingStatus": {
"calculating": "Validating path...",
"success": "The requested path is valid."
},
"pleaseWait": "Please wait…",
"simulation": {
"calculatingSimulation": "Calculation in progress...",
Expand Down
4 changes: 4 additions & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
},
"noCorrespondingResults": "Aucun résultat ne correspond à votre recherche.",
"notificationTitle": "Phase 1 : de J-7 à J-1 17h, sur l’axe Perrigny—Miramas.",
"pathfindingStatus": {
"calculating": "Validation de l'itinéraire en cours...",
"success": "L'itinéraire demandé est valide."
},
"pleaseWait": "Veuillez patientez…",
"simulation": {
"calculatingSimulation": "Calcul en cours...",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';

import { Button } from '@osrd-project/ui-core';
import cx from 'classnames';
Expand Down Expand Up @@ -90,8 +90,12 @@ const StdcmConfig = ({
const totalLength = useSelector(getTotalLength);
const maxSpeed = useSelector(getMaxSpeed);

const pathfinding = useStaticPathfinding(infra);
const [showMessage, setShowMessage] = useState(false);

const { pathfinding, isPathFindingLoading } = useStaticPathfinding(infra);

const formRef = useRef<HTMLDivElement>(null);
const pathfindingBannerRef = useRef<HTMLDivElement>(null);

const [formErrors, setFormErrors] = useState<StdcmConfigErrors>();

Expand Down Expand Up @@ -145,6 +149,13 @@ const StdcmConfig = ({
);
};

const getStatusMessage = () => {
if (isPathFindingLoading) {
return t('pathfindingStatus.calculating');
}
return t('pathfindingStatus.success');
};

useEffect(() => {
if (pathfinding) {
const formErrorsStatus = checkStdcmConfigErrors(
Expand Down Expand Up @@ -177,6 +188,31 @@ const StdcmConfig = ({
}
}, []);

useEffect(() => {
if (isPathFindingLoading) {
setShowMessage(true);
}

if (pathfinding?.status === 'failure') {
setShowMessage(false);
}
}, [isPathFindingLoading, pathfinding?.status]);

useLayoutEffect(() => {
const handleAnimationEnd = () => {
setShowMessage(false);
};

if (!showMessage || formErrors) {
return undefined;
}
pathfindingBannerRef.current!.addEventListener('animationend', handleAnimationEnd);

return () => {
pathfindingBannerRef.current?.removeEventListener('animationend', handleAnimationEnd);
};
}, [showMessage, formErrors]);

return (
<div className="stdcm__body">
{isDebugMode && (
Expand Down Expand Up @@ -238,6 +274,20 @@ const StdcmConfig = ({
)}
</div>

{!formErrors && showMessage && (
<div className="simulation-status-banner">
<div className="banner-content">
<div
ref={pathfindingBannerRef}
className={cx('pathfinding-status', {
'pathfinding-status-success': pathfinding?.status === 'success',
})}
>
{getStatusMessage()}
</div>
</div>
</div>
)}
{isPending && (
<StdcmLoader
cancelStdcmRequest={cancelStdcmRequest}
Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/stdcm/hooks/useStaticPathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const useStaticPathfinding = (infra?: InfraWithState) => {

const [pathfinding, setPathfinding] = useState<PathfindingResult>();

const [postPathfindingBlocks] =
const [postPathfindingBlocks, { isFetching }] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();

// When pathSteps changed
Expand Down Expand Up @@ -84,7 +84,7 @@ const useStaticPathfinding = (infra?: InfraWithState) => {
[pathfinding, pathProperties]
);

return result;
return { pathfinding: result, isPathFindingLoading: isFetching };
};

export default useStaticPathfinding;
1 change: 1 addition & 0 deletions front/src/styles/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ $colors: (
'primary80': #1f0f96,
'primary90': #180f47,
'selection20': #fff2b3,
'success5': #e6f7ee,
'success30': #3cca80,
'success60': #0b723c,
'warning5': #fdf5e1,
Expand Down
42 changes: 42 additions & 0 deletions front/src/styles/scss/applications/stdcm/_home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
.banner-content {
padding: 0 0 16px 378px;
background: linear-gradient(180deg, rgba(239, 243, 245) 40px, rgba(233, 239, 242) 40px);
&:has(.pathfinding-status) {
padding: 0;
}
.status {
width: 466px;
display: flex;
Expand Down Expand Up @@ -294,6 +297,45 @@
line-height: 24px;
text-align: center;
}

.pathfinding-status {
left: -8px;
position: absolute;
bottom: -95px;
width: calc(100% + 16px);
display: flex;
justify-content: center;
line-height: 24px;
border-radius: 8px;
color: var(--info60);
background-color: var(--info5);
padding-block: 22px 26px;
box-shadow:
0 0 0 4px rgba(255, 255, 255, 1) inset,
0 0 0 5px rgb(112, 193, 229) inset,
0 3px 7px -3px rgba(28, 28, 217, 0.4);
&-success {
color: var(--success60);
background-color: var(--success5);
opacity: 0;
box-shadow:
0 0 0 4px rgba(255, 255, 255, 1) inset,
0 0 0 5px rgb(60, 202, 128) inset,
0 3px 7px -3px rgba(11, 114, 60, 0.4);
animation: pathfinding-success 2.7s;
}
}
@keyframes pathfinding-success {
0% {
opacity: 1;
}
74% {
opacity: 1;
}
100% {
opacity: 0;
}
}
}
}
}
Loading