Skip to content

Commit 0dba8e4

Browse files
committed
front: stdcm: change map
1 parent 4388f9d commit 0dba8e4

File tree

9 files changed

+90
-45
lines changed

9 files changed

+90
-45
lines changed

front/src/applications/stdcm/hooks/useStdcm.ts

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ const useStdcm = () => {
165165
rollingStock: stdcmRollingStock,
166166
creationDate: new Date(),
167167
speedLimitByTag,
168+
simulationPathSteps: osrdconf.pathSteps,
168169
} as StdcmV2SuccessResponse);
169170

170171
const stdcmTrain: TrainScheduleResult = {
@@ -229,6 +230,7 @@ const useStdcm = () => {
229230
pathProperties,
230231
setPathProperties,
231232
isPending,
233+
simulationPathSteps: stdcmV2Response?.simulationPathSteps,
232234
};
233235
};
234236

front/src/applications/stdcm/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
RollingStockWithLiveries,
1515
SimulationResponse,
1616
} from 'common/api/osrdEditoastApi';
17+
import type { PathStep } from 'reducers/osrdconf/types';
1718
import type { ValueOf } from 'utils/types';
1819

1920
export type StdcmRequestStatus = ValueOf<typeof STDCM_REQUEST_STATUS>;
@@ -26,6 +27,7 @@ export type StdcmV2SuccessResponse = Omit<
2627
rollingStock: LightRollingStock;
2728
creationDate: Date;
2829
speedLimitByTag?: string;
30+
simulationPathSteps: PathStep[];
2931
};
3032

3133
export type SimulationReportSheetProps = {

front/src/applications/stdcmV2/components/StdcmConfig.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useEffect } from 'react';
1+
import React, { useRef, useEffect, useState } from 'react';
22

33
import { Button } from '@osrd-project/ui-core';
44
import { Alert } from '@osrd-project/ui-icons';
@@ -21,7 +21,6 @@ import type { StdcmSimulationResult } from '../types';
2121

