Skip to content

add cut off power tab#3906

Open
ghazwarhili wants to merge 5 commits into
mainfrom
add-cut-off-power-tab
Open

add cut off power tab#3906
ghazwarhili wants to merge 5 commits into
mainfrom
add-cut-off-power-tab

Conversation

@ghazwarhili
Copy link
Copy Markdown
Contributor

PR Summary

add cut off power tab

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 206c7b52-7d14-4dd2-8a50-123c79d8a204

📥 Commits

Reviewing files that changed from the base of the PR and between cade551 and 62c00d1.

📒 Files selected for processing (7)
  • src/components/results/securityanalysis/security-analysis-result-nmk.tsx
  • src/components/results/securityanalysis/security-analysis-result-tab.tsx
  • src/components/results/securityanalysis/security-analysis-result-utils.ts
  • src/components/results/securityanalysis/security-analysis.type.ts
  • src/components/results/securityanalysis/use-security-analysis-column-defs.tsx
  • src/translations/en.json
  • src/translations/fr.json
✅ Files skipped from review due to trivial changes (2)
  • src/translations/fr.json
  • src/translations/en.json

📝 Walkthrough

Walkthrough

Introduce NMK_TYPE with three variants and wire a new "cut-off power from constraints" result path through types, mapper and column defs, mapping, columns hook, tab UI to select nmkType, and result component switching to the new rows/style logic.

Changes

NMK power-cut-off + nmkType migration

Layer / File(s) Summary
Type additions and prop change
src/components/results/securityanalysis/security-analysis.type.ts
Add NMK_TYPE enum, add RESULT_TYPE.NMK_CUT_OFF_POWER, add CutOffPowerFromConstraintsItem & ConnectivityResult, extend SecurityAnalysisNmkTableRow, and replace isFromContingency prop with nmkType: NMK_TYPE.
Utils: mapper, columns and mapping
src/components/results/securityanalysis/security-analysis-result-utils.ts
Add mapNmKResultsCutOffPower to convert cut-off items to table rows; add securityAnalysisTableNmKCutOffPowerColumnsDefinition column set; add FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF and wire it in mappingColumnToField.
Column defs hook
src/components/results/securityanalysis/use-security-analysis-column-defs.tsx
Return the new column definitions for RESULT_TYPE.NMK_CUT_OFF_POWER in the existing switch.
Result component: nmkType-driven rows and style
src/components/results/securityanalysis/security-analysis-result-nmk.tsx
Replace boolean branching with nmkType switch to compute rows (including cut-off mapper), update getRowStyle to key off nmkType, and make postSortRows/hook deps depend on nmkType/getRowStyle.
Tab: nmkType select and wiring
src/components/results/securityanalysis/security-analysis-result-tab.tsx
Use typed SelectChangeEvent<NMK_TYPE> to set nmkType, map it to RESULT_TYPE via switch, add developer-only MenuItem for the cut-off option, and pass nmkType to SecurityAnalysisResultNmk.
Translations
src/translations/en.json, src/translations/fr.json
Add CutOffPowerFromConstraints entry in English ("Cut-off power") and French ("Puissances coupées"); add disconnectedLoadActivePower and disconnectedGenerationActivePower translation keys.

Sequence Diagram

sequenceDiagram
  actor User
  participant Tab as SecurityAnalysisResultTab
  participant NmkResult as SecurityAnalysisResultNmk
  participant Utils as ResultUtils
  participant ColDefs as ColumnDefinitions

  User->>Tab: Select nmkType from dropdown
  Tab->>Tab: Set nmkType (constraints-from-contingencies,\ncontingencies-from-constraints, or\ncut-off-power-from-constraints)
  Tab->>NmkResult: Pass nmkType prop

  alt nmkType = constraints-from-contingencies
    NmkResult->>Utils: flattenNmKResultsConstraints()
    Utils-->>NmkResult: SecurityAnalysisNmkTableRow[]
  else nmkType = contingencies-from-constraints
    NmkResult->>Utils: flattenNmKResultsContingencies()
    Utils-->>NmkResult: SecurityAnalysisNmkTableRow[]
  else nmkType = cut-off-power-from-constraints
    NmkResult->>Utils: mapNmKResultsCutOffPower()
    Utils-->>NmkResult: SecurityAnalysisNmkTableRow[]
  end

  NmkResult->>ColDefs: Request column definitions for result type
  ColDefs->>Utils: Get field-to-column mapping (mappingColumnToField)
  Utils-->>ColDefs: Mapping specific to RESULT_TYPE
  ColDefs-->>NmkResult: ColDef[]

  NmkResult->>NmkResult: Render table with mapped rows and columns
  NmkResult-->>User: Display results
