Skip to content

Commit

Permalink
front: set stdcm margins default values in the store and add new acti…
Browse files Browse the repository at this point in the history
…on resetMargins

Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Jan 3, 2025
1 parent 177e8e8 commit 9f18376
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import { extractMarkersInfo } from 'applications/stdcm/utils';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import useInfraStatus from 'modules/pathfinding/hooks/useInfraStatus';
import { Map } from 'modules/trainschedule/components/ManageTrainSchedule';
import {
updateGridMarginAfter,
updateGridMarginBefore,
updateStandardAllowance,
type StdcmConfSliceActions,
} from 'reducers/osrdconf/stdcmConf';
import { type StdcmConfSliceActions, resetMargins } from 'reducers/osrdconf/stdcmConf';
import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors';
import { useAppDispatch } from 'store';

Expand Down Expand Up @@ -119,9 +114,7 @@ const StdcmConfig = ({

useEffect(() => {
if (!isDebugMode) {
dispatch(updateGridMarginAfter(15));
dispatch(updateGridMarginBefore(15));
dispatch(updateStandardAllowance({ type: 'time_per_distance', value: 4.5 }));
dispatch(resetMargins());
}
}, [isDebugMode]);

Expand Down
21 changes: 16 additions & 5 deletions front/src/reducers/osrdconf/stdcmConf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const stdcmConfInitialState: OsrdStdcmConfState = {
},
],
margins: {
standardAllowance: undefined,
gridMarginBefore: undefined,
gridMarginAfter: undefined,
standardAllowance: { type: 'time_per_distance', value: 4.5 },
gridMarginBefore: 15,
gridMarginAfter: 15,
},
totalMass: undefined,
totalLength: undefined,
Expand Down Expand Up @@ -107,6 +107,13 @@ export const stdcmConfSlice = createSlice({
state.stdcmPathSteps = action.payload.stdcmPathSteps;
state.speedLimitByTag = action.payload.speedLimitByTag;
},
resetMargins(state: Draft<OsrdStdcmConfState>) {
state.margins = {
standardAllowance: { type: 'time_per_distance', value: 4.5 },
gridMarginBefore: 15,
gridMarginAfter: 15,
};
},
updateStandardAllowance(
state: Draft<OsrdStdcmConfState>,
action: PayloadAction<OsrdStdcmConfState['margins']['standardAllowance']>
Expand Down Expand Up @@ -223,8 +230,12 @@ export const stdcmConfSlice = createSlice({

export const stdcmConfSliceActions = stdcmConfSlice.actions;

export const { updateGridMarginAfter, updateGridMarginBefore, updateStandardAllowance } =
stdcmConfSliceActions;
export const {
resetMargins,
updateGridMarginAfter,
updateGridMarginBefore,
updateStandardAllowance,
} = stdcmConfSliceActions;

export type StdcmConfSlice = typeof stdcmConfSlice;

Expand Down

0 comments on commit 9f18376

Please sign in to comment.