-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: clean up and enhance simulation report sheet
Signed-off-by: Achraf Mohyeddine <[email protected]>
- Loading branch information
1 parent
9c34c10
commit c95d87e
Showing
12 changed files
with
122 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { Table, TR, TH, TD } from '@ag-media/react-pdf-table'; | ||
import { Page, Text, Image, Document, View, Link } from '@react-pdf/renderer'; | ||
import { Page, Text, Image, Document, View } from '@react-pdf/renderer'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import iconAlert from 'assets/simulationReportSheet/icon_alert_fill.png'; | ||
|
@@ -10,18 +8,20 @@ import type { PathStep } from 'reducers/osrdconf/types'; | |
import { extractHHMM, formatDateToString, formatDay } from 'utils/date'; | ||
import { msToKmh } from 'utils/physics'; | ||
import { capitalizeFirstLetter } from 'utils/strings'; | ||
import { secToMin } from 'utils/timeManipulation'; | ||
|
||
import styles from './SimulationReportStyleSheet'; | ||
import type { SimulationReportSheetProps } from '../../types'; | ||
import { base64ToJpeg, getStopDurationTime } from '../../utils/formatSimulationReportSheet'; | ||
import { getStopDurationTime } from '../../utils/formatSimulationReportSheet'; | ||
|
||
const SimulationReportSheet = ({ | ||
stdcmLinkedPaths, | ||
stdcmData, | ||
consist, | ||
simulationReportSheetNumber, | ||
mapCanvas, | ||
operationalPointsList, | ||
tolerances, | ||
username, | ||
}: SimulationReportSheetProps) => { | ||
const { t } = useTranslation(['stdcm-simulation-report-sheet', 'stdcm']); | ||
let renderedIndex = 0; | ||
|
@@ -33,38 +33,6 @@ const SimulationReportSheet = ({ | |
const convoyLength = consist?.totalLength ?? rollingStock.length; | ||
const convoyMaxSpeed = consist?.maxSpeed ?? msToKmh(rollingStock.max_speed); | ||
|
||
// TODO: Add RC information when it becomes avalaible, until that, we use fake ones | ||
const fakeInformation = { | ||
rcName: 'Super Fret', | ||
rcPersonName: 'Jane Smith', | ||
rcPhoneNumber: '01 23 45 67 89', | ||
rcMail: '[email protected]', | ||
path_number1: 'n°XXXXXX', | ||
path_number2: 'n°YYYYYY', | ||
}; | ||
|
||
const [mapImageUrl, setMapImageUrl] = useState<string | null>(null); | ||
|
||
// Convert image to JPEG | ||
useEffect(() => { | ||
if (mapCanvas) { | ||
base64ToJpeg(mapCanvas, 0.8).then((blob) => { | ||
const objectUrl = URL.createObjectURL(blob); | ||
setMapImageUrl(objectUrl); | ||
}); | ||
} | ||
}, [mapCanvas]); | ||
|
||
// Cleanup the object URL when the component is unmounted or before a new one is created | ||
useEffect( | ||
() => () => { | ||
if (mapImageUrl) { | ||
URL.revokeObjectURL(mapImageUrl); | ||
} | ||
}, | ||
[mapImageUrl] | ||
); | ||
|
||
const getArrivalTime = ( | ||
step: PathStep, | ||
{ isFirstStep, isLastStep }: { isFirstStep?: boolean; isLastStep?: boolean } | ||
|
@@ -107,19 +75,12 @@ const SimulationReportSheet = ({ | |
|
||
<View style={styles.rcInfo.rcInfo}> | ||
<View style={styles.rcInfo.rcBox}> | ||
<Text style={styles.rcInfo.rcName}>{fakeInformation.rcName}</Text> | ||
<Text style={styles.rcInfo.rcPersonName}>{fakeInformation.rcPersonName}</Text> | ||
</View> | ||
<View style={styles.rcInfo.rcBox}> | ||
<Text style={styles.rcInfo.rcPhoneNumber}>{fakeInformation.rcPhoneNumber}</Text> | ||
<Text style={styles.rcInfo.rcMail}>{fakeInformation.rcMail}</Text> | ||
<Text style={styles.rcInfo.rcName}>{username}</Text> | ||
</View> | ||
<View style={styles.rcInfo.rcBox}> | ||
<View style={styles.rcInfo.stdcmApplication}> | ||
<Text style={styles.rcInfo.applicationDate}>{t('applicationDate')}</Text> | ||
<Text style={styles.rcInfo.date}>{formatDay(departureTime)}</Text> | ||
<Text style={styles.rcInfo.referencePath}>{t('referencePath')}</Text> | ||
<Text style={styles.rcInfo.pathNumber}>{fakeInformation.path_number1}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
|
@@ -160,9 +121,7 @@ const SimulationReportSheet = ({ | |
<View style={styles.convoyAndRoute.fromBox}> | ||
<Text style={styles.convoyAndRoute.from}>{t('from')}</Text> | ||
</View> | ||
<Text style={styles.convoyAndRoute.fromNumber}> | ||
{anteriorPath?.trainName || fakeInformation.path_number1} | ||
</Text> | ||
<Text style={styles.convoyAndRoute.fromNumber}>{anteriorPath?.trainName}</Text> | ||
<Text style={styles.convoyAndRoute.fromScheduled}> | ||
{anteriorPath && | ||
t('scheduledArrival', { date: anteriorPath.date, time: anteriorPath.time })} | ||
|
@@ -216,7 +175,19 @@ const SimulationReportSheet = ({ | |
</View> | ||
<View style={styles.convoyAndRoute.stopTableStartWidth}> | ||
<TD style={styles.convoyAndRoute.stopTableStartColumn}> | ||
{getArrivalTime(step, { isFirstStep })} | ||
<View> | ||
<Text>{getArrivalTime(step, { isFirstStep })}</Text> | ||
</View> | ||
{isFirstStep && ( | ||
<View style={styles.convoyAndRoute.tolerancesWidth}> | ||
<Text style={styles.convoyAndRoute.tolerancesText}> | ||
{tolerances?.before ? `-${secToMin(tolerances.before)}` : ''} | ||
</Text> | ||
<Text style={styles.convoyAndRoute.tolerancesText}> | ||
{tolerances?.after ? `+${secToMin(tolerances.after)}` : ''} | ||
</Text> | ||
</View> | ||
)} | ||
</TD> | ||
</View> | ||
<View style={styles.convoyAndRoute.stopTableStopTypeWidth}> | ||
|
@@ -236,30 +207,25 @@ const SimulationReportSheet = ({ | |
</Table> | ||
</View> | ||
{/* TODO: Add path number and date from reference path when it becomes avalaible */} | ||
<View style={styles.convoyAndRoute.forBanner}> | ||
<Text style={styles.convoyAndRoute.forScheduled}> | ||
{posteriorPath && | ||
t('scheduledDeparture', { date: posteriorPath.date, time: posteriorPath.time })} | ||
</Text> | ||
<Text style={styles.convoyAndRoute.forNumber}> | ||
{posteriorPath?.trainName || fakeInformation.path_number2} | ||
</Text> | ||
<View style={styles.convoyAndRoute.forBox}> | ||
<Text style={styles.convoyAndRoute.for}>{t('for')}</Text> | ||
{posteriorPath && ( | ||
<View style={styles.convoyAndRoute.forBanner}> | ||
<Text style={styles.convoyAndRoute.forScheduled}> | ||
{t('scheduledDeparture', { | ||
date: posteriorPath.date, | ||
time: posteriorPath.time, | ||
})} | ||
</Text> | ||
<Text style={styles.convoyAndRoute.forNumber}>{posteriorPath?.trainName}</Text> | ||
<View style={styles.convoyAndRoute.forBox}> | ||
<Text style={styles.convoyAndRoute.for}>{t('for')}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
)} | ||
</View> | ||
</View> | ||
<View style={styles.simulation.simulation}> | ||
<View style={styles.simulation.simulationContainer}> | ||
<Text style={styles.simulation.simulationUppercase}>{t('simulation')}</Text> | ||
<Link | ||
href="#simulationMap" | ||
src="#simulationMap" | ||
style={styles.simulation.viewSimulation} | ||
> | ||
{t('viewSimulation')} | ||
</Link> | ||
<Text style={styles.simulation.simulationLength}> | ||
{`${Math.round(stdcmData.path.length / 1000000)} km`} | ||
</Text> | ||
|
@@ -291,15 +257,12 @@ const SimulationReportSheet = ({ | |
<View style={styles.simulation.weightWidth}> | ||
<TD>{t('weight')}</TD> | ||
</View> | ||
<View style={styles.simulation.length}> | ||
<TD>{t('length')}</TD> | ||
</View> | ||
<View style={styles.simulation.refEngineWidth}> | ||
<TD>{t('referenceEngine')}</TD> | ||
</View> | ||
<View style={styles.simulation.convSignWidth}> | ||
<TD>{t('conventionalSign')}</TD> | ||
</View> | ||
<View style={styles.simulation.crossedATEWidth}> | ||
<TD>{t('crossedATE')}</TD> | ||
</View> | ||
</TH> | ||
{operationalPointsList.map((step, index) => { | ||
const isFirstStep = index === 0; | ||
|
@@ -402,29 +365,21 @@ const SimulationReportSheet = ({ | |
{!isFirstStep ? '=' : `${Math.floor(convoyMass)} t`} | ||
</TD> | ||
</View> | ||
<View style={styles.simulation.length}> | ||
<TD style={tdPassageStopStyle}>{!isFirstStep ? '=' : `${convoyLength} m`}</TD> | ||
</View> | ||
<View style={styles.simulation.refEngineWidth}> | ||
<TD style={tdPassageStopStyle}> | ||
{!isFirstStep ? '=' : rollingStock.metadata?.reference} | ||
</TD> | ||
</View> | ||
<View style={styles.simulation.convSignWidth}> | ||
<TD style={tdPassageStopStyle} aria-label="conventionalSign" /> | ||
</View> | ||
<View style={styles.simulation.crossedATEWidth}> | ||
<TD style={tdPassageStopStyle} aria-label="crossedATE" /> | ||
</View> | ||
</TR> | ||
); | ||
})} | ||
</Table> | ||
<View style={styles.simulation.horizontalBar} /> | ||
</View> | ||
</View> | ||
{mapCanvas && ( | ||
<View style={styles.map.map} id="simulationMap"> | ||
{mapImageUrl && <Image src={mapImageUrl} />} | ||
</View> | ||
)} | ||
<View style={styles.footer.warrantyBox}> | ||
<Text style={styles.footer.warrantyMessage}>{t('withoutWarranty')}</Text> | ||
</View> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.