Loading

Suggested reviewers

  • etiennehomer
  • AbdelHedhili
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'add cut off power tab' directly describes the primary change—adding a new cut-off power tab feature to the security analysis results.
Description check ✅ Passed The description 'add cut off power tab' is related to the changeset, accurately reflecting the main feature addition visible across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.


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

Caution

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

⚠️ Outside diff range comments (1)
src/components/results/securityanalysis/security-analysis-result-tab.tsx (1)

91-96: ⚠️ Potential issue | 🟠 Major

Reset the developer-only NMK type when developer mode is disabled.

If a user selects POWER_CUT_OFF_FROM_CONTINGENCIES and then disables developer mode, the option disappears but nmkType still drives RESULT_TYPE.NMK_POWER_CUT_OFF, so the hidden result remains fetchable/exportable.

🛡️ Proposed fix
 useEffect(() => {
     if (!isDeveloperMode && tabIndexRef.current === N_RESULTS_TAB_INDEX) {
         // handle tabIndex when dev mode is disabled
         setTabIndex(NMK_RESULTS_TAB_INDEX);
     }
+    if (!isDeveloperMode && nmkType === NMK_TYPE.POWER_CUT_OFF_FROM_CONTINGENCIES) {
+        setNmkType(NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES);
+        resetResultStates();
+        dispatchPagination({ page: 0, rowsPerPage });
+    }
-}, [isDeveloperMode]);
+}, [dispatchPagination, isDeveloperMode, nmkType, resetResultStates, rowsPerPage]);

Also applies to: 322-326

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

In `@src/components/results/securityanalysis/security-analysis-result-tab.tsx`
around lines 91 - 96, When developer mode is disabled (the useEffect that checks
!isDeveloperMode && tabIndexRef.current === N_RESULTS_TAB_INDEX), also reset the
developer-only NMK selection so it cannot drive RESULT_TYPE.NMK_POWER_CUT_OFF;
call the setter that controls the nmkType (e.g., setNmkType(...)) to a safe
default/none value so the NMK-specific result type is cleared, and apply the
same reset in the other analogous block (around the other useEffect at lines
322-326).
🧹 Nitpick comments (1)
src/components/results/securityanalysis/security-analysis-result-utils.ts (1)

599-625: Wire sort params for sortable power cut-off columns.

FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF defines backend fields for status and both power columns, but the column definitions pass undefined sort params, so these columns won’t participate in the persisted/server-side sort flow.

