Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down Expand Up @@ -439,9 +443,12 @@ export const GenericTable = ({
const onCellChange = updateOnFirstEdition;

const onClearErrors = () => {
updateParameterValue({
errors: null,
});
updateParameterValue(
{
errors: null,
},
true
);
};

const buildErrorsPanelTitle = (errorsCount, maxErrorsCount) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
};

Expand Down