From 72b01e2ddbe57ac00906b6ef1d46707bfbf056c2 Mon Sep 17 00:00:00 2001 From: Claudio Procida Date: Thu, 4 Nov 2021 13:06:57 +0100 Subject: [PATCH 1/4] Refines hasAnyData check for alerts --- .../observability/public/context/has_data_context.test.tsx | 2 +- .../plugins/observability/public/context/has_data_context.tsx | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/observability/public/context/has_data_context.test.tsx b/x-pack/plugins/observability/public/context/has_data_context.test.tsx index a586a8bf0bcce..1eb4108b12181 100644 --- a/x-pack/plugins/observability/public/context/has_data_context.test.tsx +++ b/x-pack/plugins/observability/public/context/has_data_context.test.tsx @@ -556,7 +556,7 @@ describe('HasDataContextProvider', () => { status: 'success', }, }, - hasAnyData: false, + hasAnyData: true, isAllRequestsComplete: true, forceUpdate: expect.any(String), onRefreshTimeRange: expect.any(Function), diff --git a/x-pack/plugins/observability/public/context/has_data_context.tsx b/x-pack/plugins/observability/public/context/has_data_context.tsx index caed130543acc..1984451499d63 100644 --- a/x-pack/plugins/observability/public/context/has_data_context.tsx +++ b/x-pack/plugins/observability/public/context/has_data_context.tsx @@ -147,7 +147,9 @@ export function HasDataContextProvider({ children }: { children: React.ReactNode }); const hasAnyData = (Object.keys(hasDataMap) as ObservabilityFetchDataPlugins[]).some( - (app) => hasDataMap[app]?.hasData === true + (app) => + hasDataMap[app]?.hasData === true || + (Array.isArray(hasDataMap[app]?.hasData) && hasDataMap[app]?.hasData.length > 0) ); return ( From 3602685a98e313a02fe18d1e439a62eaeae54b51 Mon Sep 17 00:00:00 2001 From: Claudio Procida Date: Thu, 4 Nov 2021 13:41:52 +0100 Subject: [PATCH 2/4] Fixes type refinements --- .../plugins/observability/public/context/has_data_context.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability/public/context/has_data_context.tsx b/x-pack/plugins/observability/public/context/has_data_context.tsx index 1984451499d63..a931352b6dc0a 100644 --- a/x-pack/plugins/observability/public/context/has_data_context.tsx +++ b/x-pack/plugins/observability/public/context/has_data_context.tsx @@ -149,7 +149,7 @@ export function HasDataContextProvider({ children }: { children: React.ReactNode const hasAnyData = (Object.keys(hasDataMap) as ObservabilityFetchDataPlugins[]).some( (app) => hasDataMap[app]?.hasData === true || - (Array.isArray(hasDataMap[app]?.hasData) && hasDataMap[app]?.hasData.length > 0) + (Array.isArray(hasDataMap[app]?.hasData) && (hasDataMap[app]?.hasData as Alert[])?.length > 0) ); return ( From 5c8928b9c85a1feac9ca87256fbbc015c2f63e3b Mon Sep 17 00:00:00 2001 From: Claudio Procida Date: Thu, 4 Nov 2021 17:06:54 +0100 Subject: [PATCH 3/4] Applies review feedback --- .../observability/public/context/has_data_context.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/observability/public/context/has_data_context.tsx b/x-pack/plugins/observability/public/context/has_data_context.tsx index a931352b6dc0a..7a56a40a5c100 100644 --- a/x-pack/plugins/observability/public/context/has_data_context.tsx +++ b/x-pack/plugins/observability/public/context/has_data_context.tsx @@ -146,11 +146,10 @@ export function HasDataContextProvider({ children }: { children: React.ReactNode return appStatus !== undefined && appStatus !== FETCH_STATUS.LOADING; }); - const hasAnyData = (Object.keys(hasDataMap) as ObservabilityFetchDataPlugins[]).some( - (app) => - hasDataMap[app]?.hasData === true || - (Array.isArray(hasDataMap[app]?.hasData) && (hasDataMap[app]?.hasData as Alert[])?.length > 0) - ); + const hasAnyData = (Object.keys(hasDataMap) as ObservabilityFetchDataPlugins[]).some((app) => { + const hasData = hasDataMap[app]?.hasData; + return hasData === true || (Array.isArray(hasData) && (hasData as Alert[])?.length > 0); + }); return ( Date: Thu, 4 Nov 2021 17:27:31 +0100 Subject: [PATCH 4/4] Naming is hard --- .../observability/public/context/has_data_context.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/observability/public/context/has_data_context.tsx b/x-pack/plugins/observability/public/context/has_data_context.tsx index 7a56a40a5c100..b6a45784a53b4 100644 --- a/x-pack/plugins/observability/public/context/has_data_context.tsx +++ b/x-pack/plugins/observability/public/context/has_data_context.tsx @@ -147,8 +147,10 @@ export function HasDataContextProvider({ children }: { children: React.ReactNode }); const hasAnyData = (Object.keys(hasDataMap) as ObservabilityFetchDataPlugins[]).some((app) => { - const hasData = hasDataMap[app]?.hasData; - return hasData === true || (Array.isArray(hasData) && (hasData as Alert[])?.length > 0); + const appHasData = hasDataMap[app]?.hasData; + return ( + appHasData === true || (Array.isArray(appHasData) && (appHasData as Alert[])?.length > 0) + ); }); return (