diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx index 877a9c2b379..eb3fc77cac8 100644 --- a/front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx +++ b/front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx @@ -48,7 +48,7 @@ type StdcmConfigProps = { isDebugMode: boolean; isPending: boolean; launchStdcmRequest: () => Promise; - retainedSimulationIndex: number; + retainedSimulationIndex?: number; showBtnToLaunchSimulation: boolean; cancelStdcmRequest: () => void; }; @@ -122,7 +122,7 @@ const StdcmConfig = ({ }; }, [rollingStock, towedRollingStock, totalMass, totalLength, maxSpeed]); - const disabled = isPending || retainedSimulationIndex > -1; + const disabled = isPending || retainedSimulationIndex !== undefined; const markersInfo = useMemo(() => extractMarkersInfo(pathSteps), [pathSteps]); diff --git a/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx b/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx index f6bbc7498a8..93afc0c575e 100644 --- a/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx +++ b/front/src/applications/stdcm/components/StdcmResults/StdcmResults.tsx @@ -3,9 +3,9 @@ import { useMemo } from 'react'; import { Button } from '@osrd-project/ui-core'; import { PDFDownloadLink } from '@react-pdf/renderer'; import { useTranslation, Trans } from 'react-i18next'; +import { useSelector } from 'react-redux'; import useConflictsMessages from 'applications/stdcm/hooks/useConflictsMessages'; -import type { StdcmSimulation } from 'applications/stdcm/types'; import { extractMarkersInfo } from 'applications/stdcm/utils'; import { generateCodeNumber, @@ -13,6 +13,10 @@ import { } from 'applications/stdcm/utils/formatSimulationReportSheet'; import { hasConflicts, hasResults } from 'applications/stdcm/utils/simulationOutputUtils'; import NewMap from 'modules/trainschedule/components/ManageTrainSchedule/NewMap'; +import { + getRetainedSimulationIndex, + getSelectedSimulation, +} from 'reducers/osrdconf/stdcmConf/selectors'; import useDeploymentSettings from 'utils/hooks/useDeploymentSettings'; import SimulationReportSheet from './SimulationReportSheet'; @@ -23,35 +27,29 @@ import StdcmSimulationNavigator from './StdcmSimulationNavigator'; type StcdmResultsProps = { isCalculationFailed: boolean; isDebugMode: boolean; - onRetainSimulation: () => void; onSelectSimulation: (simulationIndex: number) => void; onStartNewQuery: () => void; onStartNewQueryWithData: () => void; buttonsVisible: boolean; - retainedSimulationIndex: number; - selectedSimulationIndex: number; showStatusBanner: boolean; - simulationsList: StdcmSimulation[]; }; const StcdmResults = ({ isCalculationFailed, isDebugMode, - onRetainSimulation, onSelectSimulation, onStartNewQuery, onStartNewQueryWithData, buttonsVisible, - retainedSimulationIndex, - selectedSimulationIndex, showStatusBanner, - simulationsList, }: StcdmResultsProps) => { const { t } = useTranslation('stdcm', { keyPrefix: 'simulation.results' }); const { stdcmName } = useDeploymentSettings(); - const selectedSimulation = simulationsList[selectedSimulationIndex]; - const { outputs } = selectedSimulation || {}; + const selectedSimulation = useSelector(getSelectedSimulation); + const retainedSimulationIndex = useSelector(getRetainedSimulationIndex); + + const { outputs } = selectedSimulation; const hasConflictResults = hasConflicts(outputs); const hasSimulationResults = hasResults(outputs); @@ -59,7 +57,8 @@ const StcdmResults = ({ const { trackConflicts, workConflicts } = useConflictsMessages(t, outputs); const simulationReportSheetNumber = generateCodeNumber(); - const isSelectedSimulationRetained = selectedSimulationIndex === retainedSimulationIndex; + const isSelectedSimulationRetained = + retainedSimulationIndex !== undefined && selectedSimulation.index === retainedSimulationIndex; const operationalPointsList = useMemo(() => { if (!hasSimulationResults) return []; @@ -81,8 +80,7 @@ const StcdmResults = ({ return ( <> {isSelectedSimulationRetained && (
@@ -123,7 +121,7 @@ const StcdmResults = ({
{t('gesicoRequest')}
)} - {retainedSimulationIndex > -1 && buttonsVisible && ( + {retainedSimulationIndex !== undefined && buttonsVisible && (