Skip to content

Commit c6da206

Browse files
committed
front: simplify pathstep handling in launchpathfinding
Since v5.5, typescript now remembers that the pathstep are all not null after the condition Signed-off-by: SharglutDev <p.filimon75@gmail.com>
1 parent 438cb74 commit c6da206

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const usePathfinding = (
6969
const setError = (error?: string) => setPathfindingState({ ...initialPathfindingState, error });
7070

7171
const handleInvalidPathItems = (
72-
steps: (PathStep | null)[],
72+
steps: PathStep[],
7373
invalidPathItems: Extract<PathfindingInputError, { error_type: 'invalid_path_items' }>['items']
7474
) => {
7575
// TODO: we currently only handle invalid pathSteps with trigram. We will have to do it for trackOffset, opId and uic too.
@@ -175,7 +175,7 @@ const usePathfinding = (
175175
dispatch(replaceItinerary(steps));
176176
setPathProperties(undefined);
177177

178-
if (steps.some((step) => step === null)) {
178+
if (!steps.every((step) => step !== null)) {
179179
setIsMissingParam();
180180
return;
181181
}
@@ -188,7 +188,7 @@ const usePathfinding = (
188188
const pathfindingInput = getPathfindingQuery({
189189
infraId,
190190
rollingStock,
191-
pathSteps: steps.filter((step) => step !== null && !step.isInvalid),
191+
pathSteps: steps.filter((step) => !step.isInvalid),
192192
});
193193

194194
if (!pathfindingInput) {
@@ -200,10 +200,7 @@ const usePathfinding = (
200200
const pathfindingResult = await postPathfindingBlocks(pathfindingInput).unwrap();
201201

202202
if (pathfindingResult.status === 'success') {
203-
await populateStoreWithPathfinding(
204-
steps.map((step) => step!),
205-
pathfindingResult
206-
);
203+
await populateStoreWithPathfinding(steps, pathfindingResult);
207204
setIsDone();
208205
return;
209206
}
@@ -214,7 +211,7 @@ const usePathfinding = (
214211

215212
if (incompatibleConstraintsCheck) {
216213
await populateStoreWithPathfinding(
217-
steps.map((step) => step!),
214+
steps,
218215
pathfindingResult.relaxed_constraints_path,
219216
pathfindingResult.incompatible_constraints
220217
);

0 commit comments

Comments
 (0)