[Uptime] Supress fetch errors on no data screen (#113458) (#113797)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Shahzad <shahzad.muhammad@elastic.co>
This commit is contained in:
Kibana Machine 2021-10-04 14:36:22 -04:00 committed by GitHub
parent 64cedf1eee
commit c7ae6fe96c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View file

@ -38,12 +38,14 @@ export const UptimePageTemplateComponent: React.FC<Props> = ({ path, pageHeader,
const noDataConfig = useNoDataConfig();
const { loading, error } = useHasData();
const { loading, error, data } = useHasData();
if (error) {
return <EmptyStateError errors={[error]} />;
}
const showLoading = loading && path === OVERVIEW_ROUTE && !data;
return (
<>
<div data-test-subj={noDataConfig ? 'data-missing' : undefined} />
@ -51,9 +53,9 @@ export const UptimePageTemplateComponent: React.FC<Props> = ({ path, pageHeader,
pageHeader={pageHeader}
noDataConfig={path === OVERVIEW_ROUTE && !loading ? noDataConfig : undefined}
>
{loading && path === OVERVIEW_ROUTE && <EmptyStateLoading />}
{showLoading && <EmptyStateLoading />}
<div
style={{ visibility: loading && path === OVERVIEW_ROUTE ? 'hidden' : 'initial' }}
style={{ visibility: showLoading ? 'hidden' : 'initial' }}
data-test-subj={noDataConfig ? 'data-missing' : undefined}
>
{children}

View file

@ -13,7 +13,7 @@ import { UptimeRefreshContext } from '../../../contexts';
import { getDynamicSettings } from '../../../state/actions/dynamic_settings';
export const useHasData = () => {
const { loading, error } = useSelector(indexStatusSelector);
const { loading, error, data } = useSelector(indexStatusSelector);
const { lastRefresh } = useContext(UptimeRefreshContext);
const { settings } = useSelector(selectDynamicSettings);
@ -29,6 +29,7 @@ export const useHasData = () => {
}, [dispatch]);
return {
data,
error,
loading,
settings,

View file

@ -9,7 +9,7 @@ import React, { createContext, useContext, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useFetcher } from '../../../observability/public';
import { DataPublicPluginStart, IndexPattern } from '../../../../../src/plugins/data/public';
import { selectDynamicSettings } from '../state/selectors';
import { indexStatusSelector, selectDynamicSettings } from '../state/selectors';
import { getDynamicSettings } from '../state/actions/dynamic_settings';
export const UptimeIndexPatternContext = createContext({} as IndexPattern);
@ -19,6 +19,8 @@ export const UptimeIndexPatternContextProvider: React.FC<{ data: DataPublicPlugi
data: { indexPatterns },
}) => {
const { settings } = useSelector(selectDynamicSettings);
const { data: indexStatus } = useSelector(indexStatusSelector);
const dispatch = useDispatch();
useEffect(() => {
@ -30,11 +32,11 @@ export const UptimeIndexPatternContextProvider: React.FC<{ data: DataPublicPlugi
const heartbeatIndices = settings?.heartbeatIndices || '';
const { data } = useFetcher<Promise<IndexPattern | undefined>>(async () => {
if (heartbeatIndices) {
if (heartbeatIndices && indexStatus?.indexExists) {
// this only creates an index pattern in memory, not as saved object
return indexPatterns.create({ title: heartbeatIndices });
}
}, [heartbeatIndices]);
}, [heartbeatIndices, indexStatus?.indexExists]);
return <UptimeIndexPatternContext.Provider value={data!} children={children} />;
};