Skip to content

Commit 607963f

Browse files
committed
front: stdcm: change map
1 parent e46a85a commit 607963f

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
@@ -77,6 +77,7 @@ const useStdcm = () => {
7777
rollingStock: stdcmRollingStock,
7878
creationDate: new Date(),
7979
speedLimitByTag,
80+
simulationPathSteps: osrdconf.pathSteps,
8081
} as StdcmV2SuccessResponse);
8182

8283
const stdcmTrain: TrainScheduleResult = {
@@ -131,6 +132,7 @@ const useStdcm = () => {
131132
pathProperties,
132133
setPathProperties,
133134
isPending,
135+
simulationPathSteps: stdcmV2Response?.simulationPathSteps,
134136
};
135137
};
136138

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
@@ -47,6 +47,7 @@ import RenderPopup from 'modules/trainschedule/components/ManageTrainSchedule/Ma
4747
import { updateViewport } from 'reducers/map';
4848
import type { Viewport } from 'reducers/map';
4949
import { getMap, getTerrain3DExaggeration } from 'reducers/map/selectors';
50+
import type { PathStep } from 'reducers/osrdconf/types';
5051
import { useAppDispatch } from 'store';
5152
import { getMapMouseEventNearestFeature } from 'utils/mapHelper';
5253

@@ -58,13 +59,17 @@ type MapProps = {
5859
setMapCanvas?: (mapCanvas: string) => void;
5960
hideAttribution?: boolean;
6061
hideItinerary?: boolean;
62+
mapId?: string;
63+
simulationPathSteps?: PathStep[];
6164
};
6265

6366
const Map = ({
6467
pathProperties,
6568
setMapCanvas,
6669
hideAttribution = false,
6770
hideItinerary = false,
71+
mapId = 'map-container',
72+
simulationPathSteps,
6873
}: MapProps) => {
6974
const mapBlankStyle = useMapBlankStyle();
7075

@@ -189,24 +194,14 @@ const Map = ({
189194
// eslint-disable-next-line react-hooks/exhaustive-deps
190195
}, []);
191196

192-
useEffect(() => {
193-
if (pathProperties) {
194-
if (setMapCanvas) {
195-
setShowLayers(false);
196-
}
197-
const newViewport = computeBBoxViewport(bbox(pathProperties.geometry), viewport);
198-
dispatch(updateViewport(newViewport));
199-
}
200-
}, [pathProperties]);
201-
202197
const captureMap = async () => {
203198
if (!pathProperties) return;
204199

205200
const itineraryViewport = computeBBoxViewport(bbox(pathProperties.geometry), viewport);
206201

207202
if (setMapCanvas && !showLayers && isEqual(viewport, itineraryViewport)) {
208203
try {
209-
const mapElement = document.getElementById('map-container');
204+
const mapElement = document.getElementById(mapId);
210205
if (mapElement) {
211206
const canvas = await html2canvas(mapElement);
212207
setMapCanvas(canvas.toDataURL());
@@ -219,6 +214,17 @@ const Map = ({
219214
}
220215
};
221216

217+
useEffect(() => {
218+
if (pathProperties) {
219+
if (setMapCanvas) {
220+
setShowLayers(false);
221+
captureMap();
222+
}
223+
const newViewport = computeBBoxViewport(bbox(pathProperties.geometry), viewport);
224+
dispatch(updateViewport(newViewport));
225+
}
226+
}, [pathProperties]);
227+
222228
return (
223229
<>
224230
<MapButtons
@@ -258,7 +264,7 @@ const Map = ({
258264
}}
259265
onIdle={() => captureMap()}
260266
preserveDrawingBuffer
261-
id="map-container"
267+
id={mapId}
262268
>
263269
<VirtualLayers />
264270
{!hideAttribution && (
@@ -379,7 +385,12 @@ const Map = ({
379385
geometry={pathProperties?.geometry}
380386
hideItineraryLine={hideItinerary}
381387
/>
382-
{mapRef.current && <ItineraryMarkersV2 map={mapRef.current.getMap()} />}
388+
{mapRef.current && (
389+
<ItineraryMarkersV2
390+
simulationPathSteps={simulationPathSteps}
391+
map={mapRef.current.getMap()}
392+
/>
393+
)}
383394
</>
384395
)}
385396
{mapSearchMarker && <SearchMarker data={mapSearchMarker} colors={colors[mapStyle]} />}

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)