Skip to content

Handle the modification applicability per root network tag - #1281

Open
flomillot wants to merge 12 commits into
mainfrom
florent/GRD-4941-modification-applicability
Open

Handle the modification applicability per root network tag#1281
flomillot wants to merge 12 commits into
mainfrom
florent/GRD-4941-modification-applicability

Conversation

@flomillot

@flomillot flomillot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Depends on gridsuite/study-server#1053.

The applicability of a modification per root network is now held by the modification itself, keyed by root network tag, and study-server exposes it as is instead of a list of exclusions per root network.

  • ExcludedNetworkModifications is replaced by NetworkModificationApplicabilities (Record<UUID, Record<UUID, boolean>>), where a root network without an entry is applicable. The modifications carry it keyed by root network tag; it is resolved to the root network uuid on collect, so renaming a root network does not leave the table holding entries under a name nothing matches any more — which would read back as applicable until the modifications are fetched again.
  • RootNetworkChipCell reads and toggles that map on rootNetwork.rootNetworkUuid, which drops the list lookup and the branching that rebuilt the exclusions. The tag stays what the chip is labelled with.
  • The chip is disabled while its root network is being created, instead of being displayed as applicable and clickable.
  • toExclude / setToExclude leave the table meta with no replacement in the public API: NetworkModificationsTable indexes the applicability that each modification carries, and holds it in its own state so a toggle shows immediately, before the refresh the notification triggers.
  • updateModificationStatusByRootNetwork sends applicable instead of activated, following the study server rename. That parameter discriminates the mapping, so this PR and Use the modification applicability per root network tag study-server#1053 must be released together.

Goes with gridsuite/gridstudy-app#4137.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 918662cd-028e-425f-930e-043c4f849026

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 17200b4b-6428-49b2-835c-425fcf358167

📥 Commits

Reviewing files that changed from the base of the PR and between 851d88c and 3449f87.

📒 Files selected for processing (1)
  • src/features/network-modification-table/renderers/root-network-chip-cell.tsx

📝 Walkthrough

Walkthrough

Changes

The table replaces excluded-modification state with tag-specific applicability mappings. Renderers pass this state to RootNetworkChipCell, which updates applicability optimistically and rolls back failed updates. The update service sends the applicable query parameter.

Network modification applicability

Layer / File(s) Summary
Applicability state contract
src/utils/types/network-modification-types.ts, src/features/network-modification-table/network-modifications-table.tsx, src/module-tanstack.d.ts
NetworkModificationApplicabilities replaces ExcludedNetworkModifications. Table props and metadata now expose applicability state and its setter.
Applicability renderer wiring
src/features/network-modification-table/renderers/cell-renderers.tsx
The root-network renderer passes applicability state and its setter to RootNetworkChipCell.
Root-network applicability behavior
src/features/network-modification-table/renderers/root-network-chip-cell.tsx, src/services/networkModification.ts
The chip derives activation from tag applicability, updates nested state optimistically, disables root networks being created, rolls back failed updates, and sends the applicable status to the backend.

Sequence Diagram(s)

sequenceDiagram
  participant NetworkModificationsTable
  participant RootNetworkCellRenderer
  participant RootNetworkChipCell
  participant networkModification
  NetworkModificationsTable->>RootNetworkCellRenderer: Pass applicabilities and setApplicabilities
  RootNetworkCellRenderer->>RootNetworkChipCell: Pass applicability state and setter
  RootNetworkChipCell->>RootNetworkChipCell: Toggle tag-specific applicability optimistically
  RootNetworkChipCell->>networkModification: Update modification status with applicable
  networkModification-->>RootNetworkChipCell: Return success or failure
  RootNetworkChipCell->>RootNetworkChipCell: Restore prior applicability on failure
Loading

Suggested reviewers: antoinebhs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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
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.
Title check ✅ Passed The title clearly summarizes the main change: handling modification applicability per root network tag.
Description check ✅ Passed The description is directly related to the changeset and explains the applicability mapping, UI behavior, API updates, and dependency on the study-server change.

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

🤖 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/features/network-modification-table/renderers/root-network-chip-cell.tsx`:
- Around line 80-83: Update the optimistic update in the component’s chip
activation handler to pass a functional updater to setApplicabilities, deriving
the toggled map from the latest state rather than captured applicabilities while
preserving each tag’s independent update. Add a test covering two distinct
root-network tags activated within one batched interaction and verify both
updates remain applied.
🪄 Autofix

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 Plus

Run ID: 0d5ece4d-54b0-4364-8d39-e8bf1a8a5940

📥 Commits

Reviewing files that changed from the base of the PR and between 750dbe9 and 79738ea.

📒 Files selected for processing (5)
  • src/features/network-modification-table/network-modifications-table.tsx
  • src/features/network-modification-table/renderers/cell-renderers.tsx
  • src/features/network-modification-table/renderers/root-network-chip-cell.tsx
  • src/module-tanstack.d.ts
  • src/utils/types/network-modification-types.ts

Comment thread src/features/network-modification-table/renderers/root-network-chip-cell.tsx Outdated
Follows the study server rename: the endpoint sets the applicability of a
modification on one root network, not its global activation flag.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
…sx` for clarity

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

# Conflicts:
#	src/features/network-modification-table/renderers/root-network-chip-cell.tsx

@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.

Caution

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

⚠️ Outside diff range comments (2)
src/features/network-modification-table/network-modifications-table.tsx (2)

161-166: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Guard forced child refreshes against stale responses. If two force=true refreshes overlap, an older response can replace newer children because fetchSubModificationsForExpandedRows has no request-generation or supersession check. Apply only the latest response, or cancel previous refreshes.