♻️ Proposed fix
 createEnumColumn(
     'status',
     'ComputationStatus',
     filterEnums['status'] ?? [],
     getEnumLabel,
     intl,
-    undefined,
+    sortParams,
     filterParams
 )
 makeAgGridFloatColumn(
     'disconnectedLoadActivePower',
     'disconnectedLoadActivePower',
     intl,
     filterParams,
-    undefined
+    sortParams
 )
 makeAgGridFloatColumn(
     'disconnectedGenerationActivePower',
     'disconnectedGenerationActivePower',
     intl,
     filterParams,
-    undefined
+    sortParams
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/results/securityanalysis/security-analysis-result-utils.ts`
around lines 599 - 625, The three column defs (createEnumColumn('status', ...),
and the two makeAgGridFloatColumn calls wrapped by makeAgGridCustomHeaderColumn)
pass undefined for their sort params so they won't hook into the
persisted/server-side sort flow; replace those undefined sort param arguments
with the appropriate entries from FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF (e.g.,
the mapping value for 'status', 'disconnectedLoadActivePower' and
'disconnectedGenerationActivePower') so the columns use the backend field
mapping when building sort/filter via filterParams.
🤖 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/results/securityanalysis/security-analysis-result-tab.tsx`:
- Around line 191-195: When switching NMK subtype in handleChangeNmkType, clear
the Redux column filter and sort state before calling setNmkType to avoid stale
filters for the new field mapping; update the handler (alongside
dispatchPagination and resetResultStates) to dispatch the existing actions that
clear column filters and clear sort/order (or add and call new actions like
clearColumnFilters and clearSortState) so columnFilters and sort state are reset
prior to setNmkType.

In `@src/translations/en.json`:
- Line 399: Replace the awkward label value for the translation key
"PowerCutOffFromContingencies" in src/translations/en.json with a clearer
phrase; change the string "Cut-off powers" to a singular, clearer label such as
"Cut-off power" (or "Disconnected power" if that better matches nearby column
wording) so the tab label reads naturally and aligns with existing column text.

---

Outside diff comments:
In `@src/components/results/securityanalysis/security-analysis-result-tab.tsx`:
- Around line 91-96: When developer mode is disabled (the useEffect that checks
!isDeveloperMode && tabIndexRef.current === N_RESULTS_TAB_INDEX), also reset the
developer-only NMK selection so it cannot drive RESULT_TYPE.NMK_POWER_CUT_OFF;
call the setter that controls the nmkType (e.g., setNmkType(...)) to a safe
default/none value so the NMK-specific result type is cleared, and apply the
same reset in the other analogous block (around the other useEffect at lines
322-326).

---

Nitpick comments:
In `@src/components/results/securityanalysis/security-analysis-result-utils.ts`:
- Around line 599-625: The three column defs (createEnumColumn('status', ...),
and the two makeAgGridFloatColumn calls wrapped by makeAgGridCustomHeaderColumn)
pass undefined for their sort params so they won't hook into the
persisted/server-side sort flow; replace those undefined sort param arguments
with the appropriate entries from FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF (e.g.,
the mapping value for 'status', 'disconnectedLoadActivePower' and
'disconnectedGenerationActivePower') so the columns use the backend field
mapping when building sort/filter via filterParams.
🪄 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: 6f3085cf-d28e-4b87-a4e5-b7f82b4ac47d

📥 Commits

Reviewing files that changed from the base of the PR and between d9ae39f and d47a9f7.

📒 Files selected for processing (7)
  • src/components/results/securityanalysis/security-analysis-result-nmk.tsx
  • src/components/results/securityanalysis/security-analysis-result-tab.tsx
  • src/components/results/securityanalysis/security-analysis-result-utils.ts
  • src/components/results/securityanalysis/security-analysis.type.ts
  • src/components/results/securityanalysis/use-security-analysis-column-defs.tsx
  • src/translations/en.json
  • src/translations/fr.json

Comment on lines +191 to 195
const handleChangeNmkType = (event: SelectChangeEvent<NMK_TYPE>) => {
dispatchPagination({ page: 0, rowsPerPage });
resetResultStates();
setNmkType(
nmkType === NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES
? NMK_TYPE.CONTINGENCIES_FROM_CONSTRAINTS
: NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES
);
setNmkType(event.target.value as NMK_TYPE);
};
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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Inspect SecurityAnalysis table filter/sort state keys and available reset actions.

rg -n -C3 'useComputationColumnFilters|tableSort|SECURITY_ANALYSIS_RESULT_N_K|getStoreFields|mapFieldsToColumnsFilter|clear.*Filter|reset.*Filter|clear.*Sort|reset.*Sort'

Repository: gridsuite/gridstudy-app

Length of output: 50379


🏁 Script executed:

#!/bin/bash
# Find NMK_TYPE definition and its values
rg -n "enum.*NMK_TYPE|type.*NMK_TYPE|NMK_TYPE.*=" -A 5

Repository: gridsuite/gridstudy-app

Length of output: 1438


🏁 Script executed:

#!/bin/bash
# Check how mappingColumnToField uses NMK type and what fields it maps
rg -n "mappingColumnToField|NMK_POWER_CUT_OFF" -B 2 -A 8 | head -100

Repository: gridsuite/gridstudy-app

Length of output: 10993


🏁 Script executed:

#!/bin/bash
# Search for column filter clearing or reset actions in security analysis context
rg -n "clearColumnFilters|resetColumnFilters|clearFilters|CLEAR.*FILTER" src/components/results/securityanalysis/ -A 3

Repository: gridsuite/gridstudy-app

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Check the useComputationColumnFilters hook for any clear/reset capabilities
cat src/components/results/common/column-filter/use-computation-column-filters.ts

Repository: gridsuite/gridstudy-app

Length of output: 1563


🏁 Script executed:

#!/bin/bash
# Find resetResultStates implementation
rg -n "resetResultStates|const resetResultStates" src/components/results/securityanalysis/ -B 2 -A 15

Repository: gridsuite/gridstudy-app

Length of output: 3411


🏁 Script executed:

#!/bin/bash
# Check the security-analysis-result-tab.tsx file around handleChangeNmkType to see the full context
sed -n '185,210p' src/components/results/securityanalysis/security-analysis-result-tab.tsx

Repository: gridsuite/gridstudy-app

Length of output: 891


🏁 Script executed:

#!/bin/bash
# Look for column filter clearing or resetting actions in Redux
rg -n "CLEAR.*COLUMN|RESET.*COLUMN|clearColumnFilters|resetColumnFilters|UPDATE_COMPUTATION_COLUMN_FILTERS" src/redux/ -B 2 -A 5

Repository: gridsuite/gridstudy-app

Length of output: 49


🏁 Script executed:

#!/bin/bash
# Check what actions/dispatches are available related to table filters and sorts
rg -n "export const.*[Ff]ilter|export const.*[Ss]ort" src/redux/actions.ts | grep -i "column\|clear\|reset" -i

Repository: gridsuite/gridstudy-app

Length of output: 233


🏁 Script executed:

#!/bin/bash
# Check the tableFilters redux structure
rg -n "tableFilters|columnsFilters" src/redux/reducer.ts -B 2 -A 5 | head -80

Repository: gridsuite/gridstudy-app

Length of output: 4065


🏁 Script executed:

#!/bin/bash
# Look for how column filters are updated for computation results
rg -n "updateComputationColumnFilters|UPDATE_COMPUTATION_COLUMN_FILTERS" src/ -B 2 -A 10 | head -100

Repository: gridsuite/gridstudy-app

Length of output: 6071


🏁 Script executed:

#!/bin/bash
# Check what updateColumnFiltersAction does
sed -n '1133,1155p' src/redux/actions.ts

Repository: gridsuite/gridstudy-app

Length of output: 597


Clear column filters and sort when switching NMK subtype.

Within the N-K tab, different NMK subtypes use different field mappings: NMK_POWER_CUT_OFF only maps contingencyId, status, and two disconnected power fields, while CONSTRAINTS_FROM_CONTINGENCIES and CONTINGENCIES_FROM_CONSTRAINTS include fields like limitType and side. Since filter/sort state is keyed by tab index only (not NMK subtype), switching between subtypes leaves stale filters in Redux that don't exist in the new field mapping, causing undefined field references in queryParams.

Add clearing of both column filters and sort state in handleChangeNmkType before setNmkType() is called.

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

In `@src/components/results/securityanalysis/security-analysis-result-tab.tsx`
around lines 191 - 195, When switching NMK subtype in handleChangeNmkType, clear
the Redux column filter and sort state before calling setNmkType to avoid stale
filters for the new field mapping; update the handler (alongside
dispatchPagination and resetResultStates) to dispatch the existing actions that
clear column filters and clear sort/order (or add and call new actions like
clearColumnFilters and clearSortState) so columnFilters and sort state are reset
prior to setNmkType.

Comment thread src/translations/en.json Outdated
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: 3

Caution

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

⚠️ Outside diff range comments (1)
src/components/results/securityanalysis/security-analysis-result-utils.ts (1)

169-184: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

mapNmKResultsCutOffPower rows are missing elementId, which breaks handlePostSortRows grouping.

handlePostSortRows indexes parent rows by row.data.elementId (line 649) and, for the cut-off case, will be invoked with isFromContingency = false (since nmkType !== CONSTRAINTS_FROM_CONTINGENCIES in security-analysis-result-nmk.tsx line 80). That sets isContingency = true and idField = 'subjectId'. Cut-off rows have contingencyId but no subjectId, so:

  • The first loop's row.data[idField] != null check is false → no parents are registered.
  • The second loop treats every row as a child and falls into the orphan branch mappedRows.get('contingencies').push(row).

The net result is that all rows are grouped under the 'contingencies' orphan bucket, which is not the intended behavior for a flat cut-off table. Either set elementId per row and call handlePostSortRows with a mode that treats cut-off as flat (no parent/child), or skip postSortRows entirely for CUT_OFF_POWER_FROM_CONSTRAINTS.

🛠️ Suggested direction

In security-analysis-result-nmk.tsx, only attach postSortRows for the two grouped NMK types:

-            postSortRows: handlePostSortRows(nmkType === NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES),
+            postSortRows:
+                nmkType === NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS
+                    ? undefined
+                    : handlePostSortRows(nmkType === NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES),
🤖 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/results/securityanalysis/security-analysis-result-utils.ts`
around lines 169 - 184, mapNmKResultsCutOffPower builds rows for the cut-off
table but omits elementId/subjectId, so handlePostSortRows treats every row as a
child and dumps them into the 'contingencies' orphan bucket; fix by populating
the appropriate id field on each row (set elementId or subjectId to the cut-off
row's unique id, e.g., contingencyId or subject identifier used by
handlePostSortRows) or avoid attaching postSortRows for
CUT_OFF_POWER_FROM_CONSTRAINTS in security-analysis-result-nmk.tsx so cut-off
remains a flat table; reference mapNmKResultsCutOffPower and handlePostSortRows
/ the idField ('subjectId') when making the change.
♻️ Duplicate comments (2)
src/components/results/securityanalysis/security-analysis-result-nmk.tsx (1)

78-85: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

postSortRows is broken for CUT_OFF_POWER_FROM_CONSTRAINTS.

See the root-cause comment in security-analysis-result-utils.ts on mapNmKResultsCutOffPower / handlePostSortRows. With nmkType === CUT_OFF_POWER_FROM_CONSTRAINTS, the call here passes false, which triggers the “contingencies-from-constraints” grouping path on rows that have neither subjectId nor linkedElementId, dumping every row into the orphan bucket. Either skip postSortRows for the cut-off case or extend handlePostSortRows to handle a flat mode.

🤖 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/results/securityanalysis/security-analysis-result-nmk.tsx`
around lines 78 - 85, The current useMemo for agGridProps passes postSortRows:
handlePostSortRows(nmkType === NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES), which
sends false for NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS and causes
handlePostSortRows to run the contingencies-from-constraints grouping (orphan
bucket) for rows without subjectId/linkedElementId; to fix, change agGridProps
so it does not set postSortRows when nmkType ===
NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS (i.e., omit or null-out postSortRows in
useMemo), or alternatively update handlePostSortRows and
mapNmKResultsCutOffPower to add a flat-mode branch that correctly handles
cut-off rows — target the useMemo/ agGridProps block and the functions
handlePostSortRows and mapNmKResultsCutOffPower when making the change.
src/components/results/securityanalysis/security-analysis-result-tab.tsx (1)

191-195: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Stale column filters/sort when switching NMK subtype.

Filter/sort state in Redux is keyed by tab index only, not by nmkType. Switching from CONSTRAINTS_FROM_CONTINGENCIES/CONTINGENCIES_FROM_CONSTRAINTS (which expose limitType, side, etc.) to CUT_OFF_POWER_FROM_CONSTRAINTS (which only maps contingencyId, status, disconnectedLoadActivePower, disconnectedGenerationActivePower) leaves previously-set filters/sort entries that reference fields absent from FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF. Those will be looked up via mappingColumnToField(resultType)[sort.colId] and produce undefined colIds in queryParams. Clear column filters and sort state in handleChangeNmkType before setNmkType.

🤖 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/results/securityanalysis/security-analysis-result-tab.tsx`
around lines 191 - 195, handleChangeNmkType must clear column-filter and sort
state tied to the previous NMK subtype before calling setNmkType to avoid stale
filters mapping to missing fields (see mappingColumnToField and
FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF). Update handleChangeNmkType to dispatch
actions that remove/clear column filters and sort state for the current tab (and
any nmkType-keyed entries) — e.g., clear columnFilters and sort entries in Redux
so mappingColumnToField(resultType)[sort.colId] cannot return undefined — and do
these clears before calling setNmkType; keep the existing calls to
dispatchPagination and resetResultStates intact. Ensure the clears target the
same keys the UI uses (tab index and nmkType) so queryParams no longer include
undefined colIds after switching NMK subtype.
🧹 Nitpick comments (2)
src/components/results/securityanalysis/security-analysis-result-nmk.tsx (1)

51-60: 💤 Low value

rows switch has no default — TS will return undefined if a new NMK_TYPE is added.

The switch covers all three current variants but lacks a default. If a new NMK_TYPE member is introduced without updating this site, rows will silently become undefined at runtime. Consider an exhaustiveness guard (e.g., assign to a never-typed variable in default) to surface this at compile time.

🤖 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/results/securityanalysis/security-analysis-result-nmk.tsx`
around lines 51 - 60, The switch inside useMemo that computes rows (using
nmkType and NMK_TYPE) is missing a default/exhaustiveness guard so adding a new
NMK_TYPE can make rows undefined; update the switch to include a default branch
that performs an exhaustive type check (e.g., assign nmkType to a never-typed
variable and throw an error) so TypeScript will force handling new NMK_TYPE
values — locate the rows useMemo and the cases calling
flattenNmKResultsContingencies, flattenNmKResultsConstraints, and
mapNmKResultsCutOffPower and add the default/exhaustive branch there.
src/components/results/securityanalysis/security-analysis-result-utils.ts (1)

582-632: 💤 Low value

Unused filterEnums parameter and pointless linkedElementId column.

  • filterEnums is only consumed by the status enum column via filterEnums['status'] ?? [], but the function signature exposes the whole FilterEnumsType. That's fine, but note: cut-off rows produced by mapNmKResultsCutOffPower never populate linkedElementId, so the hidden linkedElementId column (lines 626–630) serves no parent/child grouping purpose here and is just copied from the other definitions. Consider dropping it to avoid suggesting a grouping semantic that doesn't exist for this table.
  • Also, in the first column (lines 591–596), isChildren: false is the implicit default — passing it explicitly is unnecessary noise.
🤖 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/results/securityanalysis/security-analysis-result-utils.ts`
around lines 582 - 632, In securityAnalysisTableNmKCutOffPowerColumnsDefinition,
remove the hidden linkedElementId column block (the makeAgGridCustomHeaderColumn
with colId/field 'linkedElementId') because mapNmKResultsCutOffPower never sets
linkedElementId and that column falsely implies parent/child grouping; also
simplify the first column by deleting the explicit isChildren: false passed into
makeAgGridStringColumn (it’s the default) so the call to
makeAgGridStringColumn('Contingency', 'contingencyId', ...) is cleaner; keep
filterEnums usage for the 'status' column as-is.
🤖 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/results/securityanalysis/security-analysis-result-tab.tsx`:
- Around line 322-326: When isDeveloperMode is turned off the component can
retain nmkType = NMK_TYPE.CUT_OFF_Power_FROM_CONSTRAINTS (a developer-only
option) which causes the MUI Select "out-of-range value" warning and leaves
resultType resolving to NMK_POWER_CUT_OFF with no visible option; inside the
existing isDeveloperMode effect (the effect that watches isDeveloperMode around
lines 91-96) add logic to detect when isDeveloperMode becomes false and reset
nmkType to a non-developer default (for example the app’s regular default
NMK_TYPE used elsewhere, e.g., NMK_TYPE.NMK_POWER or whatever default constant
is used in this component) so the Select always has a rendered option and
resultType remains reachable from the UI.

In `@src/components/results/securityanalysis/security-analysis.type.ts`:
- Line 26: Rename the enum member CUT_OFF_Power_FROM_CONSTRAINTS to use
consistent SCREAMING_SNAKE_CASE (CUT_OFF_POWER_FROM_CONSTRAINTS) in
security-analysis.type (the enum declaration) and update every reference to that
enum member throughout the codebase (e.g., the usages currently referencing
CUT_OFF_Power_FROM_CONSTRAINTS in security-analysis-result-nmk and
security-analysis-result-tab) to the new name so all call sites compile and
remain consistent.

In `@src/translations/fr.json`:
- Line 399: The translation value for the key "CutOffPowerFromConstraints" is
plural in French ("Puissances coupées") but the English source uses singular
("Cut-off power"); update the French value to the singular form "Puissance
coupée" to match the English string (or, if the feature actually represents
multiple powers, update the English counterpart to a plural form instead) and
ensure the change is applied where "CutOffPowerFromConstraints" is defined.

