-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathsetPointIti.ts
37 lines (35 loc) · 1.26 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
36
37
/* eslint-disable import/prefer-default-export */
import type { ManageTrainSchedulePathProperties } from 'applications/operationalStudies/types';
import type { ConfSliceActions } from 'reducers/osrdconf/osrdConfCommon';
import type { PathStep } from 'reducers/osrdconf/types';
import { store } from 'store';
import { addElementAtIndex } from 'utils/array';
export function setPointItiV2(
pointType: 'origin' | 'destination' | 'via',
pathStep: PathStep,
actions: ConfSliceActions,
pathProperties?: ManageTrainSchedulePathProperties
) {
const { updateOriginV2, updateDestinationV2, addViaV2, updatePathSteps, updateFeatureInfoClick } =
actions;
const { pathSteps } = store.getState().operationalStudiesConf;
switch (pointType) {
case 'origin':
store.dispatch(updateOriginV2(pathStep));
break;
case 'destination':
store.dispatch(updateDestinationV2(pathStep));
break;
default:
if (pathProperties) {
store.dispatch(addViaV2({ newVia: pathStep, pathProperties }));
} else {
store.dispatch(
updatePathSteps({
pathSteps: addElementAtIndex(pathSteps, pathSteps.length - 1, pathStep),
})
);
}
}
store.dispatch(updateFeatureInfoClick({ displayPopup: false }));
}