Skip to content

Commit 3a4141b

Browse files
committed
wip
1 parent 3b7dff6 commit 3a4141b

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

front/src/applications/operationalStudies/hooks/__tests__/useSetupItineraryForTrainUpdate.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it, expect } from 'vitest';
22

33
import type { PathfindingResult } from 'common/api/osrdEditoastApi';
4+
import { populatePathStepIdInSuggestedOPs } from 'modules/pathfinding/utils';
45

56
import { updatePathStepsFromOperationalPoints } from '../useSetupItineraryForTrainUpdate';
67

@@ -177,7 +178,7 @@ describe('updatePathStepsFrom', () => {
177178
];
178179
const result = updatePathStepsFromOperationalPoints(
179180
pathSteps,
180-
suggestedOpPoints,
181+
populatePathStepIdInSuggestedOPs(suggestedOpPoints, pathSteps),
181182
pathFindingResult as Extract<PathfindingResult, { status: 'success' }>,
182183
stepsCoordinates
183184
);
@@ -253,7 +254,7 @@ describe('updatePathStepsFrom', () => {
253254
];
254255
const result = updatePathStepsFromOperationalPoints(
255256
pathSteps,
256-
suggestedOpPoints,
257+
populatePathStepIdInSuggestedOPs(suggestedOpPoints, pathSteps),
257258
pathFindingResult as Extract<PathfindingResult, { status: 'success' }>,
258259
stepsCoordinates
259260
);

front/src/modules/pathfinding/utils.ts

+26-20
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,37 @@ const matchPathStepAndOp = (
3232
return step.track === op.track && step.offset === op.offsetOnTrack;
3333
};
3434

35+
export const populatePathStepIdInSuggestedOPs = (
36+
suggestedOPs: SuggestedOP[],
37+
pathSteps: PathStep[]
38+
): SuggestedOP[] =>
39+
suggestedOPs.map((op) => ({
40+
...op,
41+
pathStepId: pathSteps.find(
42+
(pathStep) => matchPathStepAndOp(pathStep, op) // TODO: && op.kp === pathStep.kp
43+
)?.id,
44+
}));
45+
3546
export const formatSuggestedOperationalPoints = (
3647
operationalPoints: NonNullable<Required<PathProperties['operational_points']>>,
3748
pathSteps: PathStep[],
3849
geometry: GeoJsonLineString,
3950
pathLength: number
40-
): SuggestedOP[] =>
41-
operationalPoints
42-
.map((op) => ({
43-
opId: op.id,
44-
name: op.extensions?.identifier?.name,
45-
uic: op.extensions?.identifier?.uic,
46-
ch: op.extensions?.sncf?.ch,
47-
kp: op.part.extensions?.sncf?.kp,
48-
trigram: op.extensions?.sncf?.trigram,
49-
offsetOnTrack: op.part.position,
50-
track: op.part.track,
51-
positionOnPath: op.position,
52-
coordinates: getPointCoordinates(geometry, pathLength, op.position),
53-
}))
54-
.map((op) => ({
55-
...op,
56-
pathStepId: pathSteps.find(
57-
(pathStep) => matchPathStepAndOp(pathStep, op) && op.kp === pathStep.kp
58-
)?.id,
59-
}));
51+
): SuggestedOP[] => {
52+
const suggestedOPs = operationalPoints.map((op) => ({
53+
opId: op.id,
54+
name: op.extensions?.identifier?.name,
55+
uic: op.extensions?.identifier?.uic,
56+
ch: op.extensions?.sncf?.ch,
57+
kp: op.part.extensions?.sncf?.kp,
58+
trigram: op.extensions?.sncf?.trigram,
59+
offsetOnTrack: op.part.position,
60+
track: op.part.track,
61+
positionOnPath: op.position,
62+
coordinates: getPointCoordinates(geometry, pathLength, op.position),
63+
}));
64+
return populatePathStepIdInSuggestedOPs(suggestedOPs, pathSteps);
65+
};
6066

6167
export const getPathfindingQuery = ({
6268
infraId,

0 commit comments

Comments
 (0)