Skip to content

Commit

Permalink
[Uptime] Supress fetch errors on no data screen (#113458)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
shahzad31 and kibanamachine authored Oct 4, 2021
1 parent 2b401d0 commit fed0dc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions x-pack/plugins/uptime/public/apps/uptime_page_template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ 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} />
<StyledPageTemplateComponent
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,6 +29,7 @@ export const useHasData = () => {
}, [dispatch]);

return {
data,
error,
loading,
settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(() => {
Expand All @@ -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} />;
};
Expand Down

0 comments on commit fed0dc6

Please sign in to comment.