Skip to content

Commit c88571d

Browse files
fix(spreadsheet): reset equipments on update failure (#3312)
* fix(spreadsheet): reset equipments on update failure Signed-off-by: Joris Mancini <[email protected]> * fix(spreadsheet): filter count raises error if empty Signed-off-by: Joris Mancini <[email protected]> --------- Signed-off-by: Joris Mancini <[email protected]> Co-authored-by: Achour berrahma <[email protected]>
1 parent d587712 commit c88571d

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/components/spreadsheet-view/hooks/use-update-equipments-on-notification.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ export function useUpdateEquipmentsOnNotification(nodeAliases: NodeAlias[] | und
5858
}
5959

6060
if (impactedSubstationsIds.length > 0 && studyUuid && currentRootNetworkUuid) {
61-
fetchAllEquipments(studyUuid, nodeUuid, currentRootNetworkUuid, impactedSubstationsIds).then(
62-
(values) => {
61+
fetchAllEquipments(studyUuid, nodeUuid, currentRootNetworkUuid, impactedSubstationsIds)
62+
.then((values) => {
6363
dispatch(updateEquipments(values, nodeUuid));
64-
}
65-
);
64+
})
65+
.catch((error: unknown) => {
66+
console.warn(
67+
`Failed to update spreadsheet equipments on notification, it will be reset`,
68+
error
69+
);
70+
dispatch(resetEquipments());
71+
});
6672
}
6773

6874
if (deletedEquipments.length > 0) {
@@ -105,17 +111,22 @@ export function useUpdateEquipmentsOnNotification(nodeAliases: NodeAlias[] | und
105111
currentRootNetworkUuid === eventRootNetworkUuid &&
106112
builtNodesIds.has(eventNodeUuid)
107113
) {
108-
const networkImpacts = JSON.parse(eventData.payload) as NetworkImpactsInfos;
109-
updateEquipmentsLocal(
110-
eventNodeUuid,
111-
networkImpacts.impactedSubstationsIds,
112-
networkImpacts.deletedEquipments,
113-
networkImpacts.impactedElementTypes ?? []
114-
);
114+
try {
115+
const networkImpacts = JSON.parse(eventData.payload) as NetworkImpactsInfos;
116+
updateEquipmentsLocal(
117+
eventNodeUuid,
118+
networkImpacts.impactedSubstationsIds,
119+
networkImpacts.deletedEquipments,
120+
networkImpacts.impactedElementTypes ?? []
121+
);
122+
} catch (error: unknown) {
123+
console.warn(`Something failed during spreadsheet update, it will be reset`, error);
124+
dispatch(resetEquipments());
125+
}
115126
}
116127
}
117128
},
118-
[builtNodesIds, currentRootNetworkUuid, studyUuid, updateEquipmentsLocal]
129+
[builtNodesIds, currentRootNetworkUuid, dispatch, studyUuid, updateEquipmentsLocal]
119130
);
120131

121132
useNotificationsListener(NotificationsUrlKeys.STUDY, {

src/components/spreadsheet-view/spreadsheet/spreadsheet-toolbar/row-counter/use-filtered-row-counter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function useFilteredRowCounterInfo({
6060
}
6161
const api = gridRef.current.api;
6262
setDisplayedRows(api.getDisplayedRowCount());
63-
setTotalRows(Object.values(equipments.equipmentsByNodeId[currentNode.id]).length ?? 0);
63+
setTotalRows(Object.values(equipments.equipmentsByNodeId[currentNode.id] ?? {}).length ?? 0);
6464
setIsLoading(false);
6565
}, 600),
6666
[gridRef, currentNode, disabled, equipments.equipmentsByNodeId]

0 commit comments

Comments
 (0)