fix: improve edge state management using object structure (#6764)

* 🔧 (UpdateAllComponents/index.tsx): refactor the logic to track the number of edges before update and update component status for better error handling and user notification.

* ♻️ (UpdateAllComponents/index.tsx): refactor variable names for better readability and semantics
This commit is contained in:
Cristhian Zanforlin Lousa 2025-02-24 14:09:59 -03:00 committed by GitHub
commit 87886fbbac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,16 +36,25 @@ export default function UpdateAllComponents({}: {}) {
const [loadingUpdate, setLoadingUpdate] = useState(false);
const [dismissed, setDismissed] = useState(false);
const numberOfEdgesBeforeUpdate = useRef(0);
const edgesUpdateRef = useRef({
numberOfEdgesBeforeUpdate: 0,
updateComponent: false,
});
useMemo(() => {
if (
numberOfEdgesBeforeUpdate.current > 0 &&
edges.length !== numberOfEdgesBeforeUpdate.current
edgesUpdateRef.current.numberOfEdgesBeforeUpdate > 0 &&
edges.length !== edgesUpdateRef.current.numberOfEdgesBeforeUpdate &&
edgesUpdateRef.current.updateComponent
) {
useAlertStore.getState().setNoticeData({
title: ERROR_MESSAGE_EDGES_LOST,
});
edgesUpdateRef.current = {
numberOfEdgesBeforeUpdate: 0,
updateComponent: false,
};
}
}, [edges]);
@ -56,7 +65,11 @@ export default function UpdateAllComponents({}: {}) {
};
const handleUpdateAllComponents = () => {
numberOfEdgesBeforeUpdate.current = edges.length;
edgesUpdateRef.current = {
numberOfEdgesBeforeUpdate: edges.length,
updateComponent: true,
};
setLoadingUpdate(true);
takeSnapshot();