Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4e6068d

Browse files
Caracol3RomainValls
authored andcommittedJan 17, 2025··
lmr: add messages during pathfinding and when its done
- fix padding, add translations - refacto using isfetching from rtk - add transition in css to avoid two settimeout - add eventlistener for the animation Signed-off-by: Mathieu <mathieu.coulibaly@sncf.fr> Co-authored-by: romainvalls <romain.valls95@gmail.com>
1 parent ec18e08 commit 4e6068d

File tree

6 files changed

+113
-4
lines changed

6 files changed

+113
-4
lines changed
 

‎front/public/locales/en/stdcm.json

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
},
5151
"noCorrespondingResults": "No results matching your search.",
5252
"notificationTitle": "Phase 1: from D-7 to D-1 5pm, on the Perrigny-Miramas axis.",
53+
"pathfindingStatus": {
54+
"calculating": "Validating path...",
55+
"success": "The requested path is valid."
56+
},
5357
"pleaseWait": "Please wait…",
5458
"simulation": {
5559
"calculatingSimulation": "Calculation in progress...",

‎front/public/locales/fr/stdcm.json

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
},
5151
"noCorrespondingResults": "Aucun résultat ne correspond à votre recherche.",
5252
"notificationTitle": "Phase 1 : de J-7 à J-1 17h, sur l’axe Perrigny—Miramas.",
53+
"pathfindingStatus": {
54+
"calculating": "Validation de l'itinéraire en cours...",
55+
"success": "L'itinéraire demandé est valide."
56+
},
5357
"pleaseWait": "Veuillez patientez…",
5458
"simulation": {
5559
"calculatingSimulation": "Calcul en cours...",

‎front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useMemo, useRef, useState } from 'react';
1+
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
22

33
import { Button } from '@osrd-project/ui-core';
44
import cx from 'classnames';
@@ -90,8 +90,12 @@ const StdcmConfig = ({
9090
const totalLength = useSelector(getTotalLength);
9191
const maxSpeed = useSelector(getMaxSpeed);
9292

93-
const pathfinding = useStaticPathfinding(infra);
93+
const [showMessage, setShowMessage] = useState(false);
94+
95+
const { pathfinding, isPathFindingLoading } = useStaticPathfinding(infra);
96+
9497
const formRef = useRef<HTMLDivElement>(null);
98+
const pathfindingBannerRef = useRef<HTMLDivElement>(null);
9599

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

@@ -145,6 +149,13 @@ const StdcmConfig = ({
145149
);
146150
};
147151

152+
const getStatusMessage = () => {
153+
if (isPathFindingLoading) {
154+
return t('pathfindingStatus.calculating');
155+
}
156+
return t('pathfindingStatus.success');
157+
};
158+
148159
useEffect(() => {
149160
if (pathfinding) {
150161
const formErrorsStatus = checkStdcmConfigErrors(
@@ -177,6 +188,31 @@ const StdcmConfig = ({
177188
}
178189
}, []);
179190

191+
useEffect(() => {
192+
if (isPathFindingLoading) {
193+
setShowMessage(true);
194+
}
195+
196+
if (pathfinding?.status === 'failure') {
197+
setShowMessage(false);
198+
}
199+
}, [isPathFindingLoading, pathfinding?.status]);
200+
201+
useLayoutEffect(() => {
202+
const handleAnimationEnd = () => {
203+
setShowMessage(false);
204+
};
205+
206+
if (!showMessage || formErrors) {
207+
return undefined;
208+
}
209+
pathfindingBannerRef.current!.addEventListener('animationend', handleAnimationEnd);
210+
211+
return () => {
212+
pathfindingBannerRef.current?.removeEventListener('animationend', handleAnimationEnd);
213+
};
214+
}, [showMessage, formErrors]);
215+
180216
return (
181217
<div className="stdcm__body">
182218
{isDebugMode && (
@@ -238,6 +274,20 @@ const StdcmConfig = ({
238274
)}
239275
</div>
240276

277+
{!formErrors && showMessage && (
278+
<div className="simulation-status-banner">
279+
<div className="banner-content">
280+
<div
281+
ref={pathfindingBannerRef}
282+
className={cx('pathFinding-status', {
283+
'pathFinding-status-success': pathfinding?.status === 'success',
284+
})}
285+
>
286+
{getStatusMessage()}
287+
</div>
288+
</div>
289+
</div>
290+
)}
241291
{isPending && (
242292
<StdcmLoader
243293
cancelStdcmRequest={cancelStdcmRequest}

‎front/src/applications/stdcm/hooks/useStaticPathfinding.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const useStaticPathfinding = (infra?: InfraWithState) => {
3232

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

35-
const [postPathfindingBlocks] =
35+
const [postPathfindingBlocks, { isFetching }] =
3636
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();
3737

3838
// When pathSteps changed
@@ -84,7 +84,7 @@ const useStaticPathfinding = (infra?: InfraWithState) => {
8484
[pathfinding, pathProperties]
8585
);
8686

87-
return result;
87+
return { pathfinding: result, isPathFindingLoading: isFetching };
8888
};
8989

9090
export default useStaticPathfinding;

‎front/src/styles/scss/_variables.scss

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ $colors: (
6767
'primary80': #1f0f96,
6868
'primary90': #180f47,
6969
'selection20': #fff2b3,
70+
'success5': #e6f7ee,
7071
'success30': #3cca80,
7172
'success60': #0b723c,
7273
'warning5': #fdf5e1,

‎front/src/styles/scss/applications/stdcm/_home.scss

+50
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
.banner-content {
259259
padding: 0 0 16px 378px;
260260
background: linear-gradient(180deg, rgba(239, 243, 245) 40px, rgba(233, 239, 242) 40px);
261+
&:has(.pathFinding-status) {
262+
padding: 0;
263+
}
261264
.status {
262265
width: 466px;
263266
display: flex;
@@ -294,6 +297,53 @@
294297
line-height: 24px;
295298
text-align: center;
296299
}
300+
301+
.pathFinding-status {
302+
left: -8px;
303+
position: absolute;
304+
bottom: -95px;
305+
width: 466px;
306+
display: flex;
307+
font-weight: 400;
308+
justify-content: center;
309+
line-height: 24px;
310+
height: 72px;
311+
border-radius: 8px;
312+
color: var(--info60);
313+
background-color: var(--info5);
314+
margin-top: 16px;
315+
padding-top: 23px;
316+
box-shadow:
317+
0 0 0 4px rgba(255, 255, 255, 1) inset,
318+
0 0 0 5px rgb(112, 193, 229) inset,
319+
0 3px 7px -3px rgba(28, 28, 217, 0.4);
320+
&-success {
321+
color: var(--success60);
322+
background-color: var(--success5);
323+
opacity: 0;
324+
box-shadow:
325+
0 0 0 4px rgba(255, 255, 255, 1) inset,
326+
0 0 0 5px rgb(60, 202, 128) inset,
327+
0 3px 7px -3px rgba(11, 114, 60, 0.4);
328+
animation: pathfinding-success 2.7s;
329+
}
330+
}
331+
@keyframes pathfinding-success {
332+
0% {
333+
opacity: 1;
334+
}
335+
74% {
336+
opacity: 1;
337+
}
338+
100% {
339+
opacity: 0;
340+
}
341+
}
342+
343+
.fade-out {
344+
opacity: 0;
345+
transition: opacity 0.3s ease-out;
346+
}
297347
}
298348
}
299349
}

0 commit comments

Comments
 (0)
Please sign in to comment.