Skip to content

refactor(voltage-level-creation): remove CreateSwitchesDialog and replace it with a simplified inline form (#1101)#1124

Merged
TheMaskedTurtle merged 7 commits into
mainfrom
jorism/feat/simplify-OC-UI
May 13, 2026
Merged

refactor(voltage-level-creation): remove CreateSwitchesDialog and replace it with a simplified inline form (#1101)#1124
TheMaskedTurtle merged 7 commits into
mainfrom
jorism/feat/simplify-OC-UI

Conversation

@TheMaskedTurtle
Copy link
Copy Markdown
Contributor

PR Summary

…eplace it with a simplified inline form (#1101)

Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack

Warning

Rate limit exceeded

@dbraquart has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 43 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 53f4bbe0-9a84-4b34-9614-4b17f5678608

📥 Commits

Reviewing files that changed from the base of the PR and between 131bf2d and 70ee7a8.

📒 Files selected for processing (3)
  • src/components/network-modifications/voltageLevel/creation/index.ts
  • src/translations/en/networkModificationsEn.ts
  • src/translations/fr/networkModificationsFr.ts
📝 Walkthrough

Walkthrough

This PR removes the modal dialog workflow for creating switches between voltage-level sections. The SwitchesBetweenSections component is refactored to render inline EnumInput controls via useFieldArray instead of delegating to a separate dialog. Supporting dialog components and validation utilities are deleted; MAX_SECTIONS_COUNT and translations are added and used to cap section-count validation.

Changes

Switch Creation UI Refactor

Layer / File(s) Summary
Component hooks & rendering
src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx
Replace dialog state and getValues with useWatch/useFieldArray, keep setValue synchronization, add MAX_SECTIONS_COUNT guard, and render a Grid of EnumInput rows bound to SWITCH_KINDS[index].SWITCH_KIND.
Removed dialog components & utils
src/components/.../switchesBetweenSections/creation/CreateSwitchesDialog.tsx, CreateSwitchesDialogSubmitButton.tsx, createSwitchesDialog.utils.ts, creation/index.ts, CreateSwitchesForm.tsx
Delete modal dialog component, its submit-button wrapper, and validation/empty-form utilities; remove re-export from the creation index. CreateSwitchesForm file content remains but dialog consumers were removed.
Constants, validation, and translations
src/components/network-modifications/voltageLevel/creation/voltageLevel.constants.ts, voltageLevelCreation.utils.ts, StructureTab.tsx, src/translations/en/networkModificationsEn.ts, src/translations/fr/networkModificationsFr.ts
Add MAX_SECTIONS_COUNT = 20, apply it to SECTION_COUNT Yup validation, trigger SECTION_COUNT validation on watch changes in StructureTab, and add English/French translation keys for the new validation message.

Suggested reviewers

  • achour94
🚥 Pre-merge checks | ✅ 3 | ❌ 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, containing only a template header with no actual content describing the changes. Provide a meaningful description of the refactoring changes, rationale, and any important notes for reviewers.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main refactoring change: removing CreateSwitchesDialog and replacing it with an inline form.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Copy link
Copy Markdown

@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/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx (1)

22-39: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

SWITCHES_BETWEEN_SECTIONS becomes stale when users change inline EnumInput values and is not consumed by form submission.

setSwitchesKinds (which syncs SWITCHES_BETWEEN_SECTIONS to a formatted string) is only called when section count changes. When a user selects a different switch type via the inline EnumInput dropdowns, only SWITCH_KINDS[i].switchKind updates in the form—SWITCHES_BETWEEN_SECTIONS remains frozen at its last reset value. Although the field is not currently displayed to users or sent to the backend (only SWITCH_KINDS is extracted during form submission), it is part of the form schema and watched by this component, creating unnecessary complexity and a potential source of bugs if the field is later repurposed.

Remove the useWatch on line 22–24 and the setValue(FieldConstants.SWITCHES_BETWEEN_SECTIONS, ...) call in setSwitchesKinds to eliminate the staleness issue and dead code, unless this field is actively displayed or consumed elsewhere.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx`
around lines 22 - 39, The watched field watchSwitchesBetweenSections and the
redundant write to SWITCHES_BETWEEN_SECTIONS are causing a stale/unused field;
remove the useWatch call that defines watchSwitchesBetweenSections and delete
the setValue(FieldConstants.SWITCHES_BETWEEN_SECTIONS, ...) line inside
setSwitchesKinds so setSwitchesKinds only updates FieldConstants.SWITCH_KINDS
(keep intl formatting and the setValue(FieldConstants.SWITCH_KINDS, ...) call),
ensuring no other code relies on SWITCHES_BETWEEN_SECTIONS before removing.
🧹 Nitpick comments (1)
src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx (1)

44-60: ⚡ Quick win

The switchesBetweenSectionsRef guard in useEffect is now a no-op.

The second condition — switchesBetweenSectionsRef.current === watchSwitchesBetweenSections — was designed to prevent a reset when the user had just updated SWITCHES_BETWEEN_SECTIONS via the dialog. With the dialog gone, nothing updates SWITCHES_BETWEEN_SECTIONS through user interaction, so the refs are always in sync and the condition always evaluates to true. The guard adds complexity without providing any protection.

If the intent after the refactor is simply "reset on section count change," the condition and the related switchesBetweenSectionsRef ref (lines 42, 48, 59) can be removed:

♻️ Proposed simplification
     const sectionCountRef = useRef<number>(watchSectionCount);
-    const switchesBetweenSectionsRef = useRef<string>(watchSwitchesBetweenSections);

     useEffect(() => {
-        if (
-            sectionCountRef.current !== watchSectionCount &&
-            switchesBetweenSectionsRef.current === watchSwitchesBetweenSections
-        ) {
+        if (sectionCountRef.current !== watchSectionCount) {
             const initialKindDisconnector: SwitchKindFormData = { switchKind: SwitchKind.DISCONNECTOR };
             let list = [];
             if (watchSectionCount >= 1) {
                 list = new Array(watchSectionCount - 1).fill(initialKindDisconnector);
             }
             const data: CreateSwitchesFormData = { switchKinds: list };
             setSwitchesKinds(data);
         }
         sectionCountRef.current = watchSectionCount;
-        switchesBetweenSectionsRef.current = watchSwitchesBetweenSections;
-    }, [watchSectionCount, watchSwitchesBetweenSections, setSwitchesKinds]);
+    }, [watchSectionCount, setSwitchesKinds]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx`
around lines 44 - 60, Remove the now-unused guard that compares
switchesBetweenSectionsRef.current to watchSwitchesBetweenSections and the
switchesBetweenSectionsRef ref itself: inside the useEffect that watches
watchSectionCount and watchSwitchesBetweenSections (function containing the
section count reset logic), simplify the condition to only check for a section
count change (sectionCountRef.current !== watchSectionCount) and always reset
switch kinds when that occurs; delete references to
switchesBetweenSectionsRef.current and any code that updates
switchesBetweenSectionsRef (lines referencing switchesBetweenSectionsRef, the
ref declaration, and its assignment), keeping sectionCountRef,
watchSectionCount, watchSwitchesBetweenSections, and setSwitchesKinds intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx`:
- Line 20: Replace usages of setValue for the SWITCH_KINDS array with the
replace method returned by useFieldArray: locate the useFieldArray call that
destructures fields as rows and use its replace(fnOrArray) to update the entire
FieldConstants.SWITCH_KINDS array instead of calling setValue; also add an
onChange handler (or watch + effect) tied to the SWITCH_KINDS entries (the
inline EnumInput edits) to recompute and update SWITCHES_BETWEEN_SECTIONS
whenever individual switch kinds change so SWITCHES_BETWEEN_SECTIONS doesn't go
stale after edits.

---

Outside diff comments:
In
`@src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx`:
- Around line 22-39: The watched field watchSwitchesBetweenSections and the
redundant write to SWITCHES_BETWEEN_SECTIONS are causing a stale/unused field;
remove the useWatch call that defines watchSwitchesBetweenSections and delete
the setValue(FieldConstants.SWITCHES_BETWEEN_SECTIONS, ...) line inside
setSwitchesKinds so setSwitchesKinds only updates FieldConstants.SWITCH_KINDS
(keep intl formatting and the setValue(FieldConstants.SWITCH_KINDS, ...) call),
ensuring no other code relies on SWITCHES_BETWEEN_SECTIONS before removing.

---

Nitpick comments:
In
`@src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx`:
- Around line 44-60: Remove the now-unused guard that compares
switchesBetweenSectionsRef.current to watchSwitchesBetweenSections and the
switchesBetweenSectionsRef ref itself: inside the useEffect that watches
watchSectionCount and watchSwitchesBetweenSections (function containing the
section count reset logic), simplify the condition to only check for a section
count change (sectionCountRef.current !== watchSectionCount) and always reset
switch kinds when that occurs; delete references to
switchesBetweenSectionsRef.current and any code that updates
switchesBetweenSectionsRef (lines referencing switchesBetweenSectionsRef, the
ref declaration, and its assignment), keeping sectionCountRef,
watchSectionCount, watchSwitchesBetweenSections, and setSwitchesKinds intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6bd2cb98-1d4f-4f76-b89c-613d8c8186ad

📥 Commits

Reviewing files that changed from the base of the PR and between 456a5a4 and a16241a.

📒 Files selected for processing (6)
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/CreateSwitchesDialog.tsx
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/CreateSwitchesDialogSubmitButton.tsx
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/CreateSwitchesForm.tsx
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/createSwitchesDialog.utils.ts
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/index.ts
💤 Files with no reviewable changes (5)
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/CreateSwitchesDialogSubmitButton.tsx
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/index.ts
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/createSwitchesDialog.utils.ts
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/CreateSwitchesDialog.tsx
  • src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/creation/CreateSwitchesForm.tsx

const [openCreateSwitchesDialog, setOpenCreateSwitchesDialog] = useState(false);

const { setValue } = useFormContext();
const { fields: rows } = useFieldArray({ name: `${FieldConstants.SWITCH_KINDS}` });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

cat -n src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx | head -70

Repository: gridsuite/commons-ui

Length of output: 3673


🌐 Web query:

React Hook Form useFieldArray replace method documentation

💡 Result:

The replace method from React Hook Form's useFieldArray hook replaces the entire field array with a new array of objects. Its signature is replace(obj: object[]) => void [1][2]. It fully replaces the field array values in one action, useful for loading new initial values or completely resetting the array [1][3][4]. Example usage from the official docs: const { fields, replace } = useFieldArray({ control, name: "test" }); const handleReplace = () => { replace([{ value: 'dolor' }, { value: 'sit' }]); }; This clears existing fields and sets the new array, with each object receiving an auto-generated id for React keys [1][2][5]. Note: Data must be complete objects (not partial), similar to append/prepend/insert/update [1]. The method was added in v7.15.0 via PR #6304 [3].

Citations:


🏁 Script executed:

rg "SWITCHES_BETWEEN_SECTIONS" --type ts --type tsx -n

Repository: gridsuite/commons-ui

Length of output: 92


🏁 Script executed:

cat -n src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx | sed -n '40,62p'

Repository: gridsuite/commons-ui

Length of output: 1320


🏁 Script executed:

rg "SWITCHES_BETWEEN_SECTIONS" -n

Repository: gridsuite/commons-ui

Length of output: 1206


🏁 Script executed:

cat -n src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx | sed -n '60,90p'

Repository: gridsuite/commons-ui

Length of output: 1286


🏁 Script executed:

rg "EnumInput" --type-list | head -20

Repository: gridsuite/commons-ui

Length of output: 454


🏁 Script executed:

fd "EnumInput" --extension ts --extension tsx | head -5

Repository: gridsuite/commons-ui

Length of output: 127


🏁 Script executed:

cat -n src/components/network-modifications/voltageLevel/creation/voltageLevel.constants.ts | sed -n '35,45p'

Repository: gridsuite/commons-ui

Length of output: 521


🏁 Script executed:

cat -n src/components/inputs/reactHookForm/selectInputs/EnumInput.tsx | head -50

Repository: gridsuite/commons-ui

Length of output: 2095


🌐 Web query:

React Hook Form setValue field array deprecation changelog v8

💡 Result:

In React Hook Form versions prior to v8 (current stable is v7.74.0 as of April 2026 [1][2]), using setValue to update an entire field array (e.g., setValue("fieldArray", [{...}, {...}])) is supported but causes the targeted field array fields to unmount and remount [3][4]. The official docs recommend using replace from useFieldArray instead and warn: "update entire field array with setValue will be removed in the next major version" [3]. This warning has appeared in the setValue documentation [3] and aligns with v8 being the next major version. For v8 (currently at beta.1 released Jan 11, 2026 [5], no stable release yet [6][7][1]), this becomes a breaking change: "setValue no longer direct update useFieldArray, instead use replace api" [5][8]. Developers must migrate to useFieldArray's replace method for entire field array updates to avoid unmounting issues and ensure compatibility with v8 [4]. No full v8 changelog for stable exists yet, as it's in beta [9][10]. Recent v7 issues discuss setValue field array bugs [11], but the deprecation path is clear from docs and v8 beta notes [3][5].

Citations:


Replace setValue on SWITCH_KINDS with useFieldArray's replace method.

React Hook Form v8 (currently in beta) breaks setValue for entire field arrays. The docs explicitly recommend using replace from useFieldArray instead. Additionally, SWITCHES_BETWEEN_SECTIONS becomes stale after inline EnumInput edits since it's only updated when the section count resets, not when users modify individual switch kinds directly.

🔧 Proposed changes
-    const { fields: rows } = useFieldArray({ name: `${FieldConstants.SWITCH_KINDS}` });
+    const { fields: rows, replace } = useFieldArray({ name: `${FieldConstants.SWITCH_KINDS}` });
-        setValue(FieldConstants.SWITCH_KINDS, data[FieldConstants.SWITCH_KINDS]);
+        replace(data[FieldConstants.SWITCH_KINDS]);

Consider adding an onChange listener to SWITCH_KINDS to regenerate SWITCHES_BETWEEN_SECTIONS whenever individual switch kinds change, keeping the display consistent.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const { fields: rows } = useFieldArray({ name: `${FieldConstants.SWITCH_KINDS}` });
const { fields: rows, replace } = useFieldArray({ name: `${FieldConstants.SWITCH_KINDS}` });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/components/network-modifications/voltageLevel/creation/tabs/structureTab/switchesBetweenSections/SwitchesBetweenSections.tsx`
at line 20, Replace usages of setValue for the SWITCH_KINDS array with the
replace method returned by useFieldArray: locate the useFieldArray call that
destructures fields as rows and use its replace(fnOrArray) to update the entire
FieldConstants.SWITCH_KINDS array instead of calling setValue; also add an
onChange handler (or watch + effect) tied to the SWITCH_KINDS entries (the
inline EnumInput edits) to recompute and update SWITCHES_BETWEEN_SECTIONS
whenever individual switch kinds change so SWITCHES_BETWEEN_SECTIONS doesn't go
stale after edits.

…ops for compatibility with MUI v5

Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
Copy link
Copy Markdown
Contributor

@dbraquart dbraquart left a comment

Choose a reason for hiding this comment

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

code: ok
tests: ok

open question before approve: could we have a max value for section number ? I tried 1000 and my browser was in total panic !

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link
Copy Markdown
Contributor

@dbraquart dbraquart left a comment

Choose a reason for hiding this comment

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

code & tests: ok

@TheMaskedTurtle TheMaskedTurtle merged commit 45ea257 into main May 13, 2026
5 of 6 checks passed
@TheMaskedTurtle TheMaskedTurtle deleted the jorism/feat/simplify-OC-UI branch May 13, 2026 13:53
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