Skip to content

Move Voltage Level Modification functionality and related components into commons-ui#1060

Open
achour94 wants to merge 4 commits intomainfrom
achour/move-vl-modification-into-commons-ui
Open

Move Voltage Level Modification functionality and related components into commons-ui#1060
achour94 wants to merge 4 commits intomainfrom
achour/move-vl-modification-into-commons-ui

Conversation

@achour94
Copy link
Contributor

PR Summary

…into commons-ui

Signed-off-by: achour94 <berrahmaachour@gmail.com>
@achour94 achour94 self-assigned this Mar 19, 2026
…cation-into-commons-ui

# Conflicts:
#	src/components/network-modifications/voltage-level/index.ts
@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Adds voltage-level modification support: a React modification form, TypeScript DTOs/types, Yup validation and form↔DTO mapping utilities, new barrel exports, a field constant, and English/French translation keys. No other runtime control flow changes.

Changes

Cohort / File(s) Summary
Modification Form
src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx
New React form component for editing voltage level attributes (equipment ID read-only, name, substation, nominal/limit voltages, short-circuit limits, properties) using react-hook-form and existing shared inputs.
Modification Types
src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts
New DTO and type interfaces: IdentifiableShortCircuitDto, VoltageLevelDto, and VoltageLevelModificationDto describing payloads and structure for voltage level modifications.
Validation & Mapping Utilities
src/components/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts
Added Yup form schema (with conditional max rules), empty form data, and two converters: form→DTO (voltageLevelModificationFormToDto) and DTO→form (voltageLevelModificationDtoToForm).
Modification Barrel Exports
src/components/network-modifications/voltage-level/modification/index.ts
New barrel file re-exporting form, types, and utils from the modification directory.
Voltage-level Barrel Export Update
src/components/network-modifications/voltage-level/index.ts
Extended public exports to include the new ./modification barrel.
Translations (i18n)
src/translations/en/networkModificationsEn.ts, src/translations/fr/networkModificationsFr.ts
Added ModifyVoltageLevel and VoltageLevelModificationError translation keys for English and French locales.
Field Constants
src/utils/constants/fieldConstants.ts
Added HIDE_SUBSTATION_FIELD = 'hideSubstationField' to FieldConstants enum.

Sequence Diagram(s)

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is empty, providing no information about the changes. Provide a detailed description of the changes, including what was moved, why it was moved, and any breaking changes or migration notes.
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.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: moving voltage level modification functionality into the commons-ui repository.

✏️ 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.

🧹 Nitpick comments (3)
src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx (2)

57-65: Outdated comment about MUI bug.

The comment references a MUI bug that "should be fixed after v5.12.2", but the project uses @mui/material v5.16.14. The MUI bug is no longer relevant—the remaining limitation is purely backend-related (Powsybl). Consider simplifying the comment to focus on the actual blocking issue.

✏️ Simplified comment
     const substationField = (
         <AutocompleteInput
             allowNewValue
             forcePopupIcon
             name={FieldConstants.SUBSTATION_ID}
             label="SUBSTATION"
-            // Because of a mui/material bug, the disabled attribute does not work properly.
-            // It should be fixed after v5.12.2. For the moment, instead of fetching the
-            // substation list to display in this AutocompleteInput, we only show the current substation.
+            // Only showing current substation since changing substations is not yet supported by the backend (Powsybl).
             options={[voltageLevelToModify?.substationId ?? '']}
             inputTransform={(value) => (value === null ? '' : value)}
             outputTransform={(value) => value}
             size="small"
             formProps={filledTextField}
-            disabled // TODO: to be removed when it is possible to change the substation of a voltage level in the backend (Powsybl)
+            disabled // TODO: Enable when Powsybl supports changing substation of a voltage level
         />
     );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx`
around lines 57 - 65, Update the outdated comment in
VoltageLevelModificationForm.tsx (around the AutocompleteInput options/disabled
props) to remove the MUI bug reference and version number; instead state
concisely that the field is disabled due to a backend limitation in Powsybl and
keep the TODO about removing the disabled flag once the backend supports
changing a voltage level's substation.

27-39: Redundant readOnly with disabled.

Setting both InputProps={{ readOnly: true }} and disabled is redundant since disabled already prevents user input. You can simplify by removing the InputProps prop.

✨ Simplified TextField
     const voltageLevelIdField = (
         <TextField
             size="small"
             fullWidth
             label="ID"
             value={equipmentId ?? ''}
-            InputProps={{
-                readOnly: true,
-            }}
             disabled
             {...filledTextField}
         />
     );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx`
