Skip to content

Commit

Permalink
front: separate stdcm and operationnal studies
Browse files Browse the repository at this point in the history
- move MODES, DEFAULT_MODE and associated types from operationnalStudies/consts.ts to main/consts.ts
- move OsrdConfState and OsrdStdcmConfState from operationnalStudies/consts.ts to reducers/osrdconf/consts.ts
- move RUNTIME_CAP from operationnalStudies/consts.ts to stdcm/consts.ts
- move allowancesConsts.ts from applications/stdcm to modules/stdcmAllowances
- update imports, add type keyword when needed
  • Loading branch information
Yohh committed Jan 17, 2024
1 parent 4b7a478 commit 55d4edd
Show file tree
Hide file tree
Showing 30 changed files with 136 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"addVias": "Add waypoints",
"addTrainSchedule": "Add one or several trains",
"apply": "Apply",
"blocktype": "Signalling block type",
"BoundsAreLinked": "Both bounds are linked",
"BoundsAreNotLinked": "Both bounds are not linked",
"returnToSimulationResults": "Go back to simulation results",
"cancelPathfinding": "Cancel",
"cancelRequest": "Cancel request",
"chooseOnMap": "Choose on the map",
"composition": "Composition",
"deleteVias": "Delete steps",
Expand All @@ -33,8 +31,6 @@
"noTrainStep": "The increment step of the train must be greater than zero",
"noTrainStepInput": "Must be > 0",
"softErrorInfra": "The application is unavailable, a server error has occurred, please try again later.",
"stdcmError": "Calculation error for last minute train path.",
"stdcmErrorNoPaths": "Incompatibility with other train paths.",
"The requested train couldn't reach its destination": "The train cannot reach its destination",
"trainScheduleTitle": "An error has occurred",
"unableToDeleteTrain": "Impossible to delete the train",
Expand Down Expand Up @@ -79,19 +75,13 @@
"pathfindingMissingParamsSimple": "Missing information for the search",
"pathfindingNoState": "No route search.",
"pathfindingStatus": "Pathfinding state",
"pleaseWait": "Please wait…",
"powerRestriction": "Power restriction code",
"powerRestrictionExplanationText": "By default, the simulation will use the nominal power.",
"powerRestrictionEmptyExplanationText": "The selected rolling stock does not have any power restrictions. You can edit it in the rolling stock editor.",
"restartPathfinding": "Restart search",
"rollingstock": "Rolling stock",
"simulation": "Simulation",
"spaceSpeedGraphic": "Space-Velocity graph",
"spaceTimeGraphic": "Space-Time graph",
"speedLimitByTag": "Composition code",
"stdcmComputation": "Search for a train path",
"stdcmNoResults": "No path found",
"stdcmResults": "Results",
"stopSimulation": "Stop",
"tabs": {
"rollingStock": "Rolling stock",
Expand Down
12 changes: 12 additions & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"apply": "Apply",
"cancelRequest": "Cancel request",
"pleaseWait": "Please wait…",
"spaceSpeedGraphic": "Space-Velocity graph",
"spaceTimeGraphic": "Space-Time graph",
"stdcmComputation": "Search for a train path",
"stdcmError": "Calculation error for last minute train path.",
"stdcmErrorNoPaths": "Incompatibility with other train paths.",
"stdcmNoResults": "No path found",
"stdcmResults": "Results"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{
"addVias": "Ajout de vias",
"addTrainSchedule": "Ajouter un ou plusieurs trains",
"apply": "Appliquer",
"blocktype": "Type de block",
"BoundsAreLinked": "Les deux bornes sont liées",
"BoundsAreNotLinked": "Les deux bornes ne sont pas liées",
"returnToSimulationResults": "Retourner aux résultats de simulation",
"cancelPathfinding": "Annuler",
"cancelRequest": "Annuler la requête",
"chooseOnMap": "Choisir sur la carte",
"composition": "Composition",
"deleteRoute": "Supprimer l'itinéraire",
Expand All @@ -33,8 +30,6 @@
"noTrainStep": "Le pas d'incrément du nom du train doit être supérieur à zéro",
"noTrainStepInput": "Doit être > 0",
"softErrorInfra": "L'application est indisponible, une erreur serveur est survenue, veuillez réessayer ultérieurement.",
"stdcmError": "Erreur de calcul Sillon de dernière minute",
"stdcmErrorNoPaths": "Incompatibilité avec d'autres sillons.",
"The requested train couldn't reach its destination": "Le train ne peut pas atteindre sa destination",
"trainScheduleTitle": "Une erreur est survenue",
"unableToDeleteTrain": "Impossible de supprimer le train",
Expand Down Expand Up @@ -86,12 +81,7 @@
"restartPathfinding": "Relancer la recherche",
"rollingstock": "Matériel",
"simulation": "Simulation",
"spaceSpeedGraphic": "Graphique Espace-Vitesse",
"spaceTimeGraphic": "Graphique Espace-Temps",
"speedLimitByTag": "Code de composition",
"stdcmComputation": "Recherche de sillon",
"stdcmNoResults": "Aucun sillon trouvé",
"stdcmResults": "Résultats",
"stopSimulation": "Stopper",
"tabs": {
"rollingStock": "Matériel",
Expand Down
12 changes: 12 additions & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"apply": "Appliquer",
"cancelRequest": "Annuler la requête",
"pleaseWait": "Veuillez patientez…",
"spaceSpeedGraphic": "Graphique Espace-Vitesse",
"spaceTimeGraphic": "Graphique Espace-Temps",
"stdcmComputation": "Recherche de sillon",
"stdcmError": "Erreur de calcul Sillon de dernière minute",
"stdcmErrorNoPaths": "Incompatibilité avec d'autres sillons.",
"stdcmNoResults": "Aucun sillon trouvé",
"stdcmResults": "Résultats"
}
70 changes: 1 addition & 69 deletions front/src/applications/operationalStudies/consts.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import i18n from 'i18n';
import { Position, Feature } from 'geojson';
import { Position } from 'geojson';
import {
AllowanceValue,
RollingStockComfortType,
ElectrificationRange,
ElectrificationUsage,
PathResponse,
PowerRestrictionRangeItem,
} from 'common/api/osrdEditoastApi';
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
import { HeightPosition } from 'reducers/osrdsimulation/types';
import { AllowanceForm } from 'modules/trainschedule/components/ManageTrainSchedule/Allowances/types';
import { InfraState } from 'reducers/infra';

export const BLOCKTYPES = [
{
Expand Down Expand Up @@ -80,24 +75,6 @@ export const MANAGE_TRAIN_SCHEDULE_TYPES = Object.freeze({
import: 'IMPORT',
});

interface MODES_Types {
[n: string]: string;
}

export const MODES: MODES_Types = Object.freeze({
simulation: 'SIMULATION',
stdcm: 'STDCM',
editor: 'EDITOR',
mapViewer: 'MAP_VIEWER',
});

export const DEFAULT_MODE = MODES.simulation;

export interface StandardAllowance {
type: AllowanceValue['value_type'];
value: number;
}

export interface PointOnMap {
id?: string;
name?: string;
Expand Down Expand Up @@ -150,51 +127,6 @@ export const studyTypes = Object.keys(STUDY_TYPES) as StudyType[];

export type PowerRestrictionRange = LinearMetadataItem<{ value: string }>;

export interface OsrdConfState extends InfraState {
rollingStockComfort: RollingStockComfortType;
name: string;
trainCount: number;
trainStep: number;
trainDelta: number;
allowances: AllowanceForm[];
usingElectricalProfiles: boolean;
labels: string[];
projectID?: number;
studyID?: number;
scenarioID?: number;
pathfindingID?: number;
timetableID?: number;
rollingStockID?: number;
speedLimitByTag?: string;
// TODO: update the call to the api, to rename the fields begin & end -> begin_position & end_position
powerRestrictionRanges: PowerRestrictionRange[];
origin?: PointOnMap;
initialSpeed?: number;
departureTime: string;
destination?: PointOnMap;
vias: PointOnMap[];
suggeredVias: PathResponse['steps'] | PointOnMap[];
geojson?: PathResponse;
originDate?: string;
originTime?: string;
originUpperBoundDate?: string;
originUpperBoundTime?: string;
originLinkedBounds: boolean;
destinationDate?: string;
destinationTime?: string;
gridMarginBefore?: number;
gridMarginAfter?: number;
trainScheduleIDsToModify: number[];
featureInfoClick: { displayPopup: boolean; feature?: Feature; coordinates?: number[] };
}

export interface OsrdStdcmConfState extends OsrdConfState {
maximumRunTime: number;
standardStdcmAllowance?: StandardAllowance;
}

export const RUNTIME_CAP = 43200;

// electrical profiles
interface Profile {
mode: string;
Expand Down
3 changes: 1 addition & 2 deletions front/src/applications/stdcm/components/RunningTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { noop } from 'lodash';

import { sec2time, time2sec } from 'utils/timeManipulation';

import { RUNTIME_CAP } from 'applications/operationalStudies/consts';

import InputSNCF from 'common/BootstrapSNCF/InputSNCF';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';

import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf';
import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors';
import { RUNTIME_CAP } from 'applications/stdcm/consts';

interface RunningTimeProps {
dispatch?: Dispatch;
Expand Down
2 changes: 2 additions & 0 deletions front/src/applications/stdcm/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ const STDCM_REQUEST_STATUS = Object.freeze({
});

export default STDCM_REQUEST_STATUS;

export const RUNTIME_CAP = 43200;
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { PathfindingRequest } from 'common/api/osrdEditoastApi';

import { time2sec } from 'utils/timeManipulation';

import { createAllowanceValue } from 'applications/stdcm/components/allowancesConsts';
import type { OsrdStdcmConfState } from 'applications/operationalStudies/consts';

import { getPathfindingQuery } from 'common/Pathfinding/Pathfinding';
import type { PostStdcmApiArg } from 'common/api/osrdEditoastApi';

import { setFailure } from 'reducers/main';
import type { InfraState } from 'reducers/infra';
import type { OsrdStdcmConfState } from 'reducers/osrdconf/consts';
import { createAllowanceValue } from 'modules/stdcmAllowances/allowancesConsts';

export default function formatStdcmConf(
dispatch: Dispatch,
Expand Down
12 changes: 4 additions & 8 deletions front/src/applications/stdcm/views/OSRDStdcmConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import STDCM_REQUEST_STATUS from 'applications/stdcm/consts';
import type { StdcmRequestStatus } from 'applications/stdcm/types';
import RunningTime from 'applications/stdcm/components/RunningTime';
import OSRDStdcmResults from 'applications/stdcm/views/OSRDStdcmResults';
import type { OsrdStdcmConfState } from 'applications/operationalStudies/consts';

import StdcmAllowances from 'modules/stdcmAllowances/components/StdcmAllowances';
import { Itinerary, Map } from 'modules/trainschedule/components/ManageTrainSchedule';
Expand All @@ -18,6 +17,7 @@ import ScenarioExplorer from 'modules/scenario/components/ScenarioExplorer';
import SpeedLimitByTagSelector from 'common/SpeedLimitByTagSelector/SpeedLimitByTagSelector';

import { getSelectedTrain } from 'reducers/osrdsimulation/selectors';
import type { OsrdStdcmConfState } from 'reducers/osrdconf/consts';

type OSRDStdcmConfigProps = {
currentStdcmRequestStatus: string;
Expand All @@ -41,11 +41,7 @@ export default function OSRDConfig({

const osrdconf: OsrdStdcmConfState = useSelector(getConf) as OsrdStdcmConfState;

const { t } = useTranslation([
'translation',
'operationalStudies/manageTrainSchedule',
'simulation',
]);
const { t } = useTranslation(['translation', 'stdcm', 'simulation']);

const { data: infra } = osrdEditoastApi.useGetInfraByIdQuery(
{ id: infraID as number },
Expand Down Expand Up @@ -111,9 +107,9 @@ export default function OSRDConfig({
setCurrentStdcmRequestStatus(STDCM_REQUEST_STATUS.pending);
}}
>
{t('operationalStudies/manageTrainSchedule:apply')}
{t('stdcm:apply')}
<span className="sr-only" aria-hidden="true">
{t('operationalStudies/manageTrainSchedule:apply')}
{t('stdcm:apply')}
</span>
</button>
</div>
Expand Down
8 changes: 3 additions & 5 deletions front/src/applications/stdcm/views/OSRDStdcmResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AllowancesSettings } from 'reducers/osrdsimulation/types';
import { SimulationReport } from 'common/api/osrdEditoastApi';

const OSRDStcdmResults = () => {
const { t } = useTranslation(['translation', 'operationalStudies/manageTrainSchedule']);
const { t } = useTranslation(['translation', 'stdcm']);

const selectedTrain = useSelector(getSelectedTrain);
const simulation = useSelector(getPresentSimulation);
Expand Down Expand Up @@ -44,9 +44,7 @@ const OSRDStcdmResults = () => {
<div className="osrd-simulation-container mb-2 simulation-results">
<div className="osrd-config-item mb-2">
<div className="osrd-simulation-container mb-2">
<p className="mt-2 mb-3 ml-4 font-weight-bold">
{t('operationalStudies/manageTrainSchedule:spaceTimeGraphic')}
</p>
<p className="mt-2 mb-3 ml-4 font-weight-bold">{t('stdcm:spaceTimeGraphic')}</p>
<div className="chart-container mt-2" style={{ height: `${spaceTimeChartHeight}px` }}>
<SpaceTimeChart
allowancesSettings={allowancesSettings}
Expand All @@ -62,7 +60,7 @@ const OSRDStcdmResults = () => {
className="btn d-flex align-items-center mb-1 font-weight-bold"
onClick={() => setShowSpeedSpaceChart(!showSpeedSpaceChart)}
>
{t('operationalStudies/manageTrainSchedule:spaceSpeedGraphic')}
{t('stdcm:spaceSpeedGraphic')}
<i
className={
showSpeedSpaceChart ? 'icons-arrow-up ml-auto' : 'icons-arrow-down ml-auto'
Expand Down
26 changes: 10 additions & 16 deletions front/src/applications/stdcm/views/StdcmRequestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ModalHeaderSNCF from 'common/BootstrapSNCF/ModalSNCF/ModalHeaderSNCF';
import ReactModal from 'react-modal';
// OSRD helpers
import createTrain from 'modules/simulationResult/components/SpaceTimeChart/createTrain';
import formatStdcmConf from 'applications/stdcm/formatStcmConf';
import formatStdcmConf from 'applications/stdcm/formatStdcmConf';
// Static Data and Assets
import { setFailure } from 'reducers/main';
import STDCM_REQUEST_STATUS from 'applications/stdcm/consts';
Expand All @@ -28,19 +28,15 @@ import type { StdcmRequestStatus } from 'applications/stdcm/types';
import { extractMessageFromError, extractStatusFromError } from 'utils/error';
import { Train } from 'reducers/osrdsimulation/types';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import type { OsrdStdcmConfState } from 'applications/operationalStudies/consts';
import type { OsrdStdcmConfState } from 'reducers/osrdconf/consts';

type StdcmRequestModalProps = {
setCurrentStdcmRequestStatus: (currentStdcmRequestStatus: StdcmRequestStatus) => void;
currentStdcmRequestStatus: StdcmRequestStatus;
};

export default function StdcmRequestModal(props: StdcmRequestModalProps) {
const { t } = useTranslation([
'translation',
'operationalStudies/manageTrainSchedule',
'translation',
]);
const { t } = useTranslation(['translation', 'stdcm']);
const { getConf } = useOsrdConfSelectors();
const osrdconf = useSelector(getConf);
const dispatch = useDispatch();
Expand Down Expand Up @@ -103,7 +99,7 @@ export default function StdcmRequestModal(props: StdcmRequestModalProps) {
.catch(() => {
dispatch(
setFailure({
name: t('operationalStudies/manageTrainSchedule:errorMessages.stdcmError'),
name: t('stdcm:stdcmError'),
message: t('translation:common.error'),
})
);
Expand All @@ -115,10 +111,10 @@ export default function StdcmRequestModal(props: StdcmRequestModalProps) {
setCurrentStdcmRequestStatus(STDCM_REQUEST_STATUS.rejected);
dispatch(
setFailure({
name: t('operationalStudies/manageTrainSchedule:errorMessages.stdcmError'),
name: t('stdcm:stdcmError'),
message:
extractStatusFromError(e) === 400 && errorMessage === 'No path could be found'
? t('operationalStudies/manageTrainSchedule:errorMessages.stdcmErrorNoPaths')
? t('stdcm:stdcmErrorNoPaths')
: errorMessage,
})
);
Expand Down Expand Up @@ -154,15 +150,13 @@ export default function StdcmRequestModal(props: StdcmRequestModalProps) {
<div className="modal-dialog" role="document">
<div className="modal-content">
<ModalHeaderSNCF>
<h1>{t('operationalStudies/manageTrainSchedule:stdcmComputation')}</h1>
<h1>{t('stdcm:stdcmComputation')}</h1>
</ModalHeaderSNCF>
<ModalBodySNCF>
<div className="d-flex flex-column text-center">
{currentStdcmRequestStatus === STDCM_REQUEST_STATUS.pending && (
<div className="d-flex align-items-center justify-content-center mb-3">
<span className="mr-2">
{t('operationalStudies/manageTrainSchedule:pleaseWait')}
</span>
<span className="mr-2">{t('stdcm:pleaseWait')}</span>
<Spinner />
</div>
)}
Expand All @@ -173,9 +167,9 @@ export default function StdcmRequestModal(props: StdcmRequestModalProps) {
type="button"
onClick={cancelStdcmRequest}
>
{t('operationalStudies/manageTrainSchedule:cancelRequest')}
{t('stdcm:cancelRequest')}
<span className="sr-only" aria-hidden="true">
{t('operationalStudies/manageTrainSchedule:cancelRequest')}
{t('stdcm:cancelRequest')}
</span>
</button>
</div>
Expand Down
Loading

0 comments on commit 55d4edd

Please sign in to comment.