diff --git a/src/components/ScenarioParameters/components/ScenarioParametersInputs/GenericTable.js b/src/components/ScenarioParameters/components/ScenarioParametersInputs/GenericTable.js index f1fd1d567..56468f706 100644 --- a/src/components/ScenarioParameters/components/ScenarioParametersInputs/GenericTable.js +++ b/src/components/ScenarioParameters/components/ScenarioParametersInputs/GenericTable.js @@ -116,11 +116,15 @@ export const GenericTable = ({ // Store last parameter in a ref // Update a state is async, so, in case of multiple call of updateParameterValue in same function - // parameter state value will be update only in last call. + // parameter state value will be updated only in last call. // We need here to use a ref value for be sure to have the good value. const lastNewParameterValue = useRef(parameter); + const dirtyState = useRef(false); + const updateParameterValue = useCallback( (newValuePart, shouldReset = false) => { + const lastIsDirty = dirtyState.current; + dirtyState.current = isDirty; const newParameterValue = { ...lastNewParameterValue.current, ...newValuePart, @@ -138,14 +142,14 @@ export const GenericTable = ({ // Prevent useless update of parameterValue if multiple updateParameterValue was done before if (lastNewParameterValue.current === newParameterValue) { if (shouldReset) { - resetParameterValue(newParameterValue); + resetParameterValue(newParameterValue, lastIsDirty === isDirty); } else { setParameterValue(newParameterValue); } } }); }, - [resetParameterValue, setParameterValue] + [resetParameterValue, setParameterValue, isDirty] ); const updateParameterValueWithReset = (newValuePart) => { @@ -439,9 +443,12 @@ export const GenericTable = ({ const onCellChange = updateOnFirstEdition; const onClearErrors = () => { - updateParameterValue({ - errors: null, - }); + updateParameterValue( + { + errors: null, + }, + true + ); }; const buildErrorsPanelTitle = (errorsCount, maxErrorsCount) => { diff --git a/src/components/ScenarioParameters/components/ScenarioParametersTabs/ScenarioParameterInput.js b/src/components/ScenarioParameters/components/ScenarioParametersTabs/ScenarioParameterInput.js index 748aab089..2f160dcb6 100644 --- a/src/components/ScenarioParameters/components/ScenarioParametersTabs/ScenarioParameterInput.js +++ b/src/components/ScenarioParameters/components/ScenarioParametersTabs/ScenarioParameterInput.js @@ -49,9 +49,9 @@ const ScenarioParameterInput = ({ parameterData, context }) => { } }; - const resetParameterValue = (newDefaultValue) => { + const resetParameterValue = (newDefaultValue, keepDirty = false) => { if (scenarioIdOnMount.current === getCurrentScenarioId()) { - resetField(parameterData.id, { defaultValue: newDefaultValue }); + resetField(parameterData.id, { defaultValue: newDefaultValue, keepDirty }); } };