---

Outside diff comments:
In `@src/components/results/securityanalysis/security-analysis-result-utils.ts`:
- Around line 169-184: mapNmKResultsCutOffPower builds rows for the cut-off
table but omits elementId/subjectId, so handlePostSortRows treats every row as a
child and dumps them into the 'contingencies' orphan bucket; fix by populating
the appropriate id field on each row (set elementId or subjectId to the cut-off
row's unique id, e.g., contingencyId or subject identifier used by
handlePostSortRows) or avoid attaching postSortRows for
CUT_OFF_POWER_FROM_CONSTRAINTS in security-analysis-result-nmk.tsx so cut-off
remains a flat table; reference mapNmKResultsCutOffPower and handlePostSortRows
/ the idField ('subjectId') when making the change.

---

Duplicate comments:
In `@src/components/results/securityanalysis/security-analysis-result-nmk.tsx`:
- Around line 78-85: The current useMemo for agGridProps passes postSortRows:
handlePostSortRows(nmkType === NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES), which
sends false for NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS and causes
handlePostSortRows to run the contingencies-from-constraints grouping (orphan
bucket) for rows without subjectId/linkedElementId; to fix, change agGridProps
so it does not set postSortRows when nmkType ===
NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS (i.e., omit or null-out postSortRows in
useMemo), or alternatively update handlePostSortRows and
mapNmKResultsCutOffPower to add a flat-mode branch that correctly handles
cut-off rows — target the useMemo/ agGridProps block and the functions
handlePostSortRows and mapNmKResultsCutOffPower when making the change.

