Skip to content

Commit

Permalink
front: enhance lmr report sheet and fix linked paths
Browse files Browse the repository at this point in the history
Signed-off-by: Achraf Mohyeddine <[email protected]>
  • Loading branch information
achrafmohye committed Dec 23, 2024
1 parent 3042c47 commit 205ed74
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 5 deletions.
3 changes: 2 additions & 1 deletion front/public/locales/en/stdcm-simulation-report-sheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"passageStop": "passage",
"refEngine": "Ref. engine",
"referenceEngine": "reference engine",
"simulationStopType": "Type d'arrêt",
"requestedRoute": "requested route",
"scheduledArrival": "scheduled arrival on {{date}} at {{time}}",
"scheduledDeparture": "scheduled departure on {{date}} at {{time}}",
"serviceStop": "Service stop",
"simulation": "Simulation",
"speedLimitByTag": "speed limit by tag",
"startStop": "start",
"stdcm": "ST DCM",
"stdcm": "LMR",
"stdcmCreation": "short term path creation",
"stopType": "motif",
"towedMaterial": "towed material",
Expand Down
3 changes: 2 additions & 1 deletion front/public/locales/fr/stdcm-simulation-report-sheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
"passageStop": "passage",
"refEngine": "Engin de réf.",
"referenceEngine": "engin de référence",
"simulationStopType": "Type d'arrêt",
"requestedRoute": "parcours demandé",
"scheduledArrival": "arrivée prévue le {{date}} à {{time}}",
"scheduledDeparture": "départ prévu le {{date}} à {{time}}",
"serviceStop": "Arrêt de service",
"simulation": "Simulation",
"speedLimitByTag": "code de composition",
"startStop": "départ",
"stdcm": "ST DCM",
"stdcm": "LMR",
"stdcmCreation": "Création de sillon de dernière minute",
"stopType": "motif",
"towedMaterial": "matériel remorqué",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { useState, type ReactNode } from 'react';
import { DatePicker, Input } from '@osrd-project/ui-core';
import { Gear } from '@osrd-project/ui-icons';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';

import useLinkedPathSearch from 'applications/stdcm/hooks/useLinkedPathSearch';
import { useOsrdConfActions } from 'common/osrdContext';
import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf';

