@@ -1567,9 +1567,7 @@ export const reducer = createReducer(initialState, (builder) => {
1567
1567
1568
1568
builder . addCase ( DELETE_EQUIPMENTS , ( state , action : DeleteEquipmentsAction ) => {
1569
1569
action . equipments . forEach ( ( { equipmentType : equipmentToDeleteType , equipmentId : equipmentToDeleteId } ) => {
1570
- const currentEquipments =
1571
- state . spreadsheetNetwork [ equipmentToDeleteType ] ?. equipmentsByNodeId [ action . nodeId ] ;
1572
- if ( currentEquipments !== undefined ) {
1570
+ if ( state . spreadsheetNetwork [ equipmentToDeleteType ] ?. equipmentsByNodeId [ action . nodeId ] ) {
1573
1571
// in case of voltage level deletion, we need to update the linked substation which contains a list of its voltage levels
1574
1572
if ( equipmentToDeleteType === SpreadsheetEquipmentType . VOLTAGE_LEVEL ) {
1575
1573
const currentSubstations = state . spreadsheetNetwork [ SpreadsheetEquipmentType . SUBSTATION ]
@@ -1579,12 +1577,19 @@ export const reducer = createReducer(initialState, (builder) => {
1579
1577
action . nodeId
1580
1578
] = updateSubstationAfterVLDeletion ( currentSubstations , equipmentToDeleteId ) ;
1581
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
+ ] ;
1582
1589
}
1583
-
1584
- state . spreadsheetNetwork [ equipmentToDeleteType ] . equipmentsByNodeId [ action . nodeId ] = deleteEquipment (
1585
- currentEquipments ,
1590
+ delete state . spreadsheetNetwork [ equipmentToDeleteType ] . equipmentsByNodeId [ action . nodeId ] [
1586
1591
equipmentToDeleteId
1587
- ) ;
1592
+ ] ;
1588
1593
}
1589
1594
} ) ;
1590
1595
} ) ;
@@ -1950,11 +1955,6 @@ function updateSubstationAfterVLDeletion(
1950
1955
return currentSubstations ;
1951
1956
}
1952
1957
1953
- function deleteEquipment ( currentEquipments : Record < string , Identifiable > , equipmentToDeleteId : string ) {
1954
- delete currentEquipments [ equipmentToDeleteId ] ;
1955
- return currentEquipments ;
1956
- }
1957
-
1958
1958
export type Substation = Identifiable & {
1959
1959
voltageLevels : Identifiable [ ] ;
1960
1960
} ;
0 commit comments