In `@src/components/results/securityanalysis/security-analysis-result-tab.tsx`:
- Around line 191-195: handleChangeNmkType must clear column-filter and sort
state tied to the previous NMK subtype before calling setNmkType to avoid stale
filters mapping to missing fields (see mappingColumnToField and
FROM_COLUMN_TO_FIELD_NMK_POWER_CUT_OFF). Update handleChangeNmkType to dispatch
actions that remove/clear column filters and sort state for the current tab (and
any nmkType-keyed entries) — e.g., clear columnFilters and sort entries in Redux
so mappingColumnToField(resultType)[sort.colId] cannot return undefined — and do
these clears before calling setNmkType; keep the existing calls to
dispatchPagination and resetResultStates intact. Ensure the clears target the
same keys the UI uses (tab index and nmkType) so queryParams no longer include
undefined colIds after switching NMK subtype.

---

Nitpick comments:
In `@src/components/results/securityanalysis/security-analysis-result-nmk.tsx`:
- Around line 51-60: The switch inside useMemo that computes rows (using nmkType
and NMK_TYPE) is missing a default/exhaustiveness guard so adding a new NMK_TYPE
can make rows undefined; update the switch to include a default branch that
performs an exhaustive type check (e.g., assign nmkType to a never-typed
variable and throw an error) so TypeScript will force handling new NMK_TYPE
values — locate the rows useMemo and the cases calling
flattenNmKResultsContingencies, flattenNmKResultsConstraints, and
mapNmKResultsCutOffPower and add the default/exhaustive branch there.

