Skip to content

Add details for errors in the security analysis parameters contingency count#1215

Open
FranckLecuyer wants to merge 11 commits into
mainfrom
add_details_for_security_analysis_parameters_contingency_count
Open

Add details for errors in the security analysis parameters contingency count#1215
FranckLecuyer wants to merge 11 commits into
mainfrom
add_details_for_security_analysis_parameters_contingency_count

Conversation

@FranckLecuyer

Copy link
Copy Markdown
Contributor

PR Summary

…y count

Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
@coderabbitai

coderabbitai Bot commented Jun 29, 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

Contingency count data now uses per-list structures, is enriched with contingency-list names, and is converted into success or failure simulation states before rendering. The contingency messages in English and French now distinguish simulated counts from non-simulatable contingencies.

Changes

Contingency Count Enrichment and Simulation Result

Layer / File(s) Summary
ContingencyCount type restructuring
src/features/parameters/common/contingency-table/types.ts
Adds ContingencyCountByContingencyList; replaces scalar ContingencyCount fields with a UUID-keyed countByContingencyList record; introduces ContingencyCountEnriched with string keys.
Enrichment, analysis helpers, and state update
src/features/parameters/common/contingency-table/contingency-table.tsx
Adds the internal success/failure union, maps contingency-list UUIDs to names, analyzes enriched counts into a simulation result, and stores that result after fetch.
Render logic and translation keys
src/features/parameters/common/contingency-table/contingency-table.tsx, src/translations/en/parameters.ts, src/translations/fr/parameters.ts
Updates simulated contingency rendering to branch on null, success, and failure states, adjusts the top-level Grid props, and replaces the combined contingency translation key with separate count and failure messages in EN and FR.

Suggested reviewers: ayolab

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description is just a placeholder and does not describe the changeset. Replace the placeholder with a brief summary of the actual changes and why they were made.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding error details to the contingency count in security analysis parameters.
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.

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