2222
type StdcmConfigProps = {
2323
currentSimulationInputs: StdcmSimulationResult['input'] | undefined;
24-
pathProperties?: ManageTrainSchedulePathProperties;
2524
isPending: boolean;
2625
launchStdcmRequest: () => Promise<void>;
2726
cancelStdcmRequest: () => void;
@@ -32,7 +31,6 @@ type StdcmConfigProps = {
3231

3332
const StdcmConfig = ({
3433
currentSimulationInputs,
35-
pathProperties,
3634
isPending,
3735
launchStdcmRequest,
3836
cancelStdcmRequest,
@@ -45,7 +43,8 @@ const StdcmConfig = ({
4543
const { updateGridMarginAfter, updateGridMarginBefore, updateStdcmStandardAllowance } =
4644
useOsrdConfActions() as StdcmConfSliceActions;
4745

48-
const { pathfindingState } = usePathfindingV2(undefined, pathProperties);
46+
const [pathProperties, setPathProperties] = useState<ManageTrainSchedulePathProperties>();
47+
const { pathfindingState } = usePathfindingV2(setPathProperties, pathProperties);
4948

5049
const clickOnSimulation = () => {
5150
if (pathfindingState.done) {

front/src/applications/stdcmV2/components/StdcmResults/StdcmResults.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getOperationalPointsWithTimes,
1414
} from 'applications/stdcm/utils/formatSimulationReportSheet';
1515
import { Map } from 'modules/trainschedule/components/ManageTrainSchedule';
16+
import type { PathStep } from 'reducers/osrdconf/types';
1617
import { dateTimeFormatting } from 'utils/date';
1718

1819
import StcdmResultsTable from './StdcmResultsTable';
@@ -22,11 +23,13 @@ type StcdmResultsV2Props = {
2223
stdcmData: StdcmV2SuccessResponse;
2324
pathProperties?: ManageTrainSchedulePathProperties;
2425
setInteractedResultsElements: (interactedResultsElements: boolean) => void;
26+
simulationPathSteps?: PathStep[];
2527
};
2628

2729
const StcdmResults = ({
2830
stdcmData,
2931
pathProperties,
32+
simulationPathSteps,
3033
setInteractedResultsElements,
3134
}: StcdmResultsV2Props) => {
3235
const { t } = useTranslation('stdcm');
@@ -51,7 +54,7 @@ const StcdmResults = ({
5154

5255
return (
5356
<main className="stdcm-v2-results">
54-
<div className="simuation-banner">
57+
<div className="simulation-banner">
5558
<div
5659
className="simulation-validated"
5760
style={{ color: isSimulationSelected ? '#0B723C' : '' }}
@@ -65,7 +68,7 @@ const StcdmResults = ({
6568
</div>
6669
<div className="creation-date">{date}</div>
6770
</div>
68-
<div className="simuation-results">
71+
<div className="simulation-results">
6972
<div className="results-and-sheet">
7073
<StcdmResultsTable
7174
stdcmData={stdcmData}
@@ -97,7 +100,13 @@ const StcdmResults = ({
97100
)}
98101
</div>
99102
<div className="osrd-config-item-container osrd-config-item-container-map map-results">
100-
<Map hideAttribution setMapCanvas={setMapCanvas} pathProperties={pathProperties} />
103+
<Map
104+
mapId="map-result"
105+
hideAttribution
106+
setMapCanvas={setMapCanvas}
107+
pathProperties={pathProperties}
108+
simulationPathSteps={simulationPathSteps}
109+
/>
101110
</div>
102111
</div>
103112
</main>

front/src/applications/stdcmV2/views/StdcmViewV2.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ import type { StdcmSimulationResult } from '../types';
1414

1515
const StdcmViewV2 = () => {
1616
const { t } = useTranslation('stdcm');
17-
const { launchStdcmRequest, cancelStdcmRequest, isPending, stdcmV2Results, pathProperties } =
18-
useStdcm();
17+
const {
18+
launchStdcmRequest,
19+
cancelStdcmRequest,
20+
isPending,
21+
stdcmV2Results,
22+
pathProperties,
23+
simulationPathSteps,
24+
} = useStdcm();
1925
const { getScenarioID } = useOsrdConfSelectors();
2026
const scenarioID = useSelector(getScenarioID);
2127

@@ -41,7 +47,7 @@ const StdcmViewV2 = () => {
4147
{scenarioID && (
4248
<StdcmConfig
4349
currentSimulationInputs={currentSimulationInputs}
44-
pathProperties={pathProperties}
50+
// pathProperties={pathProperties}
4551
isPending={isPending}
4652
launchStdcmRequest={launchStdcmRequest}
4753
cancelStdcmRequest={cancelStdcmRequest}
@@ -59,6 +65,7 @@ const StdcmViewV2 = () => {
5965
stdcmData={stdcmV2Results.stdcmResponse}
6066
pathProperties={pathProperties}
6167
setInteractedResultsElements={setInteractedResultsElements}
68+
simulationPathSteps={simulationPathSteps}
6269
/>
6370
)}
6471
</div>

front/src/modules/pathfinding/hook/usePathfinding.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function init({
134134
}
135135

136136
export const usePathfindingV2 = (
137-
setPathProperties?: (pathProperties?: ManageTrainSchedulePathProperties) => void | null,
137+
setPathProperties: (pathProperties?: ManageTrainSchedulePathProperties) => void | null,
138138
pathProperties?: ManageTrainSchedulePathProperties
139139
) => {
140140
const { t } = useTranslation(['operationalStudies/manageTrainSchedule']);
@@ -175,7 +175,7 @@ export const usePathfindingV2 = (
175175
const { updatePathSteps } = useOsrdConfActions();
176176

177177
const generatePathfindingParams = (): PostV2InfraByInfraIdPathfindingBlocksApiArg | null => {
178-
setPathProperties?.(undefined);
178+
setPathProperties(undefined);
179179
return getPathfindingQuery({ infraId, rollingStock, origin, destination, pathSteps });
180180
};
181181

@@ -284,7 +284,7 @@ export const usePathfindingV2 = (
284284
compact(updatedPathSteps)
285285
);
286286

287-
setPathProperties?.({
287+
setPathProperties({
288288
electrifications,
289289
geometry,
290290
suggestedOperationalPoints,

front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkersV2.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,20 @@ const extractMarkerInformation = (pathSteps: (PathStep | null)[]) =>
7878
return acc;
7979
}, [] as MarkerInformation[]);
8080

81-
const ItineraryMarkers = ({ map }: { map: Map }) => {
81+
const ItineraryMarkers = ({
82+
map,
83+
simulationPathSteps,
84+
}: {
85+
map: Map;
86+
simulationPathSteps?: PathStep[];
87+
}) => {
8288
const { getPathSteps } = useOsrdConfSelectors();
8389
const pathSteps = useSelector(getPathSteps);
8490

85-
const markersInformation = useMemo(() => extractMarkerInformation(pathSteps), [pathSteps]);
91+
const markersInformation = useMemo(
92+
() => extractMarkerInformation(simulationPathSteps || pathSteps),
93+
[simulationPathSteps, pathSteps]
94+
);
8695

8796
const getMarkerDisplayInformation = useCallback(
8897
(markerInfo: MarkerInformation) => {

front/src/modules/trainschedule/components/ManageTrainSchedule/Map.tsx

+24-13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import RenderPopup from 'modules/trainschedule/components/ManageTrainSchedule/Ma
4949
import { updateViewport } from 'reducers/map';
5050
import type { Viewport } from 'reducers/map';
5151
import { getMap, getTerrain3DExaggeration } from 'reducers/map/selectors';
52+
import type { PathStep } from 'reducers/osrdconf/types';
5253
import { getTrainScheduleV2Activated } from 'reducers/user/userSelectors';
5354
import { useAppDispatch } from 'store';
5455
import { getMapMouseEventNearestFeature } from 'utils/mapHelper';
@@ -61,13 +62,17 @@ type MapProps = {
6162
setMapCanvas?: (mapCanvas: string) => void;
6263
hideAttribution?: boolean;
6364
hideItinerary?: boolean;
65+
mapId?: string;
66+
simulationPathSteps?: PathStep[];
6467
};
6568

6669
const Map = ({
6770
pathProperties,
6871
setMapCanvas,
6972
hideAttribution = false,
7073
hideItinerary = false,
74+
mapId = 'map-container',
75+
simulationPathSteps,
7176
}: MapProps) => {
7277
const mapBlankStyle = useMapBlankStyle();
7378

@@ -193,24 +198,14 @@ const Map = ({
193198
// eslint-disable-next-line react-hooks/exhaustive-deps
194199
}, []);
195200

196-
useEffect(() => {
197-
if (pathProperties) {
198-
if (setMapCanvas) {
199-
setShowLayers(false);
200-
}
201-
const newViewport = computeBBoxViewport(bbox(pathProperties.geometry), viewport);
202-
dispatch(updateViewport(newViewport));
203-
}
204-
}, [pathProperties]);
205-
206201
const captureMap = async () => {
207202
if (!pathProperties) return;
208203

209204
const itineraryViewport = computeBBoxViewport(bbox(pathProperties.geometry), viewport);
210205

211206
if (setMapCanvas && !showLayers && isEqual(viewport, itineraryViewport)) {
212207
try {
213-
const mapElement = document.getElementById('map-container');
208+
const mapElement = document.getElementById(mapId);
214209
if (mapElement) {
215210
const canvas = await html2canvas(mapElement);
216211
setMapCanvas(canvas.toDataURL());
@@ -223,6 +218,17 @@ const Map = ({
223218
}
224219
};
225220

221+
useEffect(() => {
222+
if (pathProperties) {
223+
if (setMapCanvas) {
224+
setShowLayers(false);
225+
captureMap();
226+
}
227+
const newViewport = computeBBoxViewport(bbox(pathProperties.geometry), viewport);
228+
dispatch(updateViewport(newViewport));
229+
}
230+
}, [pathProperties]);
231+
226232
return (
227233
<>
228234
<MapButtons
@@ -262,7 +268,7 @@ const Map = ({
262268
}}
263269
onIdle={() => captureMap()}
264270
preserveDrawingBuffer
265-
id="map-container"
271+
id={mapId}
266272
>
267273
<VirtualLayers />
268274
{!hideAttribution && (
@@ -384,7 +390,12 @@ const Map = ({
384390
geometry={pathProperties?.geometry}
385391
hideItineraryLine={hideItinerary}
386392
/>
387-
{mapRef.current && <ItineraryMarkersV2 map={mapRef.current.getMap()} />}
393+
{mapRef.current && (
394+
<ItineraryMarkersV2
395+
simulationPathSteps={simulationPathSteps}
396+
map={mapRef.current.getMap()}
397+
/>
398+
)}
388399
</>
389400
) : (
390401
<>

front/src/styles/scss/applications/stdcmV2/_home.scss

+23-17
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,24 @@
9696
}
9797

9898
.stdcm-v2-map {
99-
border-radius: 8px;
100-
border: 1px solid rgba(255, 255, 255, 1);
99+
border-radius: 0.5rem;
100+
border: 0.063rem solid rgba(255, 255, 255, 1);
101101
box-shadow:
102-
0px 0px 0px 2px rgba(255, 255, 255, 0.75) inset,
103-
0px 0px 0px 1px rgba(0, 0, 0, 0.25) inset;
102+
0rem 0rem 0rem 0.125rem rgba(255, 255, 255, 0.75) inset,
103+
0rem 0rem 0rem 0.063rem rgba(0, 0, 0, 0.25) inset;
104104
height: auto;
105105
min-height: 540px;
106106
margin-left: 0.85rem;
107107
width: 100%;
108108
height: calc(100vh - 64px);
109+
110+
& .results {
111+
margin: 2.313rem 2rem 0 0.85rem;
112+
width: 100%;
113+
height: 540px;
114+
}
109115
}
116+
110117
}
111118
.stdcm-container {
112119
position: relative;
@@ -144,7 +151,7 @@
144151

145152
.stdcm-v2-results {
146153
background-color: rgb(233, 239, 242);
147-
.simuation-banner {
154+
.simulation-banner {
148155
color: rgb(0, 0, 0);
149156
font-weight: 600;
150157
font-size: 1.125rem;
@@ -169,9 +176,19 @@
169176
}
170177
}
171178
}
172-
.simuation-results {
179+
.simulation-results {
173180
display: flex;
174181
justify-content: space-between;
182+
.map-results {
183+
border: 0.063rem solid rgba(255, 255, 255, 1);
184+
border-radius: 0.5rem;
185+
box-shadow:
186+
0rem 0rem 0rem 0.125rem rgba(255, 255, 255, 0.75) inset,
187+
0rem 0rem 0rem 0.063rem rgba(0, 0, 0, 0.25) inset;
188+
height: 33.75rem;
189+
margin: 2rem 2rem 0 0.85rem;
190+
width: 100%;
191+
}
175192
.results-and-sheet {
176193
display: flex;
177194
flex-direction: column;
@@ -320,16 +337,5 @@
320337
padding-left: 12.938rem;
321338
}
322339
}
323-
.map-results {
324-
width: 33.75rem;
325-
height: 33.75rem;
326-
margin-top: 2.313rem;
327-
margin-right: 2rem;
328-
border-radius: 0.5rem;
329-
border: 0.063rem solid rgba(255, 255, 255, 1);
330-
box-shadow:
331-
0rem 0rem 0rem 0.125rem rgba(255, 255, 255, 0.75) inset,
332-
0rem 0rem 0rem 0.063rem rgba(0, 0, 0, 0.25) inset;
333-
}
334340
}
335341
}

0 commit comments

Comments
 (0)