around lines 27 - 39, The TextField instance assigned to voltageLevelIdField
currently sets both InputProps={{ readOnly: true }} and disabled, which is
redundant; remove the InputProps prop (or the readOnly flag) and keep disabled
so the field remains non-editable, i.e. update the TextField used in
voltageLevelIdField to drop InputProps while preserving disabled, label, value
(equipmentId ?? ''), and {...filledTextField}.
src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts (1)

34-46: Consider making type required with a literal type for stronger type safety.

The type field is defined as optional and generic (type?: ModificationType), but the DTO contract (per the context snippet) expects it to be type: ModificationType.VOLTAGE_LEVEL_MODIFICATION. Since voltageLevelModificationFormToDto always sets this value explicitly, the code works at runtime, but the type definition is more permissive than intended.

💡 Suggested type refinement
 export interface VoltageLevelModificationDto {
     uuid?: UUID;
     equipmentId: string;
     equipmentName?: AttributeModification<string> | null;
     substationId?: AttributeModification<string> | null;
     nominalV?: AttributeModification<number> | null;
     lowVoltageLimit?: AttributeModification<number> | null;
     highVoltageLimit?: AttributeModification<number> | null;
     ipMin?: AttributeModification<number> | null;
     ipMax?: AttributeModification<number> | null;
     properties?: Property[] | null;
-    type?: ModificationType;
+    type: ModificationType.VOLTAGE_LEVEL_MODIFICATION;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts`
around lines 34 - 46, The VoltageLevelModificationDto currently has an optional,
generic type field; change it so the field is required and narrowed to the
literal value used by the DTO: replace "type?: ModificationType" with "type:
ModificationType.VOLTAGE_LEVEL_MODIFICATION" in the VoltageLevelModificationDto
declaration, and update any call sites or converters (e.g.,
voltageLevelModificationFormToDto) if they rely on the field being optional to
ensure they still set that required literal value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts`:
- Around line 34-46: The VoltageLevelModificationDto currently has an optional,
generic type field; change it so the field is required and narrowed to the
literal value used by the DTO: replace "type?: ModificationType" with "type:
ModificationType.VOLTAGE_LEVEL_MODIFICATION" in the VoltageLevelModificationDto
declaration, and update any call sites or converters (e.g.,
voltageLevelModificationFormToDto) if they rely on the field being optional to
ensure they still set that required literal value.

In
`@src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx`:
- Around line 57-65: Update the outdated comment in
VoltageLevelModificationForm.tsx (around the AutocompleteInput options/disabled
props) to remove the MUI bug reference and version number; instead state
concisely that the field is disabled due to a backend limitation in Powsybl and
keep the TODO about removing the disabled flag once the backend supports
changing a voltage level's substation.
- Around line 27-39: The TextField instance assigned to voltageLevelIdField
currently sets both InputProps={{ readOnly: true }} and disabled, which is
redundant; remove the InputProps prop (or the readOnly flag) and keep disabled
so the field remains non-editable, i.e. update the TextField used in
voltageLevelIdField to drop InputProps while preserving disabled, label, value
(equipmentId ?? ''), and {...filledTextField}.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ffdce5c-0e57-45eb-a69b-c6e9efce4f4e

📥 Commits

Reviewing files that changed from the base of the PR and between 3b5f4c3 and bc04226.

📒 Files selected for processing (7)
  • src/components/network-modifications/voltage-level/index.ts
  • src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx
  • src/components/network-modifications/voltage-level/modification/index.ts
  • src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts
  • src/components/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts
  • src/translations/en/networkModificationsEn.ts
  • src/translations/fr/networkModificationsFr.ts

@KoloMenek
Copy link
Member

KoloMenek commented Mar 23, 2026

Tested with gridstudy locally and it worked. (Can you please fix the sonarcloud reliability rating so it can be merged? --- Apparently it's common during refactors and it is ignored)

@KoloMenek KoloMenek self-requested a review March 23, 2026 12:51
@KoloMenek
Copy link
Member

There is one issue with gridexplore where in the form, the field that contains the value of SubstationId is empty. A fix needs to be implemented either in gridExplore or commons-ui

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

🤖 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/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts`:
- Around line 60-70: The form defaults object
voltageLevelModificationEmptyFormData is missing substationId which causes the
FieldConstants.SUBSTATION_ID bound control to start empty; add substationId: ''
(or appropriate null/empty type) to voltageLevelModificationEmptyFormData and
update the DTO→form mapping function (the voltage level DTO to form converter
used around lines ~93-104) to copy dto.substationId into the form data so the
substation field is hydrated when a DTO value exists.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79490040-ed72-46ee-8375-20d62311cdef

📥 Commits

Reviewing files that changed from the base of the PR and between bc04226 and 2186e30.

📒 Files selected for processing (4)
  • src/components/network-modifications/voltage-level/modification/VoltageLevelModificationForm.tsx
  • src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts
  • src/components/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts
  • src/utils/constants/fieldConstants.ts
✅ Files skipped from review due to trivial changes (2)
  • src/utils/constants/fieldConstants.ts
  • src/components/network-modifications/voltage-level/modification/voltageLevelModification.types.ts

Comment on lines +60 to +70
export const voltageLevelModificationEmptyFormData: VoltageLevelModificationFormData = {
equipmentID: '',
equipmentName: '',
hideSubstationField: false,
nominalV: null,
lowVoltageLimit: null,
highVoltageLimit: null,
lowShortCircuitCurrentLimit: null,
highShortCircuitCurrentLimit: null,
AdditionalProperties: [],
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Hydrate and initialize substationId in form data to prevent empty Substation field.

Line 60 and Line 93 omit substationId from defaults/DTO→form mapping, so the form control bound to FieldConstants.SUBSTATION_ID starts empty even when DTO carries a value.

💡 Proposed fix
 export const voltageLevelModificationEmptyFormData: VoltageLevelModificationFormData = {
     equipmentID: '',
     equipmentName: '',
     hideSubstationField: false,
+    substationId: '',
     nominalV: null,
     lowVoltageLimit: null,
     highVoltageLimit: null,
     lowShortCircuitCurrentLimit: null,
     highShortCircuitCurrentLimit: null,
     AdditionalProperties: [],
 };
@@
 export const voltageLevelModificationDtoToForm = (
     voltageLevelDto: VoltageLevelModificationDto,
     includePreviousValues = true
 ): VoltageLevelModificationFormData => ({
     equipmentID: voltageLevelDto.equipmentId,
     equipmentName: voltageLevelDto.equipmentName?.value ?? '',
     hideSubstationField: false,
+    substationId: voltageLevelDto.substationId ?? '',
     nominalV: voltageLevelDto.nominalV?.value ?? null,
     lowVoltageLimit: voltageLevelDto.lowVoltageLimit?.value ?? null,
     highVoltageLimit: voltageLevelDto.highVoltageLimit?.value ?? null,
     lowShortCircuitCurrentLimit:
         convertInputValue(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevelDto.ipMin?.value) ?? null,
     highShortCircuitCurrentLimit:
         convertInputValue(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, voltageLevelDto.ipMax?.value) ?? null,
     ...getPropertiesFromModification(voltageLevelDto.properties, includePreviousValues),
 });

Also applies to: 93-104

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

In
`@src/components/network-modifications/voltage-level/modification/voltageLevelModification.utils.ts`
around lines 60 - 70, The form defaults object
voltageLevelModificationEmptyFormData is missing substationId which causes the
FieldConstants.SUBSTATION_ID bound control to start empty; add substationId: ''
(or appropriate null/empty type) to voltageLevelModificationEmptyFormData and
update the DTO→form mapping function (the voltage level DTO to form converter
used around lines ~93-104) to copy dto.substationId into the form data so the
substation field is hydrated when a DTO value exists.

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