In `@src/components/results/securityanalysis/security-analysis-result-utils.ts`:
- Around line 582-632: In securityAnalysisTableNmKCutOffPowerColumnsDefinition,
remove the hidden linkedElementId column block (the makeAgGridCustomHeaderColumn
with colId/field 'linkedElementId') because mapNmKResultsCutOffPower never sets
linkedElementId and that column falsely implies parent/child grouping; also
simplify the first column by deleting the explicit isChildren: false passed into
makeAgGridStringColumn (it’s the default) so the call to
makeAgGridStringColumn('Contingency', 'contingencyId', ...) is cleaner; keep
filterEnums usage for the 'status' column as-is.
🪄 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: fa68400c-43d4-4c88-a19e-323cef7ada0d

📥 Commits

Reviewing files that changed from the base of the PR and between d47a9f7 and cade551.

📒 Files selected for processing (7)
  • src/components/results/securityanalysis/security-analysis-result-nmk.tsx
  • src/components/results/securityanalysis/security-analysis-result-tab.tsx
  • src/components/results/securityanalysis/security-analysis-result-utils.ts
  • src/components/results/securityanalysis/security-analysis.type.ts
  • src/components/results/securityanalysis/use-security-analysis-column-defs.tsx
  • src/translations/en.json
  • src/translations/fr.json