🤖 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/features/network-modification-table/network-modifications-table.tsx`
around lines 161 - 166, Update fetchSubModificationsForExpandedRows and its
callers to track refresh generations or otherwise supersede in-flight force=true
requests, applying child-modification results only when they belong to the
latest refresh. Ensure older overlapping responses cannot overwrite newer
children while preserving normal expanded-row loading behavior.

184-185: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Move fetchSubModificationsForExpandedRows out of the state updater.

At network-modifications-table.tsx:184-185, the updater performs the async fetch. React requires updater functions to be pure and may call them twice in Strict Mode. The helper starts network requests before its first await, so duplicate updater calls can start duplicate requests and enqueue duplicate child updates. Trigger the fetch from a post-commit path, and keep the updater limited to returning the next state.

🤖 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/features/network-modification-table/network-modifications-table.tsx`
around lines 184 - 185, The setComposedModifications updater must remain pure:
remove fetchSubModificationsForExpandedRows from its callback and have it only
return the next state. Trigger the fetch from a post-commit path, such as an
effect keyed to the committed expanded-row state, while preserving the existing
newlyExpandedRowKeys behavior and child updates.

Source: Linters/SAST tools

🤖 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.

Outside diff comments:
In `@src/features/network-modification-table/network-modifications-table.tsx`:
- Around line 161-166: Update fetchSubModificationsForExpandedRows and its
callers to track refresh generations or otherwise supersede in-flight force=true
requests, applying child-modification results only when they belong to the
latest refresh. Ensure older overlapping responses cannot overwrite newer
children while preserving normal expanded-row loading behavior.
- Around line 184-185: The setComposedModifications updater must remain pure:
remove fetchSubModificationsForExpandedRows from its callback and have it only
return the next state. Trigger the fetch from a post-commit path, such as an
effect keyed to the committed expanded-row state, while preserving the existing
newlyExpandedRowKeys behavior and child updates.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2dcd1460-e57d-4205-b957-d1fdea7040b4

📥 Commits

Reviewing files that changed from the base of the PR and between 29f58d8 and 851d88c.

📒 Files selected for processing (4)
  • src/features/network-modification-table/network-modifications-table.tsx
  • src/features/network-modification-table/renderers/cell-renderers.tsx
  • src/features/network-modification-table/renderers/root-network-chip-cell.tsx
  • src/services/networkModification.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/features/network-modification-table/renderers/cell-renderers.tsx
  • src/features/network-modification-table/renderers/root-network-chip-cell.tsx
  • src/services/networkModification.ts

Also make the optimistic update and its rollback use the value captured
at click time instead of blindly toggling the current state.

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

@Mathieu-Deharbe Mathieu-Deharbe 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.

Ok for me. I didn't approve yet because I have some questions and need to check gridstudy.

Comment on lines +29 to +34
function withApplicability(
applicabilities: NetworkModificationApplicabilities,
modificationUuid: UUID,
tag: string,
applicable: boolean
): NetworkModificationApplicabilities {

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.

This function is fine but I am a bit confused by the naming. Why 'with' ?

Suggested change
function withApplicability(
applicabilities: NetworkModificationApplicabilities,
modificationUuid: UUID,
tag: string,
applicable: boolean
): NetworkModificationApplicabilities {
function updateAnApplicability(
prevApplicabilities: NetworkModificationApplicabilities,
modificationUuid: UUID,
tag: string,
applicable: boolean
): NetworkModificationApplicabilities {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What about setApplicability ?

@@ -88,17 +69,8 @@ export function RootNetworkChipCell(props: RootNetworkChipCellProps) {
data.type === ModificationType.MODIFICATION_REFERENCE || data.childFromShared;

const isModificationActivated = useMemo(() => {

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.

I think this should be called "applicable" or "applied", instead of activated : to avoid any confusion with the activated boolean that all modifications have.

Suggested change
const isModificationActivated = useMemo(() => {
const isModificationApplied = useMemo(() => {

@flomillot flomillot Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I did not know which name to choose...
I don't think applied is correct either. Because the modification is not necessarily applied yet.
And we have the same issue if we choose applicable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@coderabbitai Any suggestion ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@flomillot, use isModificationApplicable.

applicable matches the state stored in NetworkModificationApplicabilities and the applicable backend parameter. It also avoids the implication that the modification has already been applied.

const isModificationApplicable = useMemo(() => {
    return isApplicableOn(applicabilities, modificationUuid, rootNetwork.rootNetworkUuid);
}, [modificationUuid, applicabilities, rootNetwork.rootNetworkUuid]);

isModificationActivated is only required at the ActivableChip API boundary, where it is the component prop name.

You are interacting with an AI system.

tooltipMessage={rootNetwork.name}
isActivated={isModificationActivated}
isDisabled={isLoading || isDisabled || isReferenceModificationOrInsideOne}
isDisabled={isLoading || isDisabled || isReferenceModificationOrInsideOne || rootNetwork.isCreating}

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.

I think that this disable when rootNetwork.isCreating won't be approved by Stephane. It gives the impression that the applicability changed when they are enabled because the loading is over. And given that gridstudy is multi user it will be confusing.

A loading mode/icon for chip will probably be needed. But it could be in a separate ticket.

Mathieu-Deharbe and others added 2 commits August 20, 2026 15:05
Every modification carries its own applicability per root network tag, so the
table indexes them itself instead of receiving them from its parent, and the
two props leave the public API.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Warning

Your free Security trial is over. An organization admin can activate billing to continue.

flomillot and others added 4 commits August 21, 2026 14:38
The modifications carry their applicability keyed by the root network
tag, which renaming a root network changes under the table: the entries
in hand then match no tag and every root network reads back as
applicable. The tag is resolved to the root network uuid on collect, so
what the table holds survives a rename; the tag stays a label.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
…fication-applicability

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

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.

3 participants