-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathindex.ts
59 lines (48 loc) · 2.21 KB
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { createSlice, type Draft, type PayloadAction } from '@reduxjs/toolkit';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import computeBasePathStep from 'modules/trainschedule/helpers/computeBasePathStep';
import { defaultCommonConf, buildCommonConfReducers } from 'reducers/osrdconf/osrdConfCommon';
import type { OsrdConfState } from 'reducers/osrdconf/types';
import { convertIsoUtcToLocalTime } from 'utils/date';
import { msToKmh } from 'utils/physics';
import { builPowerRestrictionReducer } from './powerRestrictionReducer';
export type OperationalStudiesConfState = OsrdConfState;
export const operationalStudiesConfSlice = createSlice({
name: 'operationalStudiesConf',
initialState: defaultCommonConf,
reducers: {
...buildCommonConfReducers<OperationalStudiesConfState>(),
...builPowerRestrictionReducer<OperationalStudiesConfState>(),
selectTrainToEdit(
state: Draft<OperationalStudiesConfState>,
action: PayloadAction<TrainScheduleWithDetails>
) {
const {
rollingStock,
trainName,
initial_speed,
start_time,
options,
speedLimitTag,
labels,
power_restrictions,
path,
constraint_distribution,
} = action.payload;
state.rollingStockID = rollingStock?.id;
state.pathSteps = path.map((_, index) => computeBasePathStep(action.payload, index));
state.startTime = convertIsoUtcToLocalTime(start_time);
state.name = trainName;
state.initialSpeed = initial_speed ? Math.floor(msToKmh(initial_speed) * 10) / 10 : 0;
state.usingElectricalProfiles = options?.use_electrical_profiles ?? true;
state.labels = labels;
state.speedLimitByTag = speedLimitTag || undefined;
state.powerRestriction = power_restrictions || [];
state.constraintDistribution = constraint_distribution || 'STANDARD';
},
},
});
export const operationalStudiesConfSliceActions = operationalStudiesConfSlice.actions;
export type OperationalStudiesConfSlice = typeof operationalStudiesConfSlice;
export type OperationalStudiesConfSliceActions = typeof operationalStudiesConfSliceActions;
export default operationalStudiesConfSlice.reducer;