Skip to content

Commit 333b7dd

Browse files
committed
front: use getStepLocation in pathfinding/utils and checkCurrentConfig
Signed-off-by: Clara Ni <[email protected]>
1 parent cb7e4d9 commit 333b7dd

File tree

3 files changed

+10
-50
lines changed

3 files changed

+10
-50
lines changed

front/src/modules/pathfinding/helpers/getStepLocation.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { mToMm } from 'utils/physics';
44

55
const getStepLocation = (step: PathStep | StdcmPathStep): PathItemLocation => {
66
if ('track' in step) {
7+
// TODO: step offset should be in mm in the store /!\
8+
// pathfinding blocks endpoint requires offsets in mm
79
return { track: step.track, offset: mToMm(step.offset) };
810
}
911
if ('operational_point' in step) {

front/src/modules/pathfinding/utils.ts

+5-22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type { PathStep } from 'reducers/osrdconf/types';
1313
import { addElementAtIndex } from 'utils/array';
1414
import { getPointCoordinates } from 'utils/geometry';
1515

16+
import getStepLocation from './helpers/getStepLocation';
17+
1618
export const formatSuggestedOperationalPoints = (
1719
operationalPoints: NonNullable<Required<PathProperties['operational_points']>>,
1820
geometry: GeoJsonLineString,
@@ -65,28 +67,9 @@ export const getPathfindingQuery = ({
6567
}): PostInfraByInfraIdPathfindingBlocksApiArg | null => {
6668
if (infraId && rollingStock && origin && destination) {
6769
// Only origin and destination can be null so we can compact and we want to remove any via that would be null
68-
const pathItems: PathfindingInput['path_items'] = compact(pathSteps).map((step) => {
69-
if ('uic' in step) {
70-
return { uic: step.uic, secondary_code: step.ch };
71-
}
72-
if ('track' in step) {
73-
return {
74-
track: step.track,
75-
// TODO: step offset should be in mm in the store /!\
76-
// pathfinding blocks endpoint requires offsets in mm
77-
offset: step.offset * 1000,
78-
};
79-
}
80-
if ('operational_point' in step) {
81-
return {
82-
operational_point: step.operational_point,
83-
};
84-
}
85-
return {
86-
trigram: step.trigram,
87-
secondary_code: step.ch,
88-
};
89-
});
70+
const pathItems: PathfindingInput['path_items'] = compact(pathSteps).map((step) =>
71+
getStepLocation(step)
72+
);
9073

9174
return {
9275
infraId,

front/src/modules/trainschedule/components/ManageTrainSchedule/helpers/checkCurrentConfig.ts

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
21
import { compact } from 'lodash';
32
import type { Dispatch } from 'redux';
43

4+
import getStepLocation from 'modules/pathfinding/helpers/getStepLocation';
55
import type { ValidConfig } from 'modules/trainschedule/components/ManageTrainSchedule/types';
66
import { setFailure } from 'reducers/main';
77
import type { OsrdConfState } from 'reducers/osrdconf/types';
88
import { isInvalidFloatNumber } from 'utils/numbers';
9-
import { kmhToMs, mToMm } from 'utils/physics';
9+
import { kmhToMs } from 'utils/physics';
1010

1111
import formatMargin from './formatMargin';
1212
import formatSchedule from './formatSchedule';
@@ -145,32 +145,7 @@ const checkCurrentConfig = (
145145
rollingStockComfort,
146146
initialSpeed: initialSpeed ? kmhToMs(initialSpeed) : 0,
147147
usingElectricalProfiles,
148-
path: compact(pathSteps).map((step) => {
149-
// TODO use lodash pick
150-
const {
151-
arrival,
152-
locked,
153-
stopFor,
154-
positionOnPath,
155-
coordinates,
156-
name,
157-
ch,
158-
metadata,
159-
kp,
160-
receptionSignal,
161-
theoreticalMargin,
162-
...stepLocation
163-
} = step;
164-
165-
if ('track' in stepLocation) {
166-
return {
167-
...stepLocation,
168-
offset: mToMm(stepLocation.offset),
169-
};
170-
}
171-
return { ...stepLocation, secondary_code: ch };
172-
}),
173-
148+
path: compact(pathSteps).map((step) => ({ id: step.id, ...getStepLocation(step) })),
174149
margins: formatMargin(compact(pathSteps)),
175150
schedule: formatSchedule(compact(pathSteps)),
176151
powerRestrictions: powerRestriction,

0 commit comments

Comments
 (0)