Skip to content

Commit 138a8d6

Browse files
esasovanborde-CSM
authored andcommitted
fix: [PROD-11887] fix wrong dirty state after clearing errors
1 parent 745a4da commit 138a8d6

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/components/ScenarioParameters/components/ScenarioParametersInputs/GenericTable.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,15 @@ export const GenericTable = ({
116116

117117
// Store last parameter in a ref
118118
// Update a state is async, so, in case of multiple call of updateParameterValue in same function
119-
// parameter state value will be update only in last call.
119+
// parameter state value will be updated only in last call.
120120
// We need here to use a ref value for be sure to have the good value.
121121
const lastNewParameterValue = useRef(parameter);
122+
const dirtyState = useRef(false);
123+
122124
const updateParameterValue = useCallback(
123125
(newValuePart, shouldReset = false) => {
126+
const lastIsDirty = dirtyState.current;
127+
dirtyState.current = isDirty;
124128
const newParameterValue = {
125129
...lastNewParameterValue.current,
126130
...newValuePart,
@@ -138,14 +142,14 @@ export const GenericTable = ({
138142
// Prevent useless update of parameterValue if multiple updateParameterValue was done before
139143
if (lastNewParameterValue.current === newParameterValue) {
140144
if (shouldReset) {
141-
resetParameterValue(newParameterValue);
145+
resetParameterValue(newParameterValue, lastIsDirty === isDirty);
142146
} else {
143147
setParameterValue(newParameterValue);
144148
}
145149
}
146150
});
147151
},
148-
[resetParameterValue, setParameterValue]
152+
[resetParameterValue, setParameterValue, isDirty]
149153
);
150154

151155
const updateParameterValueWithReset = (newValuePart) => {
@@ -439,9 +443,12 @@ export const GenericTable = ({
439443
const onCellChange = updateOnFirstEdition;
440444

441445
const onClearErrors = () => {
442-
updateParameterValue({
443-
errors: null,
444-
});
446+
updateParameterValue(
447+
{
448+
errors: null,
449+
},
450+
true
451+
);
445452
};
446453

447454
const buildErrorsPanelTitle = (errorsCount, maxErrorsCount) => {

src/components/ScenarioParameters/components/ScenarioParametersTabs/ScenarioParameterInput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ const ScenarioParameterInput = ({ parameterData, context }) => {
4949
}
5050
};
5151

52-
const resetParameterValue = (newDefaultValue) => {
52+
const resetParameterValue = (newDefaultValue, keepDirty = false) => {
5353
if (scenarioIdOnMount.current === getCurrentScenarioId()) {
54-
resetField(parameterData.id, { defaultValue: newDefaultValue });
54+
resetField(parameterData.id, { defaultValue: newDefaultValue, keepDirty });
5555
}
5656
};
5757

0 commit comments

Comments
 (0)