Skip to content

Commit 304b4ec

Browse files
committed
Fix logs extra fetches when switching nodes
Signed-off-by: Ayoub LABIDI <[email protected]>
1 parent d9845f1 commit 304b4ec

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

src/components/report-viewer-tab.jsx

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { ReportType } from 'utils/report/report.type';
2020
import { sortSeverityList } from 'utils/report/report-severity';
2121
import FormControlLabel from '@mui/material/FormControlLabel';
2222
import { Box, Switch } from '@mui/material';
23-
import { NotificationsUrlKeys, useNotificationsListener } from '@gridsuite/commons-ui';
24-
import { isStudyNotification } from '../types/notification-types';
2523

2624
const styles = {
2725
div: {
@@ -48,7 +46,6 @@ export const ReportViewerTab = ({ visible, currentNode, disabled }) => {
4846
const [nodeOnlyReport, setNodeOnlyReport] = useState(true);
4947
const [resetFilters, setResetFilters] = useState(false);
5048
const treeModel = useSelector((state) => state.networkModificationTreeModel);
51-
const currentRootNetworkUuid = useSelector((state) => state.currentRootNetworkUuid);
5249
const intl = useIntl();
5350
const [isReportLoading, fetchReport, fetchReportSeverities] = useReportFetcher(
5451
COMPUTING_AND_NETWORK_MODIFICATION_TYPE.NETWORK_MODIFICATION
@@ -70,48 +67,24 @@ export const ReportViewerTab = ({ visible, currentNode, disabled }) => {
7067
return rootNode?.id;
7168
}, [treeModel]);
7269

73-
const fetchReportAndSeverities = useCallback(() => {
74-
fetchReport(nodeOnlyReport).then((r) => {
75-
if (r !== undefined) {
76-
setReport(r);
77-
fetchReportSeverities(r.id, r.parentId ? ReportType.NODE : ReportType.GLOBAL).then((severities) => {
78-
setSeverities(sortSeverityList(severities));
79-
});
80-
}
81-
});
82-
}, [fetchReport, nodeOnlyReport, fetchReportSeverities]);
83-
84-
// Listen for STUDY notifications
85-
const handleNotification = useCallback(
86-
(event) => {
87-
const eventData = JSON.parse(event.data);
88-
if (
89-
visible &&
90-
!disabled &&
91-
isStudyNotification(eventData) &&
92-
eventData.headers.rootNetworkUuid === currentRootNetworkUuid &&
93-
eventData.headers.node === currentNode?.id
94-
) {
95-
fetchReportAndSeverities();
96-
}
97-
},
98-
[visible, disabled, currentRootNetworkUuid, currentNode?.id, fetchReportAndSeverities]
99-
);
100-
101-
useNotificationsListener(NotificationsUrlKeys.STUDY, { listenerCallbackMessage: handleNotification });
102-
103-
// This useEffect is responsible for updating the reports when the user opens the LOGS panel
10470
useEffect(() => {
105-
// Visible and !disabled ensure that the user has the LOGS tab open and the current node is built.
71+
// Visible and !disabled ensure that the current node is built.
10672
if (visible && !disabled) {
107-
fetchReportAndSeverities();
73+
fetchReport(nodeOnlyReport).then((r) => {
74+
if (r !== undefined) {
75+
setReport(r);
76+
fetchReportSeverities(r.id, r.parentId ? ReportType.NODE : ReportType.GLOBAL).then((severities) => {
77+
setSeverities(sortSeverityList(severities));
78+
});
79+
}
80+
});
10881
} else {
10982
// if the user unbuilds a node, the report needs to be reset.
11083
// otherwise, the report will be kept in the state and useless report fetches with previous id will be made when the user rebuilds the node.
11184
setReport();
11285
setSeverities();
11386
}
114-
}, [visible, currentNode?.id, disabled, nodeOnlyReport, fetchReportAndSeverities]);
87+
}, [visible, currentNode, disabled, fetchReport, nodeOnlyReport, fetchReportSeverities]);
11588

11689
return (
11790
<>

0 commit comments

Comments
 (0)