-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathsetPointIti.ts
35 lines (32 loc) · 1.23 KB
/
setPointIti.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable import/prefer-default-export */
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import { insertViaFromMap } from 'reducers/osrdconf/helpers';
import type { PathStep } from 'reducers/osrdconf/types';
import { store } from 'store';
import { addElementAtIndex, replaceElementAtIndex } from 'utils/array';
export function setPointIti(
pointType: 'origin' | 'destination' | 'via',
pathStep: PathStep,
launchPathfinding: (newPathSteps: (PathStep | null)[]) => void,
resetFeatureInfoClick: () => void,
pathProperties?: ManageTrainSchedulePathProperties
) {
const { pathSteps } = store.getState().operationalStudiesConf;
let newPathSteps: (PathStep | null)[];
switch (pointType) {
case 'origin':
newPathSteps = replaceElementAtIndex(pathSteps, 0, pathStep);
break;
case 'destination':
newPathSteps = replaceElementAtIndex(pathSteps, -1, pathStep);
break;
default:
if (pathProperties) {
newPathSteps = insertViaFromMap(pathSteps, pathStep, pathProperties);
} else {
newPathSteps = addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep);
}
}
resetFeatureInfoClick();
launchPathfinding(newPathSteps);
}