Skip to content

Commit 0495a0a

Browse files
fix: delete equipment reducer for branch
Co-authored-by: Achour berrahma <[email protected]> Signed-off-by: Joris Mancini <[email protected]>
1 parent 7593695 commit 0495a0a

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/redux/reducer.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,26 +1567,24 @@ export const reducer = createReducer(initialState, (builder) => {
15671567

15681568
builder.addCase(DELETE_EQUIPMENTS, (state, action: DeleteEquipmentsAction) => {
15691569
action.equipments.forEach(({ equipmentType: equipmentToDeleteType, equipmentId: equipmentToDeleteId }) => {
1570-
if (state.spreadsheetNetwork[equipmentToDeleteType]?.equipmentsByNodeId[action.nodeId]) {
1571-
// in case of voltage level deletion, we need to update the linked substation which contains a list of its voltage levels
1572-
if (equipmentToDeleteType === SpreadsheetEquipmentType.VOLTAGE_LEVEL) {
1573-
const currentSubstations = state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION]
1574-
.equipmentsByNodeId[action.nodeId] as Record<string, Substation> | null;
1575-
if (currentSubstations != null) {
1576-
state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION].equipmentsByNodeId[
1577-
action.nodeId
1578-
] = updateSubstationAfterVLDeletion(currentSubstations, equipmentToDeleteId);
1579-
}
1580-
} else if (
1581-
// If we delete a line or a two windings transformer we also have to delete it from branch type
1582-
(equipmentToDeleteType === SpreadsheetEquipmentType.LINE ||
1583-
SpreadsheetEquipmentType.TWO_WINDINGS_TRANSFORMER) &&
1584-
state.spreadsheetNetwork[SpreadsheetEquipmentType.BRANCH].equipmentsByNodeId[action.nodeId]
1585-
) {
1586-
delete state.spreadsheetNetwork[SpreadsheetEquipmentType.BRANCH].equipmentsByNodeId[action.nodeId][
1587-
equipmentToDeleteId
1588-
];
1570+
if (
1571+
// If we delete a line or a two windings transformer we also have to delete it from branch type
1572+
(equipmentToDeleteType === SpreadsheetEquipmentType.LINE ||
1573+
equipmentToDeleteType === SpreadsheetEquipmentType.TWO_WINDINGS_TRANSFORMER) &&
1574+
state.spreadsheetNetwork[SpreadsheetEquipmentType.BRANCH]?.equipmentsByNodeId[action.nodeId]
1575+
) {
1576+
delete state.spreadsheetNetwork[SpreadsheetEquipmentType.BRANCH].equipmentsByNodeId[action.nodeId][
1577+
equipmentToDeleteId
1578+
];
1579+
} else if (equipmentToDeleteType === SpreadsheetEquipmentType.VOLTAGE_LEVEL) {
1580+
const currentSubstations = state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION]
1581+
.equipmentsByNodeId[action.nodeId] as Record<string, Substation> | null;
1582+
if (currentSubstations != null) {
1583+
state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION].equipmentsByNodeId[action.nodeId] =
1584+
updateSubstationAfterVLDeletion(currentSubstations, equipmentToDeleteId);
15891585
}
1586+
}
1587+
if (state.spreadsheetNetwork[equipmentToDeleteType]?.equipmentsByNodeId[action.nodeId]) {
15901588
delete state.spreadsheetNetwork[equipmentToDeleteType].equipmentsByNodeId[action.nodeId][
15911589
equipmentToDeleteId
15921590
];

0 commit comments

Comments
 (0)