Skip to content

Commit 285b017

Browse files
committed
fixup! front: create type StdcmPathStep
1 parent 5d1a191 commit 285b017

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

front/src/applications/stdcm/utils/formatStdcmConf.ts

+3-19
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,20 @@ import { compact } from 'lodash';
33
import type { Dispatch } from 'redux';
44

55
import type {
6-
PathItemLocation,
76
PathfindingItem,
87
PostTimetableByIdStdcmApiArg,
98
TrainScheduleBase,
109
} from 'common/api/osrdEditoastApi';
10+
import getStepLocation from 'modules/pathfinding/helpers/getStepLocation';
1111
import type { InfraState } from 'reducers/infra';
1212
import { setFailure } from 'reducers/main';
13-
import type { OsrdStdcmConfState, StandardAllowance, StdcmPathStep } from 'reducers/osrdconf/types';
13+
import type { OsrdStdcmConfState, StandardAllowance } from 'reducers/osrdconf/types';
1414
import { dateTimeFormatting } from 'utils/date';
15-
import { kmhToMs, mToMm, tToKg } from 'utils/physics';
15+
import { kmhToMs, tToKg } from 'utils/physics';
1616
import { ISO8601Duration2sec, sec2ms } from 'utils/timeManipulation';
1717

1818
import createMargin from './createMargin';
1919

20-
const getStepLocation = (step: StdcmPathStep): PathItemLocation => {
21-
if ('track' in step) {
22-
return { track: step.track, offset: mToMm(step.offset) };
23-
}
24-
if ('operational_point' in step) {
25-
return { operational_point: step.operational_point };
26-
}
27-
if ('trigram' in step) {
28-
return { trigram: step.trigram, secondary_code: step.secondary_code };
29-
}
30-
if (step.uic === -1) {
31-
throw new Error('Invalid UIC');
32-
}
33-
return { uic: step.uic, secondary_code: step.secondary_code };
34-
};
35-
3620
// TODO: DROP STDCM V1: remove formattedStartTime, startTime and latestStartTime
3721
type ValidStdcmConfig = {
3822
rollingStockId: number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { PathItemLocation } from 'common/api/osrdEditoastApi';
2+
import type { PathStep, StdcmPathStep } from 'reducers/osrdconf/types';
3+
import { mToMm } from 'utils/physics';
4+
5+
const getStepLocation = (step: PathStep | StdcmPathStep): PathItemLocation => {
6+
if ('track' in step) {
7+
return { track: step.track, offset: mToMm(step.offset) };
8+
}
9+
if ('operational_point' in step) {
10+
return { operational_point: step.operational_point };
11+
}
12+
if ('trigram' in step) {
13+
return { trigram: step.trigram, secondary_code: step.ch };
14+
}
15+
if (step.uic === -1) {
16+
throw new Error('Invalid UIC');
17+
}
18+
return { uic: step.uic, secondary_code: step.ch };
19+
};
20+
21+
export default getStepLocation;

0 commit comments

Comments
 (0)