Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: fix stop types in stdcm table results and simulation report sheet #9098

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 99 additions & 71 deletions front/src/applications/stdcm/components/SimulationReportSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useTranslation } from 'react-i18next';

import iconAlert from 'assets/simulationReportSheet/icon_alert_fill.png';
import logoSNCF from 'assets/simulationReportSheet/logo_sncf_reseau.png';
import { formatDateToString, formatDay } from 'utils/date';
import type { PathStep } from 'reducers/osrdconf/types';
import { extractHHMM, formatDateToString, formatDay } from 'utils/date';
import { capitalizeFirstLetter } from 'utils/strings';

import styles from './SimulationReportStyleSheet';
Expand Down Expand Up @@ -56,6 +57,19 @@ const SimulationReportSheet = ({
[mapImageUrl]
);

const getArrivalTime = (
clarani marked this conversation as resolved.
Show resolved Hide resolved
step: PathStep,
{ isFirstStep, isLastStep }: { isFirstStep?: boolean; isLastStep?: boolean }
) => {
if (isFirstStep || isLastStep) {
if (step.arrival && step.arrivalType === 'preciseTime') {
return extractHHMM(step.arrival);
}
return t('asap');
}
return '';
};

return (
<Document>
<Page wrap={false} style={styles.main.page} size={[1344]}>
Expand Down Expand Up @@ -163,56 +177,46 @@ const SimulationReportSheet = ({
<TD>{t('stopType')}</TD>
</View>
</TH>
{operationalPointsList.map((step, index) => {
{stdcmData.simulationPathSteps.map((step, index) => {
const isFirstStep = index === 0;
const isLastStep = index === operationalPointsList.length - 1;
const shouldRenderRow =
isFirstStep ||
step.duration > 0 ||
stdcmData.simulationPathSteps[renderedIndex].stopType === 'passageTime' ||
isLastStep;
if (shouldRenderRow) {
renderedIndex += 1;
return (
<TR key={index} style={styles.convoyAndRoute.stopTableTbody}>
<View style={styles.convoyAndRoute.stopTableIndexWidth}>
<TD style={styles.convoyAndRoute.stopTableIndexColumn}>
{renderedIndex}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableOpWidth}>
<TD style={styles.convoyAndRoute.stopTableOpColumn}>
{step.name || 'Unknown'}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableChWidth}>
<TD style={styles.convoyAndRoute.stopTableChColumn}>{step.ch}</TD>
</View>
<View style={styles.convoyAndRoute.stopTableEndWidth}>
<TD style={styles.convoyAndRoute.stopTableItalicColumn}>
{isLastStep ? t('asap') : ''}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableStartWidth}>
<TD style={styles.convoyAndRoute.stopTableStartColumn}>
{isFirstStep ? step.stopEndTime : ''}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableStopTypeWidth}>
<TD style={styles.convoyAndRoute.stopTableItalicColumn}>
{isFirstStep || isLastStep
? t('serviceStop')
: capitalizeFirstLetter(
t(
`stdcm:trainPath.stopType.${stdcmData.simulationPathSteps[renderedIndex - 1].stopType}`
)
)}
</TD>
</View>
</TR>
);
}
return null;
const isLastStep = index === stdcmData.simulationPathSteps.length - 1;
renderedIndex += 1;
return (
<TR key={index} style={styles.convoyAndRoute.stopTableTbody}>
<View style={styles.convoyAndRoute.stopTableIndexWidth}>
<TD style={styles.convoyAndRoute.stopTableIndexColumn}>{renderedIndex}</TD>
</View>
<View style={styles.convoyAndRoute.stopTableOpWidth}>
<TD style={styles.convoyAndRoute.stopTableOpColumn}>
{step.name || 'Unknown'}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableChWidth}>
<TD style={styles.convoyAndRoute.stopTableChColumn}>{step.ch}</TD>
</View>
<View style={styles.convoyAndRoute.stopTableEndWidth}>
<TD style={styles.convoyAndRoute.stopTableItalicColumn}>
{getArrivalTime(step, { isLastStep })}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableStartWidth}>
<TD style={styles.convoyAndRoute.stopTableStartColumn}>
{getArrivalTime(step, { isFirstStep })}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableStopTypeWidth}>
<TD style={styles.convoyAndRoute.stopTableItalicColumn}>
{isFirstStep || isLastStep
? t('serviceStop')
: capitalizeFirstLetter(
t(
`stdcm:trainPath.stopType.${stdcmData.simulationPathSteps[index].stopType}`
)
)}
</TD>
</View>
</TR>
);
})}
</Table>
</View>
Expand Down Expand Up @@ -281,34 +285,55 @@ const SimulationReportSheet = ({
const isFirstStep = index === 0;
const isLastStep = index === operationalPointsList.length - 1;
const prevStep = operationalPointsList[index - 1];
const isViaInSimulationPath = stdcmData.simulationPathSteps
.slice(1, -1)
.some((pathStep) => pathStep.name === step.name && pathStep.ch === step.ch);
const isViaWithoutStop = isViaInSimulationPath && step.duration === 0;
const isNotExtremity = !isFirstStep && !isLastStep;
const isStepWithDuration = step.duration !== 0 && !isLastStep;
const tdPassageStopStyle = !isViaWithoutStop
? styles.simulation.td
: { ...styles.simulation.td, paddingLeft: '' };
return (
<TR
key={index}
style={
step.duration !== 0 && !isLastStep
? styles.simulation.blueRow
: styles.simulation.tbody
}
style={isStepWithDuration ? styles.simulation.blueRow : styles.simulation.tbody}
>
<TD style={styles.simulation.indexColumn}>{index + 1}</TD>
<TD
style={
isViaWithoutStop
? styles.simulation.indexColumnPassageStop
: styles.simulation.indexColumn
}
>
{index + 1}
</TD>
<View style={styles.simulation.opWidth}>
<TD
style={
!isFirstStep && !isLastStep && step.duration !== 0
? styles.simulation.opStop
: styles.simulation.td
// eslint-disable-next-line no-nested-ternary
isViaWithoutStop
? styles.simulation.opColumnPassageStop
: isNotExtremity && step.duration !== 0
? styles.simulation.opStop
: styles.simulation.td
}
>
{!isFirstStep &&
!isLastStep &&
step.name === prevStep.name &&
step.duration === 0
{isNotExtremity && !isViaInSimulationPath && step.name === prevStep.name
? '='
: step.name || 'Unknown'}
</TD>
</View>
<View style={styles.simulation.chWidth}>
<TD style={styles.simulation.chColumn}>{step.ch}</TD>
<TD
style={
isViaWithoutStop
? styles.simulation.chColumnPassageStop
: styles.simulation.chColumn
}
>
{step.ch}
</TD>
</View>
<View style={styles.simulation.trackWidth}>
<TD style={styles.simulation.td}>{step.trackName}</TD>
Expand All @@ -321,17 +346,20 @@ const SimulationReportSheet = ({
<View style={styles.simulation.passageWidth}>
<TD
style={{
...(step.duration !== 0 && !isLastStep
// eslint-disable-next-line no-nested-ternary
...(isStepWithDuration
? {
width: `${step.duration < 600 && step.duration >= 60 ? 60 : 70}px`,
...styles.simulation.blueStop,
}
: styles.simulation.stopColumn),
: !isViaWithoutStop
? styles.simulation.stopColumn
: { ...styles.simulation.stopColumn, marginLeft: '' }),
}}
>
{
// eslint-disable-next-line no-nested-ternary
!isFirstStep && !isLastStep
isNotExtremity
? step.duration !== 0
? getStopDurationTime(step.duration)
: step.time
Expand All @@ -345,20 +373,20 @@ const SimulationReportSheet = ({
</TD>
</View>
<View style={styles.simulation.weightWidth}>
<TD style={styles.simulation.td}>
<TD style={tdPassageStopStyle}>
{!isFirstStep ? '=' : `${Math.floor(rollingStock.mass / 1000)} t`}
</TD>
</View>
<View style={styles.simulation.refEngineWidth}>
<TD style={styles.simulation.td}>
<TD style={tdPassageStopStyle}>
{!isFirstStep ? '=' : rollingStock.metadata?.reference}
</TD>
</View>
<View style={styles.simulation.convSignWidth}>
<TD style={styles.simulation.td} aria-label="conventionalSign" />
<TD style={tdPassageStopStyle} aria-label="conventionalSign" />
</View>
<View style={styles.simulation.crossedATEWidth}>
<TD style={styles.simulation.td} aria-label="crossedATE" />
<TD style={tdPassageStopStyle} aria-label="crossedATE" />
</View>
</TR>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,43 @@ const styles = {
color: '#000000',
opacity: 0.25,
},
indexColumnPassageStop: {
fontFamily: 'IBM Plex Sans',
fontSize: '14',
fontWeight: 'semibold',
paddingLeft: '12',
paddingRight: '32',
color: '#216482',
backgroundColor: '#d3eaf2',
borderTop: '1 solid #ffffff',
borderBottom: '1 solid #ffffff',
borderLeft: '1 solid #ffffff',
borderTopLeftRadius: '4',
borderBottomLeftRadius: '4',
boxSizing: 'border-box',
},
chColumn: {
fontSize: '16',
fontWeight: 'semibold',
marginLeft: '16',
},
chColumnPassageStop: {
fontSize: '16',
fontWeight: 'semibold',
marginRight: '56',
backgroundColor: '#d3eaf2',
borderTop: '1 solid #ffffff',
borderBottom: '1 solid #ffffff',
borderRight: '1 solid #ffffff',
borderTopRightRadius: '2',
borderBottomRightRadius: '2',
boxSizing: 'border-box',
},
stopColumn: {
fontFamily: 'IBM Plex Mono',
fontSize: '16',
fontWeight: 'medium',
marginLeft: '14',
marginLeft: '16',
},
blueStop: {
height: '24',
Expand All @@ -512,6 +539,15 @@ const styles = {
color: '#312E2B',
paddingLeft: '16',
},
opColumnPassageStop: {
fontSize: '14',
fontWeight: 'semibold',
color: '#216482',
backgroundColor: '#d3eaf2',
borderTop: '1 solid #ffffff',
borderBottom: '1 solid #ffffff',
boxSizing: 'border-box',
},
opStop: {
fontSize: '14',
fontWeight: 'semibold',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,27 @@ const StcdmResultsTable = ({
const isLastStep = index === operationalPointsList.length - 1;
const prevStep = operationalPointsList[index - 1];
const isRequestedPathStep = stdcmData.simulationPathSteps.some(
(pathStep) => pathStep?.name === step.name && pathStep?.ch === step.ch
(pathStep) => pathStep.name === step.name && pathStep.ch === step.ch
);
const shouldRenderRow = isFirstStep || isRequestedPathStep || isLastStep;
const isPathStep =
isFirstStep || isLastStep || (isRequestedPathStep && step.duration === 0);
const isNotExtremity = !isFirstStep && !isLastStep;
if (showAllOP || shouldRenderRow) {
return (
<tr key={index}>
<td
className="index"
style={{
fontWeight: isFirstStep || isLastStep ? 600 : 'normal',
color: isFirstStep || isLastStep ? '' : 'rgb(121, 118, 113)',
fontWeight: isPathStep ? 600 : 'normal',
color: isPathStep ? '' : 'rgb(121, 118, 113)',
}}
>
{index + 1}
</td>
<td style={{ color: 'rgb(49, 46, 43)' }}>
{!isFirstStep &&
!isLastStep &&
{isNotExtremity &&
!isRequestedPathStep &&
step.name === prevStep.name &&
!isRequestedPathStep &&
step.duration === 0
Expand All @@ -86,7 +89,7 @@ const StcdmResultsTable = ({
>
{
// eslint-disable-next-line no-nested-ternary
!isFirstStep && !isLastStep
isNotExtremity || !isRequestedPathStep
? step.duration !== 0
? getStopDurationTime(step.duration)
: step.time
Expand All @@ -98,12 +101,10 @@ const StcdmResultsTable = ({
{isFirstStep || step.duration > 0 ? step.stopEndTime : ''}
</td>
<td className="weight" style={{ color: !isFirstStep ? '#797671' : '#312E2B' }}>
{!isFirstStep && !isLastStep
? '='
: `${Math.floor(stdcmData.rollingStock.mass / 1000)}t`}
{isNotExtremity ? '=' : `${Math.floor(stdcmData.rollingStock.mass / 1000)}t`}
</td>
<td style={{ color: !isFirstStep ? '#797671' : '#312E2B' }}>
{!isFirstStep && !isLastStep ? '=' : stdcmData.rollingStock.metadata?.reference}
{isNotExtremity ? '=' : stdcmData.rollingStock.metadata?.reference}
</td>
</tr>
);
Expand Down
Loading
Loading