Comment on lines +322 to +326
{isDeveloperMode && (
<MenuItem value={NMK_TYPE.CUT_OFF_Power_FROM_CONSTRAINTS}>
<FormattedMessage id="CutOffPowerFromConstraints" />
</MenuItem>
)}
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 | 🟡 Minor | ⚡ Quick win

Developer-only MenuItem can leave nmkType in an invalid state when dev mode is toggled off.

If a user selects CUT_OFF_POWER_FROM_CONSTRAINTS while isDeveloperMode is true and dev mode is later disabled, nmkType remains set to a value whose corresponding MenuItem is no longer rendered. MUI Select will warn ("out-of-range value") and resultType will still resolve to NMK_POWER_CUT_OFF, but the option is no longer reachable from the UI. Consider resetting nmkType back to a non-developer default in the existing isDeveloperMode effect (line 91-96).

♻️ Suggested fix
 useEffect(() => {
     if (!isDeveloperMode && tabIndexRef.current === N_RESULTS_TAB_INDEX) {
         // handle tabIndex when dev mode is disabled
         setTabIndex(NMK_RESULTS_TAB_INDEX);
     }
+    if (!isDeveloperMode && nmkType === NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS) {
+        setNmkType(NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES);
+    }
 }, [isDeveloperMode]);
