Skip to content

Add voltage-level band filtering to NAD#4029

Open
flomillot wants to merge 15 commits into
mainfrom
nad-voltage-level-filtering
Open

Add voltage-level band filtering to NAD#4029
flomillot wants to merge 15 commits into
mainfrom
nad-voltage-level-filtering

Conversation

@flomillot

@flomillot flomillot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Overview

Adds voltage-level band filtering to the Network Area Diagram (NAD), mirroring the geographic map's existing nominal-voltage filter. The user can show/hide voltage-level bands from a sidebar; bands are masked via CSS classes on the already-rendered SVG, without refetching the diagram.

Changes

  • useNadVoltageLevelFilter hook — derives the voltage-level bands present in the current diagram from the SVG metadata CSS classes (nad-voltage-level-*), and tracks the selected bands. Returns the unselected band names so the diagram can hide them.
  • CSS-based maskingnetwork-area-diagram-content.tsx turns the unselected bands into display: none rules targeting the nad-* classes, merged into the diagram container sx.
  • NominalVoltageFilter — the two select-all / select-none buttons are replaced by a single master checkbox with an indeterminate state. Added per-element style overrides so the filter blends into the NAD sidebar instead of floating like the map overlay.

Need gridsuite/commons-ui#1203

Allow filtering the Network Area Diagram by voltage-level bands from a
sidebar, reusing the geographic map's NominalVoltageFilter. Bands are
hidden via CSS classes on the rendered SVG, without refetching the
diagram.

- Extract the filtering logic into a useNadVoltageLevelFilter hook
  deriving present bands from the SVG metadata CSS classes.
- Turn NominalVoltageFilter's two select-all/none buttons into a single
  master checkbox with an indeterminate state, and expose per-element
  style overrides so it blends into the NAD sidebar.
- Make NavigationSidebar own its collapse state internally, keyed by
  section id, with disabled sections forced collapsed.
- Rename our components' `disabled` prop to `isDisabled` to disambiguate
  from MUI's native `disabled`.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds a voltage-level band filter to the Network Area Diagram (NAD) panel. It refactors NominalVoltageFilter with a renamed isDisabled prop and new NominalVoltageFilterStyles interface, converts NavigationSidebar to a sections-based accordion API with an extracted HistorySectionContent component, introduces useNadVoltageLevelFilter to derive present voltage bands from SVG metadata, and wires filter state through NadPanelContent to hide selected bands in NetworkAreaDiagramContent via CSS. SldNavigationSidebar is updated to use the new sidebar API.

Changes

NAD Voltage-Level Band Filter

Layer / File(s) Summary
NominalVoltageFilter refactor
src/components/network/nominal-voltage-filter.tsx, src/components/network/network-map-panel.tsx
Renames disabled to isDisabled, exports NominalVoltageFilterStyles for sx overrides, switches all inline styles to mergeSx-based sx objects, replaces select-all/select-none button controls with a single indeterminate master checkbox, updates per-interval toggle disable logic, and NetworkMapPanel is updated to pass isDisabled.
NavigationSidebar sections API and HistorySectionContent
src/components/workspace/diagrams/common/navigation-sidebar.tsx
Rewrites NavigationSidebar to accept sections: SidebarSection[], manages internal expand/collapse state via expandedIds and toggleExpand, renders a collapsed icon rail or expanded section headers with conditional content, and extracts HistorySectionContent as a new exported component rendering navigationHistory as clickable items.
useNadVoltageLevelFilter and NetworkAreaDiagramContent hiddenVoltageBands
src/components/workspace/diagrams/nad/use-nad-voltage-level-filter.ts, src/components/grid-layout/cards/diagrams/networkAreaDiagram/network-area-diagram-content.tsx
Adds useNadVoltageLevelFilter hook to parse SVG metadata CSS classes into present nominal voltage options, manage user selection state initialized to all available voltages, and return unselectedVlNames for bands to hide. Extends NetworkAreaDiagramContent with optional hiddenVoltageBands prop that generates a memoized sx object mapping each band class to display: none.
NAD end-to-end wiring
src/components/workspace/panel-contents/diagrams/nad/nad-panel-content.tsx, src/components/workspace/diagrams/nad/nad-navigation-sidebar.tsx, src/translations/en.json, src/translations/fr.json
NadPanelContent calls useNadVoltageLevelFilter with diagram metadata, passes unselectedVlNames to NetworkAreaDiagramContent, and renders NadNavigationSidebar with voltage filter inputs. NadNavigationSidebar builds two memoized sections (history and voltage filter), applies disabled logic based on available data and node built state, renders NominalVoltageFilter with sidebar-integrated sx overrides, and returns NavigationSidebar with sections prop. Translation keys nadVoltageFilter are added in English and French.
SldNavigationSidebar adapted to sections API
src/components/workspace/diagrams/sld/sld-navigation-sidebar.tsx
Replaces collapse-state management and old NavigationSidebar prop wiring with a useMemo-built sections array containing a history section using HistorySectionContent, removing useState and adopting the new sections-based API.

