Skip to content

Clean up notification-types.ts#3799

Open
flomillot wants to merge 8 commits intomainfrom
clean-notif-types
Open

Clean up notification-types.ts#3799
flomillot wants to merge 8 commits intomainfrom
clean-notif-types

Conversation

@flomillot
Copy link
Contributor

@flomillot flomillot commented Mar 11, 2026

No description provided.

Signed-off-by: Florent MILLOT <florent.millot_externe@rte-france.com>
@flomillot flomillot requested review from Meklo and sBouzols March 11, 2026 13:42
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Replaced ad-hoc JSON parsing and usages of StudyUpdateEventData with parseEventData<CommonStudyEventData> across multiple listeners/handlers, added guards to skip processing when parsing yields falsy data, corrected one predicate import name, and heavily consolidated/removed many notification types and related exports in types/notification-types.ts.

Changes

Cohort / File(s) Summary
Dialog & parameter notifications
src/components/dialogs/parameters/use-parameters-notification.ts
Switched parsing to parseEventData<CommonStudyEventData> and added a guard so notification checks run only when parsed data is truthy.
Graph menu handlers
src/components/graph/menus/dynamic-simulation/event-modification-scenario-editor.tsx, src/components/graph/menus/network-modifications/network-modification-node-editor.tsx
Changed parse generic to CommonStudyEventData; added early-return guards when parseEventData returns falsy to avoid further type checks and side effects.
Root network listeners
src/components/graph/menus/root-network/use-root-network-notifications.ts
Consolidated multiple handlers into one callback using parseEventData<CommonStudyEventData>, added early-return when parsing fails, and retained existing per-notification control flow.
Root network search notifications
src/components/graph/menus/root-network/use-root-network-search-notifications.ts
Fixed predicate name: replaced isNodSubTreeCreatedNotification with isNodeSubTreeCreatedNotification, affecting the branch that triggers resetNodesSearch().
Single-line / simulation loaders
src/components/grid-layout/cards/diagrams/singleLineDiagram/hooks/use-one-bus-shortcircuit-analysis-loader.tsx
Switched to parseEventData<CommonStudyEventData> and restructured boolean checks so both result/failure predicates are gated by truthy eventData.
Network panel
src/components/network/network-map-panel.tsx
Replaced inline JSON.parse with parseEventData<CommonStudyEventData>, added defensive truthy checks before applying notification predicates, and updated imports to include parseEventData/CommonStudyEventData.
Optional loading hook
src/hooks/use-optional-loading-parameters.ts
Replaced JSON.parse + ad-hoc casting with parseEventData<CommonStudyEventData>, added guard for parsed payload and study UUID check, and updated imports.
Study path hook
src/hooks/use-study-path.ts
Changed generic to CommonStudyEventData in parseEventData calls and updated imports; preserved metadata update flow but gated on parsed event data.
Study impacts hook
src/hooks/use-get-study-impacts.ts
Now uses parseEventData<CommonStudyEventData> instead of JSON.parse, early-returns when parsed payload is missing, then continues existing isStudyNotification filtering and payload deserialization.
Notification types & guards
src/types/notification-types.ts
Major API reshaping: removed many exported notification constants, header/event interfaces, unions and computation-related types; introduced/exported CommonStudyEventData (now `payload: string
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.63% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided, making it impossible to evaluate whether it relates to the changeset. Add a description explaining the motivation, scope, and impact of removing notification type exports and consolidating the notification handling across multiple files.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Clean up notification-types.ts' directly describes the main change: removing unused exports and consolidating notification type definitions in the notification-types.ts file.

✏️ 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 and usage tips.

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: 2

🧹 Nitpick comments (2)
src/types/notification-types.ts (1)

731-735: Type guard does not narrow the type.

The function isSpreadsheetNodeAliasesUpdatedNotification returns notif is CommonStudyEventData, which is the same as the input type. This makes the type guard ineffective for narrowing purposes. Consider either:

  1. Creating a specific SpreadsheetNodeAliasesUpdatedEventData interface with appropriate headers, or
  2. Removing the type predicate if narrowing isn't needed.
Suggested fix
-export function isSpreadsheetNodeAliasesUpdatedNotification(
-    notif: CommonStudyEventData
-): notif is CommonStudyEventData {
+export function isSpreadsheetNodeAliasesUpdatedNotification(notif: CommonStudyEventData): boolean {
     return notif.headers?.updateType === NotificationType.SPREADSHEET_NODE_ALIASES_UPDATED;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/types/notification-types.ts` around lines 731 - 735, The type guard is
ineffective because isSpreadsheetNodeAliasesUpdatedNotification currently claims
the input is the same type (notif is CommonStudyEventData); update it to narrow
to a new specific type (e.g., SpreadsheetNodeAliasesUpdatedEventData) that
extends CommonStudyEventData and declares the expected headers/updateType shape,
then change the function signature to return notif is
SpreadsheetNodeAliasesUpdatedEventData and keep the runtime check
notif.headers?.updateType === NotificationType.SPREADSHEET_NODE_ALIASES_UPDATED;
alternatively, if no narrower type is needed, remove the type predicate and make
the function return boolean instead, updating all call sites accordingly
(referencing isSpreadsheetNodeAliasesUpdatedNotification, CommonStudyEventData,
and NotificationType.SPREADSHEET_NODE_ALIASES_UPDATED).
src/components/graph/menus/root-network/use-root-network-notifications.ts (1)

109-117: Consider consolidating notification listeners.

Three separate useNotificationsListener calls are registered for the same NotificationsUrlKeys.STUDY channel. While this works, it could be simplified into a single listener that handles all three notification types. This is a minor optimization that could be addressed in a follow-up.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/graph/menus/root-network/use-root-network-notifications.ts`
around lines 109 - 117, Consolidate the three useNotificationsListener calls for
NotificationsUrlKeys.STUDY into a single call: create one listener callback
(e.g., a wrapper function) that inspects the incoming notification payload
(type/event field) and delegates to rootNetworksUpdatedNotification,
rootNetworksUpdateFailedNotification, or rootNetworkDeletionStartedNotification
as appropriate, then pass that wrapper as listenerCallbackMessage to
useNotificationsListener(NotificationsUrlKeys.STUDY); this keeps the same
behavior but registers only one listener.
🤖 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/types/notification-types.ts`:
- Around line 686-688: Rename the predicate function
isNodSubTreeCreatedNotification to isNodeSubTreeCreatedNotification in the
declaration inside notification-types (update the export name) and update all
imports/usages to the new name (e.g., inside useRootNetworkSearchNotifications
and any other modules importing it); ensure TypeScript types and any type-guard
signatures remain identical so only the identifier changes.
- Around line 384-387: The code in use-get-study-impacts.ts parses
eventData.payload with JSON.parse without guarding for undefined; update the
logic (where JSON.parse(eventData.payload) is called) to first check that
eventData.payload is a non-empty string (or truthy) and only then attempt
JSON.parse, and wrap the parse in a try-catch similar to
use-workspace-notifications.ts so undefined or invalid JSON does not throw —
reference the CommonStudyEventData type, the eventData variable, and the
JSON.parse call in use-get-study-impacts.ts to locate and fix the issue.

---

Nitpick comments:
In `@src/components/graph/menus/root-network/use-root-network-notifications.ts`:
- Around line 109-117: Consolidate the three useNotificationsListener calls for
NotificationsUrlKeys.STUDY into a single call: create one listener callback
(e.g., a wrapper function) that inspects the incoming notification payload
(type/event field) and delegates to rootNetworksUpdatedNotification,
rootNetworksUpdateFailedNotification, or rootNetworkDeletionStartedNotification
as appropriate, then pass that wrapper as listenerCallbackMessage to
useNotificationsListener(NotificationsUrlKeys.STUDY); this keeps the same
behavior but registers only one listener.

In `@src/types/notification-types.ts`:
- Around line 731-735: The type guard is ineffective because
isSpreadsheetNodeAliasesUpdatedNotification currently claims the input is the
same type (notif is CommonStudyEventData); update it to narrow to a new specific
type (e.g., SpreadsheetNodeAliasesUpdatedEventData) that extends
CommonStudyEventData and declares the expected headers/updateType shape, then
change the function signature to return notif is
SpreadsheetNodeAliasesUpdatedEventData and keep the runtime check
notif.headers?.updateType === NotificationType.SPREADSHEET_NODE_ALIASES_UPDATED;
alternatively, if no narrower type is needed, remove the type predicate and make
the function return boolean instead, updating all call sites accordingly
(referencing isSpreadsheetNodeAliasesUpdatedNotification, CommonStudyEventData,
and NotificationType.SPREADSHEET_NODE_ALIASES_UPDATED).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 905ccd1e-82e6-4884-9e84-a5a32eb552bf

📥 Commits

Reviewing files that changed from the base of the PR and between 94eed1c and d2a039e.

📒 Files selected for processing (9)
  • src/components/dialogs/parameters/use-parameters-notification.ts
  • src/components/graph/menus/dynamic-simulation/event-modification-scenario-editor.tsx
  • src/components/graph/menus/network-modifications/network-modification-node-editor.tsx
  • src/components/graph/menus/root-network/use-root-network-notifications.ts
  • src/components/grid-layout/cards/diagrams/singleLineDiagram/hooks/use-one-bus-shortcircuit-analysis-loader.tsx
  • src/components/network/network-map-panel.tsx
  • src/hooks/use-optional-loading-parameters.ts
  • src/hooks/use-study-path.ts
  • src/types/notification-types.ts

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.

♻️ Duplicate comments (1)
src/types/notification-types.ts (1)

699-700: ⚠️ Potential issue | 🟡 Minor

Fix typo in exported predicate name (isNodSubTreeCreatedNotification).

Line 699 still exposes the misspelled public function name. Please rename it to isNodeSubTreeCreatedNotification and update its imports/usages.

✏️ Proposed rename
-export function isNodSubTreeCreatedNotification(notif: CommonStudyEventData): notif is SubtreeCreatedEventData {
+export function isNodeSubTreeCreatedNotification(notif: CommonStudyEventData): notif is SubtreeCreatedEventData {
     return notif.headers?.updateType === NotificationType.SUBTREE_CREATED;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/types/notification-types.ts` around lines 699 - 700, The exported
predicate function has a typo: rename isNodSubTreeCreatedNotification to
isNodeSubTreeCreatedNotification and keep its implementation and type guard
signature (notif: CommonStudyEventData): notif is SubtreeCreatedEventData
unchanged; update all references/imports/usages of
isNodSubTreeCreatedNotification throughout the codebase to the new name and
ensure any exports or re-exports reflect isNodeSubTreeCreatedNotification,
leaving the NotificationType.SUBTREE_CREATED comparison intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/types/notification-types.ts`:
- Around line 699-700: The exported predicate function has a typo: rename
isNodSubTreeCreatedNotification to isNodeSubTreeCreatedNotification and keep its
implementation and type guard signature (notif: CommonStudyEventData): notif is
SubtreeCreatedEventData unchanged; update all references/imports/usages of
isNodSubTreeCreatedNotification throughout the codebase to the new name and
ensure any exports or re-exports reflect isNodeSubTreeCreatedNotification,
leaving the NotificationType.SUBTREE_CREATED comparison intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 65a95292-a684-4d68-abfe-dd9712a4385d

📥 Commits

Reviewing files that changed from the base of the PR and between d2a039e and bba201b.

📒 Files selected for processing (1)
  • src/types/notification-types.ts

- Consolidated notification callbacks into `rootNetworkNotificationHandler`.
- Fixed typos in notification type names (e.g., `isNodSubTreeCreatedNotification` -> `isNodeSubTreeCreatedNotification`).
- Improved event data parsing with `parseEventData` utility.

Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
@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.

Caution

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

⚠️ Outside diff range comments (1)
src/hooks/use-get-study-impacts.ts (1)

56-72: ⚠️ Potential issue | 🟠 Major

Unguarded JSON.parse() can throw and break notification handling.

Line 58 guards against missing payload, but Line 72's JSON.parse(eventData.payload) remains unprotected. Malformed JSON in a valid payload string throws SyntaxError uncaught in the callback, breaking subsequent notification processing.

Suggested hardening
-                const {
-                    impactedSubstationsIds: substationsIds,
-                    deletedEquipments,
-                    impactedElementTypes,
-                } = JSON.parse(eventData.payload) as NetworkImpactsInfos;
+                let impacts: NetworkImpactsInfos;
+                try {
+                    impacts = JSON.parse(eventData.payload) as NetworkImpactsInfos;
+                } catch {
+                    return;
+                }
+
+                const {
+                    impactedSubstationsIds: substationsIds,
+                    deletedEquipments,
+                    impactedElementTypes,
+                } = impacts;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/hooks/use-get-study-impacts.ts` around lines 56 - 72, The notification
handler uses JSON.parse(eventData.payload) unguarded inside the
use-get-study-impacts hook (after parseEventData and isStudyNotification
checks), which can throw on malformed payloads; wrap the parse in a try/catch
around the JSON.parse call that produces
impactedSubstationsIds/deletedEquipments/impactedElementTypes (the destructuring
from JSON.parse(eventData.payload) as NetworkImpactsInfos), log or handle the
parse error (e.g., processLogger.warn or a local logger) and return early so the
callback continues safely when payload is invalid, keeping the existing guards
for node/rootNetwork (currentRootNetworkUuid and currentNode?.id) intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/hooks/use-get-study-impacts.ts`:
- Around line 56-72: The notification handler uses JSON.parse(eventData.payload)
unguarded inside the use-get-study-impacts hook (after parseEventData and
isStudyNotification checks), which can throw on malformed payloads; wrap the
parse in a try/catch around the JSON.parse call that produces
impactedSubstationsIds/deletedEquipments/impactedElementTypes (the destructuring
from JSON.parse(eventData.payload) as NetworkImpactsInfos), log or handle the
parse error (e.g., processLogger.warn or a local logger) and return early so the
callback continues safely when payload is invalid, keeping the existing guards
for node/rootNetwork (currentRootNetworkUuid and currentNode?.id) intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ef74b0b2-0d93-4deb-98ba-53d4c771def3

📥 Commits

Reviewing files that changed from the base of the PR and between bba201b and 5c8fde6.

📒 Files selected for processing (4)
  • src/components/graph/menus/root-network/use-root-network-notifications.ts
  • src/components/graph/menus/root-network/use-root-network-search-notifications.ts
  • src/hooks/use-get-study-impacts.ts
  • src/types/notification-types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/types/notification-types.ts

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.

1 participant