[ML] AIOps: Fixes timefilter subscriptions. (#149576)

The `useEffect` hooks that set up subscriptions related to the
`timefilter` were missing `[]` to be only called when the code is
mounted, without it they were called on every render. This PR adds the
missing `[]` and also combines the two hooks into one.
This commit is contained in:
Walter Rafelsberger 2023-01-27 12:01:22 +01:00 committed by GitHub
parent db7bc1423b
commit b87d754e9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -148,7 +148,7 @@ export const useData = (
}
useEffect(() => {
const timeUpdateSubscription = merge(
const timefilterUpdateSubscription = merge(
timefilter.getAutoRefreshFetch$(),
timefilter.getTimeUpdate$(),
mlTimefilterRefresh$
@ -161,22 +161,20 @@ export const useData = (
}
updateFieldStatsRequest();
});
return () => {
timeUpdateSubscription.unsubscribe();
};
});
// This hook listens just for an initial update of the timefilter to be switched on.
useEffect(() => {
const timeUpdateSubscription = timefilter.getEnabledUpdated$().subscribe(() => {
// This listens just for an initial update of the timefilter to be switched on.
const timefilterEnabledSubscription = timefilter.getEnabledUpdated$().subscribe(() => {
if (fieldStatsRequest === undefined) {
updateFieldStatsRequest();
}
});
return () => {
timeUpdateSubscription.unsubscribe();
timefilterUpdateSubscription.unsubscribe();
timefilterEnabledSubscription.unsubscribe();
};
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// Ensure request is updated when search changes
useEffect(() => {