Skip to content

Commit

Permalink
fixup! front: fix selected track display
Browse files Browse the repository at this point in the history
  • Loading branch information
theocrsb committed Jan 23, 2025
1 parent b7e6857 commit e4fedab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';

import cx from 'classnames';
import type { Position } from 'geojson';
import type { Map } from 'maplibre-gl';
import { Marker } from 'react-map-gl/maplibre';
import { useSelector } from 'react-redux';

import useCachedTrackSections from 'applications/operationalStudies/hooks/useCachedTrackSections';
import destinationSVG from 'assets/pictures/destination.svg';
Expand All @@ -14,7 +12,6 @@ import stdcmOrigin from 'assets/pictures/mapMarkers/start.svg';
import originSVG from 'assets/pictures/origin.svg';
import viaSVG from 'assets/pictures/via.svg';
import type { PathItemLocation, TrackSection } from 'common/api/osrdEditoastApi';
import { useOsrdConfSelectors } from 'common/osrdContext';
import { matchPathStepAndOp } from 'modules/pathfinding/utils';
import type { PathStep } from 'reducers/osrdconf/types';

Expand Down Expand Up @@ -45,10 +42,10 @@ type MarkerProperties = {
);

type ItineraryMarkersProps = {
map: Map;
simulationPathSteps: MarkerInformation[];
pathStepsAndSuggestedOPs?: SuggestedOP[];
showStdcmAssets: boolean;
infraId: number;
};

const formatPointWithNoName = (
Expand Down Expand Up @@ -112,19 +109,13 @@ const extractMarkerInformation = (
.filter((marker): marker is MarkerProperties => marker !== null);

const ItineraryMarkers = ({
map,
simulationPathSteps,
pathStepsAndSuggestedOPs,
showStdcmAssets,
infraId,
}: ItineraryMarkersProps) => {
const { getInfraID } = useOsrdConfSelectors();
const infraId = useSelector(getInfraID);
if (!infraId) return null;
const { getTrackSectionsByIds } = useCachedTrackSections(infraId);

const getTrackSectionsByIds = useMemo(
() => useCachedTrackSections(infraId).getTrackSectionsByIds,
[infraId]
);
const markersInformation = useMemo(
() =>
pathStepsAndSuggestedOPs &&
Expand All @@ -144,26 +135,23 @@ const ItineraryMarkers = ({
fetchTrackSections();
}, [markersInformation]);

const getMarkerDisplayInformation = useCallback(
(markerInfo: MarkerProperties) => {
const {
pathStep: { metadata: markerMetadata, name: markerName },
type: markerType,
} = markerInfo;
const getMarkerDisplayInformation = useCallback((markerInfo: MarkerProperties) => {
const {
pathStep: { metadata: markerMetadata, name: markerName },
type: markerType,
} = markerInfo;

if (markerName) return markerName;
if (!markerMetadata) return null;
if (markerName) return markerName;
if (!markerMetadata) return null;

const {
lineCode: markerLineCode,
lineName: markerLineName,
trackName: markerTrackName,
} = markerMetadata;

return formatPointWithNoName(markerLineCode, markerLineName, markerTrackName, markerType);
},
[map, trackSections]
);
const {
lineCode: markerLineCode,
lineName: markerLineName,
trackName: markerTrackName,
} = markerMetadata;

return formatPointWithNoName(markerLineCode, markerLineName, markerTrackName, markerType);
}, []);

return markersInformation.map((markerInfo) => {
const isDestination = markerInfo.type === MARKER_TYPE.DESTINATION;
Expand Down Expand Up @@ -196,12 +184,6 @@ const ItineraryMarkers = ({
};
}

const markerName = (
<div className={`map-pathfinding-marker ${markerInfo.type}-name`}>
{getMarkerDisplayInformation(markerInfo)}
</div>
);

return (
<Marker
longitude={markerInfo.coordinates[0]}
Expand All @@ -223,7 +205,11 @@ const ItineraryMarkers = ({
{markerInfo.index}
</span>
)}
{!showStdcmAssets && markerName}
{!showStdcmAssets && (
<div className={`map-pathfinding-marker ${markerInfo.type}-name`}>
{getMarkerDisplayInformation(markerInfo)}
</div>
)}
</Marker>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,12 @@ const Map = ({
showStdcmAssets={showStdcmAssets}
isFeasible={isFeasible}
/>
{mapRef.current && (
{mapRef.current && infraID && (
<ItineraryMarkers
simulationPathSteps={simulationPathSteps}
pathStepsAndSuggestedOPs={pathStepsAndSuggestedOPs}
map={mapRef.current.getMap()}
showStdcmAssets={showStdcmAssets}
infraId={infraID}
/>
)}
{mapSearchMarker && <SearchMarker data={mapSearchMarker} colors={colors[mapStyle]} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ const NewMap = ({
showStdcmAssets={showStdcmAssets}
isFeasible={isFeasible}
/>
{mapRef.current && (
{mapRef.current && infraID && (
<ItineraryMarkers
simulationPathSteps={simulationPathSteps}
map={mapRef.current.getMap()}
showStdcmAssets={showStdcmAssets}
infraId={infraID}
/>
)}
{mapSearchMarker && <SearchMarker data={mapSearchMarker} colors={colors[mapStyle]} />}
Expand Down

0 comments on commit e4fedab

Please sign in to comment.