Suggested Reviewers

  • sBouzols
  • SlimaneAmar
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add voltage-level band filtering to NAD' directly and clearly describes the main change: introducing voltage-level band filtering functionality to the Network Area Diagram.
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.
Description check ✅ Passed The pull request description clearly explains the feature being added (voltage-level band filtering for NAD), the implementation approach, and lists all major changes made.

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


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/workspace/diagrams/common/navigation-sidebar.tsx (2)

162-165: 💤 Low value

Section title color doesn't reflect disabled state.

The icon receives disabled color via styles.icon(theme, enabled), but the Typography text remains unchanged when enabled is false. Consider adding consistent disabled styling:

🎨 Proposed fix
-                                      <Typography variant="caption" sx={{ ml: 1, fontWeight: 'medium' }}>
+                                      <Typography
+                                          variant="caption"
+                                          sx={{
+                                              ml: 1,
+                                              fontWeight: 'medium',
+                                              color: enabled ? 'text.primary' : 'text.disabled',
+                                          }}
+                                      >
🤖 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/workspace/diagrams/common/navigation-sidebar.tsx` around lines
162 - 165, The Typography component displaying the section title does not
reflect the disabled state styling even though the icon does via
styles.icon(theme, enabled). Add consistent disabled styling to the Typography
component by passing the enabled parameter to its sx prop, following the same
pattern used for the icon styling. Create or use an appropriate styles function
(similar to styles.icon) that applies disabled color/opacity to the Typography
variant when enabled is false, ensuring both the icon and title text have
matching visual treatment for the disabled state.

153-171: ⚡ Quick win

Expanded section header is not keyboard accessible.

The clickable Box at lines 158-166 lacks tabIndex, role="button", and onKeyDown handling. Users who expand a section via keyboard cannot collapse it without a mouse.

Consider using ButtonBase or adding accessibility attributes:

♿ Proposed fix using ButtonBase
+import { ButtonBase } from '`@mui/material`';
...
-                                  <Box
-                                      onClick={enabled ? () => toggleExpand(section.id) : undefined}
-                                      sx={styles.headerExpanded(theme, enabled)}
-                                  >
+                                  <ButtonBase
+                                      onClick={enabled ? () => toggleExpand(section.id) : undefined}
+                                      disabled={!enabled}
+                                      sx={styles.headerExpanded(theme, enabled)}
+                                  >
                                       <Box sx={styles.icon(theme, enabled)}>{section.icon}</Box>
                                       <Typography variant="caption" sx={{ ml: 1, fontWeight: 'medium' }}>
                                           {intl.formatMessage({ id: section.titleId })}
                                       </Typography>
-                                  </Box>
+                                  </ButtonBase>
🤖 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/workspace/diagrams/common/navigation-sidebar.tsx` around lines
153 - 171, The clickable Box element used as the section header (which calls
toggleExpand(section.id) on click) lacks keyboard accessibility. Add keyboard
support by either replacing the Box with a ButtonBase component from
Material-UI, or by adding tabIndex="0", role="button", and an onKeyDown handler
to the Box that triggers toggleExpand(section.id) when the Enter or Space keys
are pressed, ensuring the behavior mirrors the existing onClick handling and
respects the enabled conditional logic already present.
🤖 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/workspace/diagrams/nad/use-nad-voltage-level-filter.ts`:
- Around line 56-61: The setSelectedNominalVoltages state update in the
useEffect hook only initializes when prev is undefined, causing stale voltage
selections to persist when switching between different NADs. Replace the
conditional logic (prev ?? presentNominalVoltages) with a direct assignment to
presentNominalVoltages so that selected voltages are reset whenever the
available nominal voltages change, preventing stale selections from hiding bands
or producing incorrect unselectedVlNames.

---

Nitpick comments:
In `@src/components/workspace/diagrams/common/navigation-sidebar.tsx`:
- Around line 162-165: The Typography component displaying the section title
does not reflect the disabled state styling even though the icon does via
styles.icon(theme, enabled). Add consistent disabled styling to the Typography
component by passing the enabled parameter to its sx prop, following the same
pattern used for the icon styling. Create or use an appropriate styles function
(similar to styles.icon) that applies disabled color/opacity to the Typography
variant when enabled is false, ensuring both the icon and title text have
matching visual treatment for the disabled state.
- Around line 153-171: The clickable Box element used as the section header
(which calls toggleExpand(section.id) on click) lacks keyboard accessibility.
Add keyboard support by either replacing the Box with a ButtonBase component
from Material-UI, or by adding tabIndex="0", role="button", and an onKeyDown
handler to the Box that triggers toggleExpand(section.id) when the Enter or
Space keys are pressed, ensuring the behavior mirrors the existing onClick
handling and respects the enabled conditional logic already present.
🪄 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: ada0bf48-d825-425a-96b1-d742899ab829

📥 Commits

Reviewing files that changed from the base of the PR and between 039e719 and 6747d0c.

📒 Files selected for processing (10)
  • src/components/grid-layout/cards/diagrams/networkAreaDiagram/network-area-diagram-content.tsx
  • src/components/network/network-map-panel.tsx
  • src/components/network/nominal-voltage-filter.tsx
  • src/components/workspace/diagrams/common/navigation-sidebar.tsx
  • src/components/workspace/diagrams/nad/nad-navigation-sidebar.tsx
  • src/components/workspace/diagrams/nad/use-nad-voltage-level-filter.ts
  • src/components/workspace/diagrams/sld/sld-navigation-sidebar.tsx
  • src/components/workspace/panel-contents/diagrams/nad/nad-panel-content.tsx
  • src/translations/en.json
  • src/translations/fr.json

Comment thread src/components/workspace/diagrams/nad/use-nad-voltage-level-filter.ts Outdated
flomillot and others added 4 commits June 16, 2026 14:45
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
@sonarqubecloud

Copy link
Copy Markdown

flomillot and others added 4 commits June 19, 2026 16:34
… icons

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>

@Meklo Meklo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When a new nominal voltage is added in the NAD (e.g. expanding voltage levels, adding a specific voltage level..) shouldn't its nominal voltage be preselected by default if All was ticked ? It would prevent confusion why the data doesn't show up

Comment thread src/components/workspace/diagrams/nad/nad-navigation-sidebar.tsx Outdated
Comment thread src/components/workspace/diagrams/common/navigation-sidebar.tsx
Comment thread src/translations/en.json
Comment thread src/translations/fr.json
flomillot and others added 3 commits June 26, 2026 16:49
Rename the NAD navigation sidebar props to allNominalVoltages,
selectedNominalVoltages and onNominalVoltagesChange (plus the
checkedNominalVoltages callback param and the hasNominalVoltages local),
and import the renamed NominalVoltageIcon from commons-ui.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
When a nominal voltage appears in the NAD (e.g. after expanding or adding
a voltage level), automatically add it to the current selection so its
data shows up by default, even when not all voltages are ticked.
Voltages explicitly unticked by the user stay hidden.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
@flomillot

flomillot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

When a new nominal voltage is added in the NAD (e.g. expanding voltage levels, adding a specific voltage level..) shouldn't its nominal voltage be preselected by default if All was ticked ? It would prevent confusion why the data doesn't show up

I didn't know it was possible but indeed if it's possible you're right. I Changed it.

edit : finally after discussion with the PO we dont change them

Keep the voltage selection across node, root-network and filter changes,
and never auto-check newly-present voltages. The selection is reset to
'all shown' only when a different NAD is loaded (its config uuid changes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
@flomillot flomillot requested a review from Meklo June 26, 2026 16:27
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