Skip to content

Commit 89edb2e

Browse files
fix: delete equipment reducer for branch
Co-authored-by: Achour berrahma <[email protected]>
1 parent 7593695 commit 89edb2e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/redux/reducer.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,31 @@ 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 (
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+
}
15701580
if (state.spreadsheetNetwork[equipmentToDeleteType]?.equipmentsByNodeId[action.nodeId]) {
1581+
// in case of voltage level deletion, we need to update the linked substation which contains a list of its voltage levels
1582+
if (equipmentToDeleteType === SpreadsheetEquipmentType.VOLTAGE_LEVEL) {
1583+
const currentSubstations = state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION]
1584+
.equipmentsByNodeId[action.nodeId] as Record<string, Substation> | null;
1585+
if (currentSubstations != null) {
1586+
state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION].equipmentsByNodeId[
1587+
action.nodeId
1588+
] = updateSubstationAfterVLDeletion(currentSubstations, equipmentToDeleteId);
1589+
}
1590+
}
1591+
delete state.spreadsheetNetwork[equipmentToDeleteType].equipmentsByNodeId[action.nodeId][
1592+
equipmentToDeleteId
1593+
];
1594+
}
15711595
// in case of voltage level deletion, we need to update the linked substation which contains a list of its voltage levels
15721596
if (equipmentToDeleteType === SpreadsheetEquipmentType.VOLTAGE_LEVEL) {
15731597
const currentSubstations = state.spreadsheetNetwork[SpreadsheetEquipmentType.SUBSTATION]

0 commit comments

Comments
 (0)