📝 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
{isDeveloperMode && (
<MenuItem value={NMK_TYPE.CUT_OFF_Power_FROM_CONSTRAINTS}>
<FormattedMessage id="CutOffPowerFromConstraints" />
</MenuItem>
)}
useEffect(() => {
if (!isDeveloperMode && tabIndexRef.current === N_RESULTS_TAB_INDEX) {
// handle tabIndex when dev mode is disabled
setTabIndex(NMK_RESULTS_TAB_INDEX);
}
if (!isDeveloperMode && nmkType === NMK_TYPE.CUT_OFF_POWER_FROM_CONSTRAINTS) {
setNmkType(NMK_TYPE.CONSTRAINTS_FROM_CONTINGENCIES);
}
}, [isDeveloperMode]);
🤖 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/results/securityanalysis/security-analysis-result-tab.tsx`
around lines 322 - 326, When isDeveloperMode is turned off the component can
retain nmkType = NMK_TYPE.CUT_OFF_Power_FROM_CONSTRAINTS (a developer-only
option) which causes the MUI Select "out-of-range value" warning and leaves
resultType resolving to NMK_POWER_CUT_OFF with no visible option; inside the
existing isDeveloperMode effect (the effect that watches isDeveloperMode around
lines 91-96) add logic to detect when isDeveloperMode becomes false and reset
nmkType to a non-developer default (for example the app’s regular default
NMK_TYPE used elsewhere, e.g., NMK_TYPE.NMK_POWER or whatever default constant
is used in this component) so the Select always has a rendered option and
resultType remains reachable from the UI.

Comment thread src/components/results/securityanalysis/security-analysis.type.ts Outdated
Comment thread src/translations/fr.json

"ConstraintsFromContingencies": "Aléas -> contraintes",
"ContingenciesFromConstraints": "Contraintes -> aléas",
"CutOffPowerFromConstraints": "Puissances coupées",
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 | 🟡 Minor | ⚡ Quick win

Verify singular/plural consistency with English translation.

The French translation uses plural form "Puissances coupées" while the English translation at the same key uses singular "Cut-off power". This inconsistency should be verified:

  • If the feature refers to a single concept, both should use singular form: "Puissance coupée"
  • If multiple powers are meant, English should also be plural

Please confirm whether the French translation should match the English singular form.

🤖 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/translations/fr.json` at line 399, The translation value for the key
"CutOffPowerFromConstraints" is plural in French ("Puissances coupées") but the
English source uses singular ("Cut-off power"); update the French value to the
singular form "Puissance coupée" to match the English string (or, if the feature
actually represents multiple powers, update the English counterpart to a plural
form instead) and ensure the change is applied where
"CutOffPowerFromConstraints" is defined.

@sonarqubecloud
Copy link
Copy Markdown

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

1 participant