Skip to content

Commit

Permalink
front: add stop type selector in stdcm
Browse files Browse the repository at this point in the history
  • Loading branch information
Akctarus committed Sep 16, 2024
1 parent df44230 commit 8ae91ba
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 7 deletions.
6 changes: 6 additions & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@
"origin": "Origin",
"preciseTime": "precise time",
"stopFor": "Minimum stop time",
"stopType": {
"driverSwitch": "driver switch",
"passageTime":"passage time",
"serviceStop": "service stop"
},
"time": "Time",
"tolerance": "Tolerance",
"type": "Type",
"vias": "Intermediate OP"
}
}
6 changes: 6 additions & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@
"origin": "Origine",
"preciseTime": "horaire précis",
"stopFor": "Temps d'arrêt minimum",
"stopType": {
"driverSwitch": "relève conducteur",
"passageTime":"passage",
"serviceStop": "arrêt de service"
},
"time": "Heure",
"tolerance": "Tolérance",
"type": "Type",
"vias": "PR intermédiaire"
}
}
33 changes: 33 additions & 0 deletions front/src/applications/stdcmV2/components/StdcmStopType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Select } from '@osrd-project/ui-core';
import { useTranslation } from 'react-i18next';

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

type StdcmStopTypeProps = {
stopTypes: StdcmStopTypes;
onStdcmStopTypesChange: (arrivalType: StdcmStopTypes) => void;
};

const StdcmStopType = ({ stopTypes, onStdcmStopTypesChange }: StdcmStopTypeProps) => {
const { t } = useTranslation('stdcm');

return (
<div className="stdcm-v2-via-stop-for pl-2">
<Select
label={t('trainPath.type')}
id="type"
value={stopTypes}
options={['passageTime', 'driverSwitch', 'serviceStop']}
onChange={(e) => {
if (e) {
onStdcmStopTypesChange(e as StdcmStopTypes);
}
}}
getOptionLabel={(option) => t(`trainPath.stopType.${option}`)}
getOptionValue={(option) => option}
/>
</div>
);
};

export default StdcmStopType;
38 changes: 32 additions & 6 deletions front/src/applications/stdcmV2/components/StdcmVias.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo } from 'react';
import { useEffect, useMemo, useState } from 'react';

import { Location } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';
Expand All @@ -17,6 +17,8 @@ import StdcmCard from './StdcmCard';
import StdcmDefaultCard from './StdcmDefaultCard';
import StdcmInputVia from './StdcmInputVia';
import StdcmOperationalPoint from './StdcmOperationalPoint';
import StdcmStopType from './StdcmStopType';
import { StdcmStopTypes } from '../types';
import type { StdcmConfigCardProps } from '../types';

const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfigCardProps) => {
Expand All @@ -27,11 +29,21 @@ const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfig
useOsrdConfActions() as StdcmConfSliceActions;
const pathSteps = useSelector(getPathSteps);

const [stopType, setStopType] = useState<StdcmStopTypes>(StdcmStopTypes.PASSAGE_TIME);

const intermediatePoints = useMemo(() => pathSteps.slice(1, -1), [pathSteps]);

const updatePathStepsList = (pathStep: PathStep | null, index: number) => {
const newPathSteps = replaceElementAtIndex(pathSteps, index, pathStep);
if (!pathStep) return;
const updatedPathStep = {
...pathStep,
stopType,
};

const newPathSteps = replaceElementAtIndex(pathSteps, index, updatedPathStep);
dispatch(updatePathSteps({ pathSteps: newPathSteps }));

console.log(pathStep);
};

const updatePathStepStopTime = (stopTime: string, index: number) => {
Expand Down Expand Up @@ -61,6 +73,14 @@ const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfig
}));
}, [pathSteps]);

// useEffect(() => {
// if (stopType === StdcmStopTypes.DRIVER_SWITCH) {
// setStopTypeTime('PT180S');
// } else if (stopType === StdcmStopTypes.SERVICE_STOP) {
// setStopTypeTime('PT60S');
// }
// }, [stopType]);

return (
<div className="stdcm-v2-vias-list">
{intermediatePoints.length > 0 &&
Expand Down Expand Up @@ -100,10 +120,16 @@ const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfig
/>
</div>
{pathStep && (
<StdcmInputVia
pathStep={pathStep}
updatePathStepStopTime={(e) => updatePathStepStopTime(e, pathStepIndex)}
/>
<>
<StdcmStopType stopTypes={stopType} onStdcmStopTypesChange={setStopType} />
{(stopType === StdcmStopTypes.DRIVER_SWITCH ||
stopType === StdcmStopTypes.SERVICE_STOP) && (
<StdcmInputVia
pathStep={pathStep}
updatePathStepStopTime={(e) => updatePathStepStopTime(e, pathStepIndex)}
/>
)}
</>
)}
</StdcmCard>
</>
Expand Down
6 changes: 6 additions & 0 deletions front/src/applications/stdcmV2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ export type StdcmConfigErrors = {
errorType: StdcmConfigErrorTypes;
errorDetails?: { originTime: string; destinationTime: string };
};

export enum StdcmStopTypes {
PASSAGE_TIME = 'passageTime',
DRIVER_SWITCH = 'driverSwitch',
SERVICE_STOP = 'serviceStop',
}
3 changes: 2 additions & 1 deletion front/src/reducers/osrdconf/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Feature, Position } from 'geojson';

import type { PowerRestriction } from 'applications/operationalStudies/types';
import type { AllowanceValue } from 'applications/stdcm/types';
import type { ArrivalTimeTypes } from 'applications/stdcmV2/types';
import type { ArrivalTimeTypes, StdcmStopTypes } from 'applications/stdcmV2/types';
import type { Comfort, Distribution, PathItemLocation } from 'common/api/osrdEditoastApi';
import type { InfraState } from 'reducers/infra';

Expand Down Expand Up @@ -61,6 +61,7 @@ export type PathStep = PathItemLocation & {
arrivalToleranceAfter?: number;
locked?: boolean;
stopFor?: string | null;
stopType?: StdcmStopTypes;
theoreticalMargin?: string;
onStopSignal?: boolean;
kp?: string;
Expand Down

0 comments on commit 8ae91ba

Please sign in to comment.