From 382d08dfb8ddfbf450e1b343ce2a9fd3be25dc51 Mon Sep 17 00:00:00 2001 From: Achraf Mohyeddine Date: Thu, 2 Jan 2025 19:39:03 +0100 Subject: [PATCH] front: remove map feature from simualtion report sheet Signed-off-by: Achraf Mohyeddine --- .../StdcmResults/SimulationReportSheet.tsx | 33 +--------------- .../SimulationReportStyleSheet.ts | 1 - .../components/StdcmResults/StdcmResults.tsx | 5 +-- front/src/applications/stdcm/types.ts | 1 - .../utils/formatSimulationReportSheet.ts | 38 ------------------- 5 files changed, 2 insertions(+), 76 deletions(-) diff --git a/front/src/applications/stdcm/components/StdcmResults/SimulationReportSheet.tsx b/front/src/applications/stdcm/components/StdcmResults/SimulationReportSheet.tsx index d9e2d202f64..505a246b068 100644 --- a/front/src/applications/stdcm/components/StdcmResults/SimulationReportSheet.tsx +++ b/front/src/applications/stdcm/components/StdcmResults/SimulationReportSheet.tsx @@ -1,5 +1,3 @@ -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 type { TFunction } from 'i18next'; @@ -14,7 +12,7 @@ import { capitalizeFirstLetter } from 'utils/strings'; import styles from './SimulationReportStyleSheet'; import type { SimulationReportSheetProps } from '../../types'; -import { base64ToJpeg, getStopDurationTime } from '../../utils/formatSimulationReportSheet'; +import { getStopDurationTime } from '../../utils/formatSimulationReportSheet'; const getSecondaryCode = ({ location }: StdcmPathStep) => location!.secondary_code; @@ -40,7 +38,6 @@ const SimulationReportSheet = ({ stdcmData, consist, simulationReportSheetNumber, - mapCanvas, operationalPointsList, }: SimulationReportSheetProps) => { const { t } = useTranslation(['stdcm-simulation-report-sheet', 'stdcm']); @@ -63,28 +60,6 @@ const SimulationReportSheet = ({ path_number2: 'n°YYYYYY', }; - const [mapImageUrl, setMapImageUrl] = useState(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] - ); - return ( @@ -412,14 +387,8 @@ const SimulationReportSheet = ({ ); })} - - {mapCanvas && ( - - {mapImageUrl && } - - )} {t('withoutWarranty')} diff --git a/front/src/applications/stdcm/components/StdcmResults/SimulationReportStyleSheet.ts b/front/src/applications/stdcm/components/StdcmResults/SimulationReportStyleSheet.ts index 9efd7a1af0a..387f173c9f4 100644 --- a/front/src/applications/stdcm/components/StdcmResults/SimulationReportStyleSheet.ts +++ b/front/src/applications/stdcm/components/StdcmResults/SimulationReportStyleSheet.ts @@ -606,7 +606,6 @@ const styles = { warrantyBox: { height: '64', marginTop: '16', - borderTop: '1 solid #D3D1CF', display: 'flex', alignItems: 'center', }, diff --git a/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx b/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx index b0db7555683..e1f03e23d0d 100644 --- a/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx +++ b/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from 'react'; +import { useMemo } from 'react'; import { Button } from '@osrd-project/ui-core'; import { PDFDownloadLink } from '@react-pdf/renderer'; @@ -46,7 +46,6 @@ const StcdmResults = ({ pathTrackRanges, }: StcdmResultsProps) => { const { t } = useTranslation('stdcm', { keyPrefix: 'simulation.results' }); - const [mapCanvas, setMapCanvas] = useState(); const selectedSimulation = simulationsList[selectedSimulationIndex]; const { outputs } = selectedSimulation || {}; @@ -105,7 +104,6 @@ const StcdmResults = ({ stdcmData={outputs.results} consist={selectedSimulation.inputs.consist} simulationReportSheetNumber={simulationReportSheetNumber} - mapCanvas={mapCanvas} operationalPointsList={operationalPointsList} /> } @@ -172,7 +170,6 @@ const StcdmResults = ({ hideAttribution showStdcmAssets isFeasible={!hasConflictResults} - setMapCanvas={setMapCanvas} pathGeometry={outputs?.pathProperties?.geometry} simulationPathSteps={markersInfo} /> diff --git a/front/src/applications/stdcm/types.ts b/front/src/applications/stdcm/types.ts index 746ce92658d..e7cee4b13fc 100644 --- a/front/src/applications/stdcm/types.ts +++ b/front/src/applications/stdcm/types.ts @@ -56,7 +56,6 @@ export type SimulationReportSheetProps = { stdcmData: StdcmSuccessResponse; consist: StdcmSimulationInputs['consist']; simulationReportSheetNumber: string; - mapCanvas?: string; operationalPointsList: StdcmResultsOperationalPoint[]; }; diff --git a/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts b/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts index 81e380e0df0..dea44f62394 100644 --- a/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts +++ b/front/src/applications/stdcm/utils/formatSimulationReportSheet.ts @@ -143,41 +143,3 @@ export function getOperationalPointsWithTimes( return opResults; } - -/** - * Converts a base64 image into a JPEG blob while reducing quality. - * @param base64Image - Image in base64 - * @param quality - Image quality (between 0 and 1, where 1 is the best quality) - * @returns {Promise} - Return an optimised JPEG Blob - */ -export const base64ToJpeg = (base64Image: string, quality: number): Promise => - new Promise((resolve, reject) => { - const img = new Image(); - img.src = base64Image; - img.onload = () => { - const canvas = document.createElement('canvas'); - const ctx = canvas.getContext('2d'); - if (!ctx) { - reject(new Error('Could not get canvas context')); - return; - } - canvas.width = img.width; - canvas.height = img.height; - - ctx.drawImage(img, 0, 0); - - canvas.toBlob( - (blob) => { - if (blob) { - resolve(blob); - } - }, - 'image/jpeg', - quality - ); - }; - - img.onerror = (error) => { - reject(error); - }; - });