🤖 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/parameters/common/contingency-table/contingency-table.tsx`:
- Around line 231-239: The contingency-table alert branch in
contingency-table.tsx is treating a null simulatedContingencyCount as “No
contingency,” which incorrectly shows the empty-state message after fetch
failures. Update the conditional around the alert in the contingency-table
component so it only renders when simulatedContingencyCount indicates a
successful request with nbContingencies === 0, and keep the null/error path
separate from the successful zero-result path.
- Around line 96-102: The enrichment map in contingency-table.tsx is using the
display name as the key, which can overwrite entries when multiple contingency
lists share the same name. Update the enrichment logic around the
contingencyCount.countByContingencyList loop so enriched stays keyed by
contingencyListUuid (or equivalent UUID key) and attach listName as a field on
the stored value instead of using it as the record key. Make sure any downstream
code that reads the enriched data preserves the UUID-based lookup and uses the
human-readable name only for display.
- Around line 132-135: The contingency-table missing-elements check is using
`.length` on `contingencyEquipments`, but this value is a Set stored in
`notFoundElements`, so the branch never runs. Update the conditional in
`contingency-table.tsx` to use `Set.size` instead, keeping the surrounding
`contingencyEquipments` check and the failure-alert path in place. Reference the
`notFoundElements` lookup and the `contingencyEquipments` guard so the
missing-elements alert becomes reachable again.

In `@src/translations/fr/parameters.ts`:
- Line 238: The French translation entry contingenciesWillNotBeSimulated
contains a typo in the message text. Update the string so “velide” is corrected
to “valide” in the parameters translation object.
🪄 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: 9d8d9983-e3ab-4367-8273-1d99c31e6cd5

📥 Commits

Reviewing files that changed from the base of the PR and between 2218e20 and 9ebb1de.

📒 Files selected for processing (4)
  • src/features/parameters/common/contingency-table/contingency-table.tsx
  • src/features/parameters/common/contingency-table/types.ts
  • src/translations/en/parameters.ts
  • src/translations/fr/parameters.ts

Comment thread src/features/parameters/common/contingency-table/contingency-table.tsx Outdated
Comment thread src/translations/fr/parameters.ts Outdated
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>

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

Review — contingency count error details

Scope: branch review against main (4 files, +130/−21).
Goal: surface which contingency in which list is invalid, instead of just a count + "N not found".

The discriminated-union refactor (SuccessCountType | FailureCountType) is a clear improvement over the old loose optional-field shape, and the GridGrid2 switch is aligned with the ongoing migration. Translations are in sync across EN/FR with matching ICU placeholders, and the removed key is no longer referenced. 👍

Main concern is one likely-blocking type/runtime mismatch (the Set vs .length cast), plus a fragile helper round-trip and a couple of minor cleanups — all inline below.

Validation: not run. Suggest type-check + lint; removing the as unknown as string[] cast should let tsc surface the Set/.length mismatch directly.

Generated with the commons-ui code-review skill.


if (
contingencyEquipments !== undefined &&
(contingencyEquipments as unknown as string[]).length > 0

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.

[blocker] Set<string> typed but read as an array. notFoundElements is declared Record<string, Set<string>> (types.ts), but here the deciding condition uses (contingencyEquipments as unknown as string[]).length. A Set has no .length — only .size — and this data comes from fetchContingencyCount resolving backend JSON, which cannot carry a real Set.

So either:

  • the runtime value is actually an array → change the type to Record<string, string[]> and drop the cast; or
  • it really is a Set.length is always undefined, undefined > 0 is always false, and no invalid contingency is ever detected (the feature silently no-ops).

The as unknown as string[] double cast is what hides this. Please align the declared type with the real payload and remove the cast so the compiler validates the check.

for (let i = 0; i < Object.entries(contingencyCount.countByContingencyList).length; i++) {
const [contingencyListUuid] = Object.entries(contingencyCount.countByContingencyList)[i];
const listName = namesById[contingencyListUuid as UUID];
if (listName !== undefined) {

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.

[major] Silent undercount when a list name is unresolved. When listName === undefined, the entry is dropped from enriched, so contingencies from any list whose name can't be resolved are later excluded from total in analyzeContingencies — the displayed count can be wrong. Please keep unresolved lists in the total (e.g. fall back to the UUID) or justify dropping them.

) {
return {
success: false,
contingencyListName: contingencyListName.includes('_')

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.

[major] Fragile string-key round-trip. enrichContingencyCount encodes the name into the map key as `${contingencyListUuid}_${listName}`, and here it's parsed back out with slice(indexOf('_') + 1). Encoding structured data into a string key only to split it apart again is fragile. Prefer carrying a structured value (e.g. { listName, count }) so no decode step is needed.

});
});
const enriched: Record<string, ContingencyCountByContingencyList> = {};
for (let i = 0; i < Object.entries(contingencyCount.countByContingencyList).length; i++) {

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.

[minor] Object.entries() recomputed and re-indexed each iteration. for (let i = 0; i < Object.entries(x).length; i++) then indexing Object.entries(x)[i] rebuilds the entries array on every iteration — O(n²) allocations for plain iteration. Same pattern at L121 and L128. Use for (const [k, v] of Object.entries(x)) (or .forEach); faster and clearer.

const styles = {
alert: { color: 'text.primary', paddingTop: 0, paddingBottom: 0 },
alert: { color: 'text.primary', paddingTop: 0, paddingBottom: 0, width: '100%' },
error: { color: 'red', paddingTop: 0, paddingBottom: 0, width: '100%' },

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.

[minor] Hardcoded color: 'red' instead of a theme token. The sibling alert style uses color: 'text.primary', and <Alert severity="error"> already provides error coloring, so this override is likely redundant. If a color is needed, use a theme token (error.main). Also re-check width: '100%' on both alert and error — it may now be redundant with the width: '100%' parent Grid.


return (
<Grid container direction="column">
<Grid container sx={{ width: '100%' }}>

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.

The GridGrid2 switch is fine and aligned with the ongoing migration. Just confirming: the root went from <Grid container direction="column"> to <Grid container sx={{ width: '100%' }}> — please verify dropping direction="column" is intentional and the rows still stack as before (it reads like a deliberate layout change rather than a migration requirement).

FranckLecuyer and others added 7 commits June 30, 2026 10:16
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
Signed-off-by: Franck LECUYER <franck.lecuyer@rte-france.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 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.

2 participants