Skip to content

Commit

Permalink
[ML] Fix useEffects.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Aug 26, 2021
1 parent 34e882c commit cd871b2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,9 @@ export function FailedTransactionsCorrelations({
end,
]);

// start fetching on load and on changing environment
useEffect(() => {
if (isRunning) {
cancelFetch();
}

startFetchHandler();

return () => {
// cancel any running async partial request when unmounting the component
cancelFetch();
};
// `isRunning` must not be part of the deps check
// eslint-disable-next-line react-hooks/exhaustive-deps
return cancelFetch;
}, [cancelFetch, startFetchHandler]);

const [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,9 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) {
end,
]);

// start fetching on load and on changing environment
useEffect(() => {
if (isRunning) {
cancelFetch();
}

startFetchHandler();

return () => {
// cancel any running async partial request when unmounting the component
cancelFetch();
};
// `isRunning` must not be part of the deps check
// eslint-disable-next-line react-hooks/exhaustive-deps
return cancelFetch;
}, [cancelFetch, startFetchHandler]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export function TransactionDistribution({
const {
error,
percentileThresholdValue,
isRunning,
startFetch,
cancelFetch,
transactionDistribution,
Expand Down Expand Up @@ -136,20 +135,9 @@ export function TransactionDistribution({
end,
]);

// start fetching on load and on changing environment
useEffect(() => {
if (isRunning) {
cancelFetch();
}

startFetchHandler();

return () => {
// cancel any running async partial request when unmounting the component
cancelFetch();
};
// `isRunning` must not be part of the deps check
// eslint-disable-next-line react-hooks/exhaustive-deps
return cancelFetch;
}, [cancelFetch, startFetchHandler]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function TransactionDistributionChart({
);

useEffect(() => {
if (typeof onHasData === 'function') {
if (onHasData) {
onHasData(chartLoadingState.hasData);
}
}, [chartLoadingState, onHasData]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ export const useFailedTransactionsCorrelationsFetcher = () => {
setFetchState((prevState) => ({
...prevState,
error: (res as unknown) as Error,
setIsRunning: false,
isRunning: false,
}));
}
},
error: (error: Error) => {
setFetchState((prevState) => ({
...prevState,
error,
setIsRunning: false,
isRunning: false,
}));
},
});
},
[data.search]
[data.search, setFetchState]
);

const cancelFetch = useCallback(() => {
Expand All @@ -128,9 +128,9 @@ export const useFailedTransactionsCorrelationsFetcher = () => {
abortCtrl.current.abort();
setFetchState((prevState) => ({
...prevState,
setIsRunning: false,
isRunning: false,
}));
}, []);
}, [setFetchState]);

return {
...fetchState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ export function useTransactionDistributionFetcher() {
setFetchState((prevState) => ({
...prevState,
error: (res as unknown) as Error,
setIsRunning: false,
isRunning: false,
}));
}
},
error: (error: Error) => {
setFetchState((prevState) => ({
...prevState,
error,
setIsRunning: false,
isRunning: false,
}));
},
});
},
[data.search]
[data.search, setFetchState]
);

const cancelFetch = useCallback(() => {
Expand All @@ -147,9 +147,9 @@ export function useTransactionDistributionFetcher() {
abortCtrl.current.abort();
setFetchState((prevState) => ({
...prevState,
setIsRunning: false,
isRunning: false,
}));
}, []);
}, [setFetchState]);

return {
...fetchState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ export const useTransactionLatencyCorrelationsFetcher = () => {
setFetchState((prevState) => ({
...prevState,
error: (res as unknown) as Error,
setIsRunning: false,
isRunning: false,
}));
}
},
error: (error: Error) => {
setFetchState((prevState) => ({
...prevState,
error,
setIsRunning: false,
isRunning: false,
}));
},
});
},
[data.search]
[data.search, setFetchState]
);

const cancelFetch = useCallback(() => {
Expand All @@ -149,9 +149,9 @@ export const useTransactionLatencyCorrelationsFetcher = () => {
abortCtrl.current.abort();
setFetchState((prevState) => ({
...prevState,
setIsRunning: false,
isRunning: false,
}));
}, []);
}, [setFetchState]);

return {
...fetchState,
Expand Down

0 comments on commit cd871b2

Please sign in to comment.