Skip to content

Commit 5e5c4a1

Browse files
committed
front: use early return in extractMarkerInformation() loop
Reduces indentation, evacuates the edge case up-front. Signed-off-by: Simon Ser <contact@emersion.fr>
1 parent f94fce3 commit 5e5c4a1

File tree

1 file changed

+23
-24
lines changed
  • front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap

1 file changed

+23
-24
lines changed

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

+23-24
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,40 @@ const extractMarkerInformation = (
7272
): MarkerProperties[] =>
7373
pathSteps
7474
.map((pathStep, index): MarkerProperties | null => {
75+
if (!pathStep.coordinates) return null;
76+
7577
const matchingOp = suggestedOP
7678
? suggestedOP.find((op) => matchPathStepAndOp(pathStep, op))
7779
: undefined;
7880

79-
if (pathStep.coordinates) {
80-
if (pathStep.pointType === MARKER_TYPE.ORIGIN) {
81-
return {
82-
coordinates: pathStep.coordinates,
83-
type: MARKER_TYPE.ORIGIN,
84-
imageSource: showStdcmAssets ? stdcmOrigin : originSVG,
85-
op: matchingOp,
86-
pathStep,
87-
};
88-
}
89-
90-
if (pathStep.pointType === MARKER_TYPE.DESTINATION) {
91-
return {
92-
coordinates: pathStep.coordinates,
93-
type: MARKER_TYPE.DESTINATION,
94-
imageSource: showStdcmAssets ? stdcmDestination : destinationSVG,
95-
op: matchingOp,
96-
pathStep,
97-
};
98-
}
81+
if (pathStep.pointType === MARKER_TYPE.ORIGIN) {
82+
return {
83+
coordinates: pathStep.coordinates,
84+
type: MARKER_TYPE.ORIGIN,
85+
imageSource: showStdcmAssets ? stdcmOrigin : originSVG,
86+
op: matchingOp,
87+
pathStep,
88+
};
89+
}
9990

91+
if (pathStep.pointType === MARKER_TYPE.DESTINATION) {
10092
return {
10193
coordinates: pathStep.coordinates,
102-
type: MARKER_TYPE.VIA,
103-
imageSource: showStdcmAssets ? stdcmVia : viaSVG,
104-
index,
94+
type: MARKER_TYPE.DESTINATION,
95+
imageSource: showStdcmAssets ? stdcmDestination : destinationSVG,
10596
op: matchingOp,
10697
pathStep,
10798
};
10899
}
109-
return null;
100+
101+
return {
102+
coordinates: pathStep.coordinates,
103+
type: MARKER_TYPE.VIA,
104+
imageSource: showStdcmAssets ? stdcmVia : viaSVG,
105+
index,
106+
op: matchingOp,
107+
pathStep,
108+
};
110109
})
111110
.filter((marker): marker is MarkerProperties => marker !== null);
112111

0 commit comments

Comments
 (0)