Skip to content

Commit

Permalink
don't request when request is pending (elastic#115999)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
neptunian and kibanamachine committed Oct 22, 2021
1 parent 280c71d commit 09166e8
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const PageTemplate: React.FC<PageTemplateProps> = ({

const { currentTimerange } = useContext(MonitoringTimeContainer.Context);
const [loaded, setLoaded] = useState(false);
const [isRequestPending, setIsRequestPending] = useState(false);
const history = useHistory();
const [hasError, setHasError] = useState(false);
const handleRequestError = useRequestErrorHandler();
Expand All @@ -62,6 +63,7 @@ export const PageTemplate: React.FC<PageTemplateProps> = ({
);

useEffect(() => {
setIsRequestPending(true);
getPageData?.()
.then(getPageDataResponseHandler)
.catch((err: IHttpFetchError) => {
Expand All @@ -70,11 +72,20 @@ export const PageTemplate: React.FC<PageTemplateProps> = ({
})
.finally(() => {
setLoaded(true);
setIsRequestPending(false);
});
}, [getPageData, currentTimerange, getPageDataResponseHandler, handleRequestError]);

const onRefresh = () => {
getPageData?.().then(getPageDataResponseHandler).catch(handleRequestError);
// don't refresh when a request is pending
if (isRequestPending) return;
setIsRequestPending(true);
getPageData?.()
.then(getPageDataResponseHandler)
.catch(handleRequestError)
.finally(() => {
setIsRequestPending(false);
});

if (isSetupModeFeatureEnabled(SetupModeFeature.MetricbeatMigration)) {
updateSetupModeData();
Expand Down

0 comments on commit 09166e8

Please sign in to comment.