Skip to content

Commit a0d75cf

Browse files
committed
wip
1 parent 67d74ab commit a0d75cf

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
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

+27-21
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ export 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: Array<
3748
NonNullable<Required<PathProperties['operational_points']>>[number] & {
@@ -41,27 +52,22 @@ export const formatSuggestedOperationalPoints = (
4152
pathSteps: PathStep[],
4253
geometry: GeoJsonLineString,
4354
pathLength: number
44-
): SuggestedOP[] =>
45-
operationalPoints
46-
.map((op) => ({
47-
opId: op.id,
48-
name: op.extensions?.identifier?.name,
49-
uic: op.extensions?.identifier?.uic,
50-
ch: op.extensions?.sncf?.ch,
51-
kp: op.part.extensions?.sncf?.kp,
52-
trigram: op.extensions?.sncf?.trigram,
53-
offsetOnTrack: op.part.position,
54-
track: op.part.track,
55-
positionOnPath: op.position,
56-
coordinates: getPointCoordinates(geometry, pathLength, op.position),
57-
metadata: op?.metadata,
58-
}))
59-
.map((op) => ({
60-
...op,
61-
pathStepId: pathSteps.find(
62-
(pathStep) => matchPathStepAndOp(pathStep, op) && op.kp === pathStep.kp
63-
)?.id,
64-
}));
55+
): SuggestedOP[] => {
56+
const suggestedOPs = operationalPoints.map((op) => ({
57+
opId: op.id,
58+
name: op.extensions?.identifier?.name,
59+
uic: op.extensions?.identifier?.uic,
60+
ch: op.extensions?.sncf?.ch,
61+
kp: op.part.extensions?.sncf?.kp,
62+
trigram: op.extensions?.sncf?.trigram,
63+
offsetOnTrack: op.part.position,
64+
track: op.part.track,
65+
positionOnPath: op.position,
66+
coordinates: getPointCoordinates(geometry, pathLength, op.position),
67+
metadata: op?.metadata,
68+
}));
69+
return populatePathStepIdInSuggestedOPs(suggestedOPs, pathSteps);
70+
};
6571

6672
export const getPathfindingQuery = ({
6773
infraId,

0 commit comments

Comments
 (0)