Skip to content

Commit

Permalink
front: use OperationalStudiesConfState instead of OsrdConfState
Browse files Browse the repository at this point in the history
Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Dec 31, 2024
1 parent dec7e30 commit 980149c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { Dispatch } from 'redux';
import getStepLocation from 'modules/pathfinding/helpers/getStepLocation';
import type { ValidConfig } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import { setFailure } from 'reducers/main';
import type { OsrdConfState } from 'reducers/osrdconf/types';
import type { OperationalStudiesConfState } from 'reducers/osrdconf/operationalStudiesConf';
import { isInvalidFloatNumber } from 'utils/numbers';
import { kmhToMs } from 'utils/physics';

import formatMargin from './formatMargin';
import formatSchedule from './formatSchedule';

const checkCurrentConfig = (
osrdconf: OsrdConfState,
osrdconf: OperationalStudiesConfState,
t: (arg0: string) => string,
dispatch: Dispatch,
// TODO TS2 : remove this when rollingStockName will replace rollingStockId in the store
Expand Down
13 changes: 7 additions & 6 deletions front/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import type { MapViewerState, MapViewerSlice } from 'reducers/mapViewer';
import mapViewerReducer, { mapViewerInitialState, mapViewerSlice } from 'reducers/mapViewer';
import operationalStudiesConfReducer, {
operationalStudiesConfSlice,
type OperationalStudiesConfState,
} from 'reducers/osrdconf/operationalStudiesConf';
import stdcmConfReducer, {
stdcmConfInitialState,
stdcmConfSlice,
} from 'reducers/osrdconf/stdcmConf';
import type { OsrdConfState, OsrdStdcmConfState } from 'reducers/osrdconf/types';
import type { OsrdStdcmConfState } from 'reducers/osrdconf/types';
import simulationReducer, {
simulationResultsInitialState,
simulationResultsSlice,
Expand Down Expand Up @@ -79,7 +80,7 @@ const operationalStudiesDateTransform = createTransform(
);

// Useful to only blacklist a sub-propertie of osrdconf
const buildOsrdConfPersistConfig = <T extends OsrdConfState>(
const buildOsrdConfPersistConfig = <T extends OperationalStudiesConfState | OsrdStdcmConfState>(
slice: ConfSlice
): PersistConfig<T> => ({
key: slice.name,
Expand All @@ -106,7 +107,7 @@ export interface RootState {
[editorSlice.name]: EditorState;
[mainSlice.name]: MainState;
[stdcmConfSlice.name]: OsrdStdcmConfState;
[operationalStudiesConfSlice.name]: OsrdConfState;
[operationalStudiesConfSlice.name]: OperationalStudiesConfState;
[simulationResultsSlice.name]: SimulationResultsState;
[osrdEditoastApi.reducerPath]: ReturnType<typeof osrdEditoastApi.reducer>;
[osrdGatewayApi.reducerPath]: ReturnType<typeof osrdGatewayApi.reducer>;
Expand All @@ -132,7 +133,7 @@ export type AnyReducerState =
| EditorState
| MainState
| OsrdStdcmConfState
| OsrdConfState
| OperationalStudiesConfState
| SimulationResultsState;

export const rootReducer: ReducersMapObject<RootState> = {
Expand All @@ -146,9 +147,9 @@ export const rootReducer: ReducersMapObject<RootState> = {
stdcmConfReducer
) as unknown as Reducer<OsrdStdcmConfState, AnyAction>,
[operationalStudiesConfSlice.name]: persistReducer(
buildOsrdConfPersistConfig<OsrdConfState>(operationalStudiesConfSlice),
buildOsrdConfPersistConfig<OperationalStudiesConfState>(operationalStudiesConfSlice),
operationalStudiesConfReducer
) as unknown as Reducer<OsrdConfState, AnyAction>,
) as unknown as Reducer<OperationalStudiesConfState, AnyAction>,
[simulationResultsSlice.name]: simulationReducer,
[osrdEditoastApi.reducerPath]: osrdEditoastApi.reducer,
[osrdGatewayApi.reducerPath]: osrdGatewayApi.reducer,
Expand Down
7 changes: 4 additions & 3 deletions front/src/reducers/osrdconf/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { pathStepMatchesOp } from 'modules/pathfinding/utils';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import { addElementAtIndex } from 'utils/array';

import type { OsrdConfState, PathStep } from './types';
import type { OperationalStudiesConfState } from './operationalStudiesConf';
import type { PathStep } from './types';

export const insertViaFromMap = (
pathSteps: OsrdConfState['pathSteps'],
pathSteps: OperationalStudiesConfState['pathSteps'],
newVia: PathStep,
pathProperties: ManageTrainSchedulePathProperties
): OsrdConfState['pathSteps'] => {
): OperationalStudiesConfState['pathSteps'] => {
// If one of these is missing, via is not valid (it hasn't been added via click on map) and we return the same array
if (!('track' in newVia) || !newVia.coordinates) return pathSteps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { compact, isEqual, keyBy, sortBy } from 'lodash';

import type { PowerRestriction } from 'applications/operationalStudies/types';
import { NO_POWER_RESTRICTION } from 'modules/powerRestriction/consts';
import type { OsrdConfState, PathStep } from 'reducers/osrdconf/types';
import type { PathStep } from 'reducers/osrdconf/types';
import { addElementAtIndex } from 'utils/array';

import type { OperationalStudiesConfState } from '.';
import { addPathStep, cleanPathSteps, isRangeCovered, updateRestrictions } from './utils';

export type PowerRestrictionReducer<S extends OsrdConfState> = {
export type PowerRestrictionReducer<S extends OperationalStudiesConfState> = {
['updatePowerRestrictionRanges']: CaseReducer<S, PayloadAction<PowerRestriction[]>>;
['upsertPowerRestrictionRanges']: CaseReducer<
S,
Expand All @@ -35,7 +36,9 @@ export type PowerRestrictionReducer<S extends OsrdConfState> = {
>;
};

export function builPowerRestrictionReducer<S extends OsrdConfState>(): PowerRestrictionReducer<S> {
export function builPowerRestrictionReducer<
S extends OperationalStudiesConfState,
>(): PowerRestrictionReducer<S> {
return {
updatePowerRestrictionRanges(state: Draft<S>, action: PayloadAction<PowerRestriction[]>) {
state.powerRestriction = action.payload;
Expand Down
11 changes: 7 additions & 4 deletions front/src/reducers/osrdconf/operationalStudiesConf/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { operationalStudiesConfSlice } from 'reducers/osrdconf/operationalStudiesConf';
import {
operationalStudiesConfSlice,
type OperationalStudiesConfState,
} from 'reducers/osrdconf/operationalStudiesConf';
import buildCommonConfSelectors from 'reducers/osrdconf/osrdConfCommon/selectors';

import type { OsrdConfState } from '../types';

const buildOperationalStudiesConfSelectors = () => {
const commonConfSelectors = buildCommonConfSelectors<OsrdConfState>(operationalStudiesConfSlice);
const commonConfSelectors = buildCommonConfSelectors<OperationalStudiesConfState>(
operationalStudiesConfSlice
);
return {
...commonConfSelectors,
};
Expand Down
4 changes: 2 additions & 2 deletions front/src/reducers/osrdconf/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
import type { IsoDurationString } from 'common/types';
import type { InfraState } from 'reducers/infra';

export interface OsrdConfState extends InfraState {
export type OsrdConfState = InfraState & {
constraintDistribution: Distribution;
name: string;
trainCount: number;
Expand All @@ -42,7 +42,7 @@ export interface OsrdConfState extends InfraState {
pathSteps: (PathStep | null)[];
rollingStockComfort: Comfort;
startTime: Date;
}
};

export interface StandardAllowance {
type: AllowanceValue['value_type'];
Expand Down

0 comments on commit 980149c

Please sign in to comment.