Skip to content

Fix reset all parameters#1059

Open
SlimaneAmar wants to merge 3 commits intomainfrom
fix_reset_all_lf_params
Open

Fix reset all parameters#1059
SlimaneAmar wants to merge 3 commits intomainfrom
fix_reset_all_lf_params

Conversation

@SlimaneAmar
Copy link
Contributor

PR Summary

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Three files in the form handling layer were updated to adjust dirty-field detection, parameter value iteration, and form reset timing. The changes refine how React Hook Form state is tracked and applied during form operations.

Changes

Cohort / File(s) Summary
Submit Button State
src/components/inputs/reactHookForm/utils/SubmitButton.tsx
Modified disabled state computation to check dirty fields count (Object.keys(dirtyFields).length) instead of the isDirty boolean, while preserving explicit buttonProps?.disabled overrides.
Parameter Value Iteration
src/components/parameters/common/utils.ts
Changed key iteration in getAllSpecificParametersValues to use _specificParametersValues instead of formData[SPECIFIC_PARAMETERS], restricting the reducer to only process keys present in the provided values object.
Form Reset and Provider Tracking
src/components/parameters/loadflow/use-load-flow-parameters-form.ts
Restructured form-reset effect to additionally update previousWatchProviderRef.current with the loaded provider value, enabling proper provider-change detection baseline after external parameter loads.
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request description is empty, providing no details about the changes or context for reviewers. Add a detailed description explaining what was fixed, why it was needed, and any relevant implementation details or testing notes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix reset all parameters' directly relates to the main change visible in the pull request—the reset behavior refactoring in the load-flow-parameters form.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can enable review details to help with troubleshooting, context usage and more.

Enable the reviews.review_details setting to include review details such as the model used, the time taken for each step and more in the review comments.

@sonarqubecloud
Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/parameters/common/utils.ts (1)

101-106: ⚠️ Potential issue | 🟠 Major

Potential TypeError when key exists in _specificParametersValues but not in formData[SPECIFIC_PARAMETERS].

If the parameter description and form state diverge (e.g., provider schema adds new fields asynchronously), accessing formData[SPECIFIC_PARAMETERS][key] may return undefined, causing .toString() to throw. Add a guard to handle missing keys.

🐛 Proposed fix to guard against missing keys
 return Object.keys(_specificParametersValues).reduce((acc: SpecificParametersValues, key: string) => {
+    const formValue = formData[SPECIFIC_PARAMETERS]?.[key];
+    if (formValue === undefined) {
+        return acc;
+    }
-    if (_specificParametersValues[key].toString() !== formData[SPECIFIC_PARAMETERS][key].toString()) {
-        acc[key] = formData[SPECIFIC_PARAMETERS][key].toString();
+    if (_specificParametersValues[key].toString() !== formValue.toString()) {
+        acc[key] = formValue.toString();
     }
     return acc;
 }, {});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/parameters/common/utils.ts` around lines 101 - 106, The reduce
block using _specificParametersValues and formData[SPECIFIC_PARAMETERS] can
throw when formData[SPECIFIC_PARAMETERS][key] is undefined; update the reducer
in utils.ts (the block referencing _specificParametersValues,
SPECIFIC_PARAMETERS, formData, and SpecificParametersValues) to first guard that
formData[SPECIFIC_PARAMETERS] and formData[SPECIFIC_PARAMETERS][key] are not
null/undefined before calling toString(); if the form value is missing, skip
adding that key to acc (or use String(...) with a safe default) so no
.toString() is invoked on undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/parameters/loadflow/use-load-flow-parameters-form.ts`:
- Around line 292-298: The two separate effects (the reset effect that calls
resetForm(params) and sets previousWatchProviderRef.current, and the
provider-switch effect that uses watchProvider) can run in either order and
cause a race; fix by either merging them into a single useEffect that handles
both the resetForm(params) call and the provider-switch logic (using the same
dependency array: paramsLoaded, params, specificParamsDescription,
watchProvider) so state updates happen deterministically, or add a coordinating
ref/flag (e.g., resettingRef) that the provider-switch effect checks and sets:
have the reset effect set resettingRef.current = true before running resetForm
and false after, and have the provider-switch effect return early when
resettingRef.current is true; update references to
previousWatchProviderRef.current, resetForm, params and watchProvider
accordingly.

---

Outside diff comments:
In `@src/components/parameters/common/utils.ts`:
- Around line 101-106: The reduce block using _specificParametersValues and
formData[SPECIFIC_PARAMETERS] can throw when formData[SPECIFIC_PARAMETERS][key]
is undefined; update the reducer in utils.ts (the block referencing
_specificParametersValues, SPECIFIC_PARAMETERS, formData, and
SpecificParametersValues) to first guard that formData[SPECIFIC_PARAMETERS] and
formData[SPECIFIC_PARAMETERS][key] are not null/undefined before calling
toString(); if the form value is missing, skip adding that key to acc (or use
String(...) with a safe default) so no .toString() is invoked on undefined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1af48898-9ecc-4b76-a4c3-3ca7064ae39c

📥 Commits

Reviewing files that changed from the base of the PR and between 3b5f4c3 and fea3216.

📒 Files selected for processing (3)
  • src/components/inputs/reactHookForm/utils/SubmitButton.tsx
  • src/components/parameters/common/utils.ts
  • src/components/parameters/loadflow/use-load-flow-parameters-form.ts

Comment on lines +292 to +298
useEffect(() => {
if (!params) {
return;
}
resetForm(params);
previousWatchProviderRef.current = params.provider; // Do no reset values when switch provider from a callBack
}, [paramsLoaded, params, specificParamsDescription]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Effect ordering may cause race condition with provider-switch effect.

Both effects run on the same render cycle when params changes. Since React doesn't guarantee execution order between effects, the provider-switch effect (lines 264-290) could run before this reset effect, causing previousWatchProviderRef.current to be set to watchProvider before being corrected here. Consider combining these into a single effect or using a flag to coordinate.

Run the following script to check if there are integration tests covering the reset scenario:

#!/bin/bash
# Search for tests covering loadflow parameter reset or provider switching
rg -n -C3 'resetForm|previousWatchProvider|reset.*param' --glob '*test*' --glob '*spec*'

Additionally, verify eslint-plugin-react-hooks version:

#!/bin/bash
# Check eslint-plugin-react-hooks version for useEffectEvent support
cat package.json | jq '.dependencies["eslint-plugin-react-hooks"] // .devDependencies["eslint-plugin-react-hooks"]'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/parameters/loadflow/use-load-flow-parameters-form.ts` around
lines 292 - 298, The two separate effects (the reset effect that calls
resetForm(params) and sets previousWatchProviderRef.current, and the
provider-switch effect that uses watchProvider) can run in either order and
cause a race; fix by either merging them into a single useEffect that handles
both the resetForm(params) call and the provider-switch logic (using the same
dependency array: paramsLoaded, params, specificParamsDescription,
watchProvider) so state updates happen deterministically, or add a coordinating
ref/flag (e.g., resettingRef) that the provider-switch effect checks and sets:
have the reset effect set resettingRef.current = true before running resetForm
and false after, and have the provider-switch effect return early when
resettingRef.current is true; update references to
previousWatchProviderRef.current, resetForm, params and watchProvider
accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants