Skip to content

Commit

Permalink
front: add option usingspeedlimits to validconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Rolland <[email protected]>
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
Alex Rolland authored and clarani committed Feb 24, 2025
1 parent 85702d1 commit f310a47
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo } from 'react';
import { useCallback, useEffect, useMemo } from 'react';

import { compact } from 'lodash';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -27,7 +27,10 @@ import {
} from 'modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers';
import SimulationSettings from 'modules/trainschedule/components/ManageTrainSchedule/SimulationSettings';
import TrainSettings from 'modules/trainschedule/components/ManageTrainSchedule/TrainSettings';
import { updateRollingStockComfort } from 'reducers/osrdconf/operationalStudiesConf';
import {
resetUsingSpeedLimits,
updateRollingStockComfort,
} from 'reducers/osrdconf/operationalStudiesConf';
import {
getConstraintDistribution,
getDestination,
Expand Down Expand Up @@ -198,6 +201,15 @@ const ManageTrainSchedule = () => {
),
};

// reset usingSpeedLimits when unmounting, to prevent user from being able to create a train
// without speed limits
useEffect(
() => () => {
dispatch(resetUsingSpeedLimits());
},
[]
);

return (
<>
<div className="osrd-config-item-container mb-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const checkCurrentConfig = (
speedLimitByTag,
initialSpeed,
usingElectricalProfiles,
usingSpeedLimits,
rollingStockComfort,
powerRestriction,
startTime,
Expand Down Expand Up @@ -145,6 +146,7 @@ const checkCurrentConfig = (
rollingStockComfort,
initialSpeed: initialSpeed ? kmhToMs(initialSpeed) : 0,
usingElectricalProfiles,
usingSpeedLimits,
path: compact(pathSteps).map((step) => ({ id: step.id, ...getStepLocation(step) })),
margins: formatMargin(compact(pathSteps)),
schedule: formatSchedule(compact(pathSteps)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function formatTrainSchedulePayload(
speedLimitByTag,
initialSpeed,
usingElectricalProfiles,
usingSpeedLimits,
rollingStockComfort,
margins,
powerRestrictions,
Expand All @@ -29,6 +30,7 @@ export default function formatTrainSchedulePayload(
margins,
options: {
use_electrical_profiles: usingElectricalProfiles,
use_speed_limits_for_simulation: usingSpeedLimits,
},
path,
power_restrictions: powerRestrictions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type ValidConfig = {
rollingStockComfort: TrainScheduleBase['comfort'];
initialSpeed: number;
usingElectricalProfiles: boolean;
usingSpeedLimits: boolean;
path: TrainScheduleBase['path'];
margins: TrainScheduleBase['margins'];
schedule: TrainScheduleBase['schedule'];
Expand Down
1 change: 1 addition & 0 deletions front/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const buildOsrdConfPersistConfig = <T extends OperationalStudiesConfState | Osrd
key: slice.name,
storage,
transforms: [operationalStudiesDateTransform, pathStepsTransform],
blacklist: ['usingSpeedLimits'],
});

export const persistConfig = {
Expand Down
7 changes: 7 additions & 0 deletions front/src/reducers/osrdconf/operationalStudiesConf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type OperationalStudiesConfState = OsrdConfState & {
pathSteps: (PathStep | null)[];
constraintDistribution: Distribution;
usingElectricalProfiles: boolean;
usingSpeedLimits: boolean;
powerRestriction: PowerRestriction[];
trainCount: number;
trainStep: number;
Expand All @@ -40,6 +41,7 @@ export const operationalStudiesInitialConf: OperationalStudiesConfState = {
pathSteps: [null, null],
constraintDistribution: 'MARECO',
usingElectricalProfiles: true,
usingSpeedLimits: true,
powerRestriction: [],
trainCount: 1,
trainDelta: 15,
Expand Down Expand Up @@ -79,6 +81,7 @@ export const operationalStudiesConfSlice = createSlice({
state.initialSpeed = initial_speed ? Math.floor(msToKmh(initial_speed) * 10) / 10 : 0;

state.usingElectricalProfiles = options?.use_electrical_profiles ?? true;
state.usingSpeedLimits = options?.use_speed_limits_for_simulation ?? true;
state.labels = labels;
state.speedLimitByTag = speedLimitTag || undefined;
state.powerRestriction = power_restrictions || [];
Expand All @@ -100,13 +103,17 @@ export const operationalStudiesConfSlice = createSlice({
upsertPathStep(state.pathSteps, suggestedOp);
});
},
resetUsingSpeedLimits(state: Draft<OperationalStudiesConfState>) {
state.usingSpeedLimits = true;
},
},
});

export const operationalStudiesConfSliceActions = operationalStudiesConfSlice.actions;

export const {
selectTrainToEdit,
resetUsingSpeedLimits,

// train settings reducer
updateName,
Expand Down

0 comments on commit f310a47

Please sign in to comment.