Skip to content

Commit 8016bc4

Browse files
committed
front: fix incorrect input saving when switching simulations during a running calculation
When a different simulation is selected while a calculation is still running, the new simulation’s inputs overwrite the inputs of the ongoing calculation. This causes a mismatch between the inputs used for the calculation and the results. Now, the inputs for the simulation being calculated are stored in a different state variable than the one used for the selected simulation. Signed-off-by: nncluzu <ngamenichaka@yahoo.fr>
1 parent 23a21ce commit 8016bc4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

front/src/applications/stdcm/components/StdcmForm/StdcmConfig.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare global {
4747
type StdcmConfigProps = {
4848
isDebugMode: boolean;
4949
isPending: boolean;
50-
launchStdcmRequest: () => Promise<void>;
50+
onStartSimulation: () => void;
5151
retainedSimulationIndex: number;
5252
showBtnToLaunchSimulation: boolean;
5353
cancelStdcmRequest: () => void;
@@ -56,7 +56,7 @@ type StdcmConfigProps = {
5656
const StdcmConfig = ({
5757
isDebugMode,
5858
isPending,
59-
launchStdcmRequest,
59+
onStartSimulation,
6060
retainedSimulationIndex,
6161
showBtnToLaunchSimulation,
6262
cancelStdcmRequest,
@@ -129,7 +129,7 @@ const StdcmConfig = ({
129129
const startSimulation = () => {
130130
const formErrorsStatus = checkStdcmConfigErrors(pathSteps, t, pathfinding?.status);
131131
if (pathfinding?.status === 'success' && !formErrorsStatus) {
132-
launchStdcmRequest();
132+
onStartSimulation();
133133
} else {
134134
// The console error is only for debugging the user tests (temporary)
135135
console.warn('The form is not valid:', { pathfinding, formErrorsStatus });

front/src/applications/stdcm/views/StdcmView.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import StdcmResults from '../components/StdcmResults';
1919
import StdcmStatusBanner from '../components/StdcmStatusBanner';
2020
import useStdcmEnvironment, { NO_CONFIG_FOUND_MSG } from '../hooks/useStdcmEnv';
2121
import useStdcmForm from '../hooks/useStdcmForm';
22-
import type { StdcmSimulation } from '../types';
22+
import type { StdcmSimulation, StdcmSimulationInputs } from '../types';
2323

2424
const StdcmView = () => {
2525
// TODO : refacto. state useStdcm. Maybe we can merge some state together in order to reduce the number of refresh
2626
const currentSimulationInputs = useStdcmForm();
2727
const stdcmConf = useSelector(getStdcmConf);
2828
const [simulationsList, setSimulationsList] = useState<StdcmSimulation[]>([]);
29+
const [inProgressSimulationInputs, setInProgressSimulationInputs] = useState<StdcmSimulationInputs>();
2930
const [selectedSimulationIndex, setSelectedSimulationIndex] = useState(-1);
3031
const [showStatusBanner, setShowStatusBanner] = useState(false);
3132
const [retainedSimulationIndex, setRetainedSimulationIndex] = useState(-1);
@@ -92,6 +93,11 @@ const StdcmView = () => {
9293

9394
const toggleHelpModule = () => setShowHelpModule((show) => !show);
9495

96+
const onStartSimulation = () => {
97+
setInProgressSimulationInputs(currentSimulationInputs);
98+
launchStdcmRequest();
99+
};
100+
95101
// reset config data with the selected simulation data
96102
useEffect(() => {
97103
if (selectedSimulation) {
@@ -144,8 +150,8 @@ const StdcmView = () => {
144150
* the existing one.
145151
*/
146152
const lastSimulation = simulationsList[simulationsList.length - 1];
147-
const isSimulationAlreadyListed = isEqual(lastSimulation?.inputs, currentSimulationInputs);
148-
const isSimulationOutputsComplete = stdcmResults?.stdcmResponse || hasConflicts;
153+
const isSimulationAlreadyListed = isEqual(lastSimulation?.inputs, inProgressSimulationInputs);
154+
const isSimulationOutputsComplete = stdcmResults?.stdcmResponse ?? hasConflicts;
149155

150156
if (isSimulationOutputsComplete) {
151157
const newSimulation = {
@@ -154,7 +160,7 @@ const StdcmView = () => {
154160
: {
155161
id: simulationsList.length + 1,
156162
creationDate: new Date(),
157-
inputs: currentSimulationInputs,
163+
inputs: inProgressSimulationInputs!,
158164
}),
159165
...(pathProperties && {
160166
outputs: {
@@ -220,7 +226,7 @@ const StdcmView = () => {
220226
isDebugMode={isDebugMode}
221227
showBtnToLaunchSimulation={showBtnToLaunchSimulation}
222228
retainedSimulationIndex={retainedSimulationIndex}
223-
launchStdcmRequest={launchStdcmRequest}
229+
onStartSimulation={onStartSimulation}
224230
cancelStdcmRequest={cancelStdcmRequest}
225231
/>
226232

0 commit comments

Comments
 (0)