import StdcmCard from './StdcmCard';
import StdcmDefaultCard from './StdcmDefaultCard';
Expand All @@ -29,7 +32,9 @@ const StdcmLinkedPathSearch = ({
linkedOp,
}: StdcmLinkedPathSearchProps) => {
const { t } = useTranslation('stdcm');
const dispatch = useDispatch();
const [displayLinkedPathSearch, setShowLinkedPathSearch] = useState(false);
const { resetLinkedPathResults } = useOsrdConfActions() as StdcmConfSliceActions;

const {
displaySearchButton,
Expand All @@ -42,8 +47,16 @@ const StdcmLinkedPathSearch = ({
setLinkedPathDate,
setTrainNameInput,
trainNameInput,
setLinkedPathResults,
} = useLinkedPathSearch();

const handleResetLinkedPathSearch = () => {
setShowLinkedPathSearch(false);
dispatch(resetLinkedPathResults(linkedOp.extremityType));
setLinkedPathResults([]);
setTrainNameInput('');
};

return (
<div className={`stdcm-linked-path-search-container ${className}`}>
{!displayLinkedPathSearch ? (
Expand All @@ -59,7 +72,7 @@ const StdcmLinkedPathSearch = ({
disabled={disabled}
name={cardName}
title={
<button type="button" onClick={() => setShowLinkedPathSearch(false)}>
<button type="button" onClick={handleResetLinkedPathSearch}>
{t('translation:common.delete').toLowerCase()}
</button>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { capitalizeFirstLetter } from 'utils/strings';
import { secToMin } from 'utils/timeManipulation';

import styles from './SimulationReportStyleSheet';
import type { SimulationReportSheetProps } from '../../types';
import type { SimulationReportSheetProps, StdcmResultsOperationalPoint } from '../../types';
import { getStopDurationTime } from '../../utils/formatSimulationReportSheet';

const SimulationReportSheet = ({
Expand Down Expand Up @@ -46,6 +46,20 @@ const SimulationReportSheet = ({
return '';
};

const getStopTypeLabel = (
isFirstStep: boolean,
isLastStep: boolean,
step: StdcmResultsOperationalPoint
) => {
if (isFirstStep || isLastStep) {
return t('serviceStop');
}
if (step?.stopType) {
return capitalizeFirstLetter(t(`stdcm:trainPath.stopType.${step.stopType}`));
}
return '';
};

return (
<Document>
<Page wrap={false} style={styles.main.page} size={[1344]}>
Expand Down Expand Up @@ -295,6 +309,9 @@ const SimulationReportSheet = ({
<View style={styles.simulation.refEngineWidth}>
<TD>{t('referenceEngine')}</TD>
</View>
<View style={styles.simulation.refEngineWidth}>
<TD>{t('simulationStopType')}</TD>
</View>
</TH>
{operationalPointsList.map((step, index) => {
const isFirstStep = index === 0;
Expand Down Expand Up @@ -405,6 +422,11 @@ const SimulationReportSheet = ({
{!isFirstStep ? '=' : rollingStock.metadata?.reference}
</TD>
</View>
<View style={styles.simulation.refEngineWidth}>
<TD style={tdPassageStopStyle}>
{getStopTypeLabel(isFirstStep, isLastStep, step)}
</TD>
</View>
</TR>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const StcdmResults = ({
return getOperationalPointsWithTimes(
outputs.pathProperties?.suggestedOperationalPoints || [],
outputs.results.simulation,
outputs.results.simulationPathSteps,
outputs.results.departure_time
);
}, [outputs]);
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/hooks/useLinkedPathSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const useLinkedPathSearch = () => {
setLinkedPathDate,
setTrainNameInput,
trainNameInput,
setLinkedPathResults,
};
};

Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export type StdcmResultsOperationalPoint = {
departureTime: string;
stopEndTime: string;
trackName?: string;
stopType?: string;
};

export type StdcmResults = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { SimulationResponse } from 'common/api/osrdEditoastApi';
import { matchPathStepAndOp } from 'modules/pathfinding/utils';
import { interpolateValue } from 'modules/simulationResult/SimulationResultExport/utils';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { PathStep } from 'reducers/osrdconf/types';

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

Expand Down Expand Up @@ -112,6 +114,7 @@ export function getStopDurationBetweenTwoPositions(
export function getOperationalPointsWithTimes(
operationalPoints: SuggestedOP[],
simulation: Extract<SimulationResponse, { status: 'success' }>,
pathSteps: PathStep[],
departureTime: string
): StdcmResultsOperationalPoint[] {
const { positions, times } = simulation.final_output;
Expand All @@ -121,7 +124,10 @@ export function getOperationalPointsWithTimes(
const [departureHour, departureMinute] = pathDepartureTime.split(':').map(Number);

// Map operational points with their positions, times, and stop durations
const opResults = operationalPoints.map((op) => {
const opResults = operationalPoints.map((op, index) => {
const isFirst = index === 0;
const isLast = index === operationalPoints.length - 1;

const formattedTime = getTimeAtPosition(
op.positionOnPath,
positions,
Expand All @@ -135,6 +141,10 @@ export function getOperationalPointsWithTimes(
const durationToString = secondsToTimeString(durationInSeconds);
const stopEndTime = computeStopDepartureTime(formattedTime, durationToString);

// Find the corresponding stopType from pathSteps
const correspondingStep = pathSteps.find((step) => step && matchPathStepAndOp(step, op));
const stopType = isFirst || isLast ? 'serviceStop' : correspondingStep?.stopType;

return {
opId: op.opId!,
positionOnPath: op.positionOnPath,
Expand All @@ -145,6 +155,7 @@ export function getOperationalPointsWithTimes(
departureTime,
stopEndTime,
trackName: op.metadata?.trackName,
stopType,
};
});

Expand Down
13 changes: 13 additions & 0 deletions front/src/reducers/osrdconf/stdcmConf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const stdcmConfSlice = createSlice({
state.totalMass = stdcmConfInitialState.totalMass;
state.maxSpeed = stdcmConfInitialState.maxSpeed;
state.speedLimitByTag = stdcmConfInitialState.speedLimitByTag;
state.linkedPaths = stdcmConfInitialState.linkedPaths;
},
updateTotalMass(
state: Draft<OsrdStdcmConfState>,
Expand Down Expand Up @@ -171,6 +172,18 @@ export const stdcmConfSlice = createSlice({
(pathStep) => pathStep.id !== action.payload
);
},
resetLinkedPathResults(
state: Draft<OsrdStdcmConfState>,
action: PayloadAction<ExtremityPathStepType>
) {
const extremityPathStep = action.payload;

if (extremityPathStep === 'destination') {
state.linkedPaths.anteriorPath = undefined;
} else {
state.linkedPaths.posteriorPath = undefined;
}
},
updateLinkedPathStep(
state: Draft<OsrdStdcmConfState>,
action: PayloadAction<{
Expand Down

0 comments on commit 205ed74

Please sign in to comment.