Skip to content

Commit 4da9306

Browse files
fix: delete data in branch type if it's line or twt
Signed-off-by: Joris Mancini <[email protected]>
1 parent b41d75f commit 4da9306

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/redux/reducer.ts

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

15681568
builder.addCase(DELETE_EQUIPMENTS, (state, action: DeleteEquipmentsAction) => {
15691569
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]) {
15731571
// in case of voltage level deletion, we need to update the linked substation which contains a list of its voltage levels
15741572
if (equipmentToDeleteType === SpreadsheetEquipmentType.VOLTAGE_LEVEL) {
15751573
const currentSubstations = state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION]
@@ -1579,12 +1577,19 @@ export const reducer = createReducer(initialState, (builder) => {
15791577
action.nodeId
15801578
] = updateSubstationAfterVLDeletion(currentSubstations, equipmentToDeleteId);
15811579
}
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+
];
15821589
}
1583-
1584-
state.spreadsheetNetwork[equipmentToDeleteType].equipmentsByNodeId[action.nodeId] = deleteEquipment(
1585-
currentEquipments,
1590+
delete state.spreadsheetNetwork[equipmentToDeleteType].equipmentsByNodeId[action.nodeId][
15861591
equipmentToDeleteId
1587-
);
1592+
];
15881593
}
15891594
});
15901595
});
@@ -1950,11 +1955,6 @@ function updateSubstationAfterVLDeletion(
19501955
return currentSubstations;
19511956
}
19521957

1953-
function deleteEquipment(currentEquipments: Record<string, Identifiable>, equipmentToDeleteId: string) {
1954-
delete currentEquipments[equipmentToDeleteId];
1955-
return currentEquipments;
1956-
}
1957-
19581958
export type Substation = Identifiable & {
19591959
voltageLevels: Identifiable[];
19601960
};

0 commit comments

Comments
 (0)