From cf5ba6fd55952f0f4f2d7ca34998c41ba202067c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Thu, 12 Mar 2020 23:26:16 +0100 Subject: [PATCH] =?UTF-8?q?[Logs=20UI]=20Show=20navigation=20bar=20while?= =?UTF-8?q?=20loading=20source=20configurati=E2=80=A6=20(#59997)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This moves the navigation bar and the source configuration loading indicator such that the bar is immediately visible and usable even before the source configuration has finished loading. closes #56728 --- .../source_configuration_settings.tsx | 5 +- .../logs/log_analysis/log_analysis_module.tsx | 23 ++++++++- .../log_analysis_module_status.tsx | 16 +++---- .../infra/public/containers/source/source.tsx | 5 ++ .../log_entry_categories/page_content.tsx | 18 ++++++- .../logs/log_entry_rate/page_content.tsx | 18 ++++++- .../infra/public/pages/logs/page_content.tsx | 47 ++++++------------- .../public/pages/logs/stream/page_content.tsx | 26 ++++++++-- 8 files changed, 104 insertions(+), 54 deletions(-) diff --git a/x-pack/plugins/infra/public/components/source_configuration/source_configuration_settings.tsx b/x-pack/plugins/infra/public/components/source_configuration/source_configuration_settings.tsx index 68dbdf38e6af6..36645fa3f1f35 100644 --- a/x-pack/plugins/infra/public/components/source_configuration/source_configuration_settings.tsx +++ b/x-pack/plugins/infra/public/components/source_configuration/source_configuration_settings.tsx @@ -41,6 +41,7 @@ export const SourceConfigurationSettings = ({ source, sourceExists, isLoading, + isUninitialized, updateSourceConfiguration, } = useContext(Source.Context); @@ -83,10 +84,10 @@ export const SourceConfigurationSettings = ({ source, ]); - if (!source) { + if ((isLoading || isUninitialized) && !source) { return ; } - if (!source.configuration) { + if (!source?.configuration) { return null; } diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx index d7d0ecb6f2c8d..efe9629e84e42 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { useCallback, useMemo } from 'react'; +import { useCallback, useEffect, useMemo } from 'react'; import { useTrackedPromise } from '../../../utils/use_tracked_promise'; import { useModuleStatus } from './log_analysis_module_status'; @@ -146,6 +146,27 @@ export const useLogAnalysisModule = ({ sourceId, ]); + useEffect(() => { + dispatchModuleStatus({ + type: 'updatedSourceConfiguration', + spaceId, + sourceId, + sourceConfiguration: { + timestampField, + indexPattern: indices.join(','), + bucketSpan: moduleDescriptor.bucketSpan, + }, + }); + }, [ + dispatchModuleStatus, + indices, + moduleDescriptor.bucketSpan, + sourceConfiguration, + sourceId, + spaceId, + timestampField, + ]); + return { cleanUpAndSetUpModule, cleanUpModule, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_status.tsx b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_status.tsx index bc91ae4b138b4..cf248f419f6f2 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_status.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_status.tsx @@ -329,18 +329,14 @@ const getSetupStatus = ( ) { return setupStatus; } else if ( - setupStatus === 'skippedButUpdatable' || - (jobDefinition && - !isJobRevisionCurrent( - jobId, - jobDefinition.config.custom_settings.job_revision || 0 - )(jobSummaries)) + jobDefinition && + !isJobRevisionCurrent( + jobId, + jobDefinition.config.custom_settings.job_revision || 0 + )(jobSummaries) ) { return 'skippedButUpdatable'; - } else if ( - setupStatus === 'skippedButReconfigurable' || - !isJobConfigurationConsistent(jobId, sourceConfiguration)(jobSummaries) - ) { + } else if (!isJobConfigurationConsistent(jobId, sourceConfiguration)(jobSummaries)) { return 'skippedButReconfigurable'; } else if (setupStatus === 'hiddenAfterSuccess') { return setupStatus; diff --git a/x-pack/plugins/infra/public/containers/source/source.tsx b/x-pack/plugins/infra/public/containers/source/source.tsx index 4729f7aa31f0b..a1310b1f33614 100644 --- a/x-pack/plugins/infra/public/containers/source/source.tsx +++ b/x-pack/plugins/infra/public/containers/source/source.tsx @@ -142,6 +142,10 @@ export const useSource = ({ sourceId }: { sourceId: string }) => { ] ); + const isUninitialized = useMemo(() => loadSourceRequest.state === 'uninitialized', [ + loadSourceRequest.state, + ]); + const sourceExists = useMemo(() => (source ? !!source.version : undefined), [source]); const logIndicesExist = useMemo(() => source && source.status && source.status.logIndicesExist, [ @@ -162,6 +166,7 @@ export const useSource = ({ sourceId }: { sourceId: string }) => { logIndicesExist, isLoading, isLoadingSource: loadSourceRequest.state === 'pending', + isUninitialized, hasFailedLoadingSource: loadSourceRequest.state === 'rejected', loadSource, loadSourceFailureMessage: diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_content.tsx index b6975ffc54691..d1c10820f7c9c 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/page_content.tsx @@ -6,7 +6,6 @@ import { i18n } from '@kbn/i18n'; import React, { useEffect } from 'react'; - import { isSetupStatusWithResults } from '../../../../common/log_analysis'; import { LoadingPage } from '../../../components/loading_page'; import { @@ -15,12 +14,23 @@ import { MissingSetupPrivilegesPrompt, MlUnavailablePrompt, } from '../../../components/logging/log_analysis_setup'; +import { SourceErrorPage } from '../../../components/source_error_page'; +import { SourceLoadingPage } from '../../../components/source_loading_page'; import { useLogAnalysisCapabilitiesContext } from '../../../containers/logs/log_analysis'; +import { useSourceContext } from '../../../containers/source'; import { LogEntryCategoriesResultsContent } from './page_results_content'; import { LogEntryCategoriesSetupContent } from './page_setup_content'; import { useLogEntryCategoriesModuleContext } from './use_log_entry_categories_module'; export const LogEntryCategoriesPageContent = () => { + const { + hasFailedLoadingSource, + isLoadingSource, + isUninitialized, + loadSource, + loadSourceFailureMessage, + } = useSourceContext(); + const { hasLogAnalysisCapabilites, hasLogAnalysisReadCapabilities, @@ -40,7 +50,11 @@ export const LogEntryCategoriesPageContent = () => { } }, [fetchJobStatus, fetchModuleDefinition, hasLogAnalysisReadCapabilities]); - if (!hasLogAnalysisCapabilites) { + if (isLoadingSource || isUninitialized) { + return ; + } else if (hasFailedLoadingSource) { + return ; + } else if (!hasLogAnalysisCapabilites) { return ; } else if (!hasLogAnalysisReadCapabilities) { return ; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_content.tsx index 8d2b4e1fd0ff4..fe12ca5455a75 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_content.tsx @@ -6,7 +6,6 @@ import { i18n } from '@kbn/i18n'; import React, { useEffect } from 'react'; - import { isSetupStatusWithResults } from '../../../../common/log_analysis'; import { LoadingPage } from '../../../components/loading_page'; import { @@ -15,12 +14,23 @@ import { MissingSetupPrivilegesPrompt, MlUnavailablePrompt, } from '../../../components/logging/log_analysis_setup'; +import { SourceErrorPage } from '../../../components/source_error_page'; +import { SourceLoadingPage } from '../../../components/source_loading_page'; import { useLogAnalysisCapabilitiesContext } from '../../../containers/logs/log_analysis'; +import { useSourceContext } from '../../../containers/source'; import { LogEntryRateResultsContent } from './page_results_content'; import { LogEntryRateSetupContent } from './page_setup_content'; import { useLogEntryRateModuleContext } from './use_log_entry_rate_module'; export const LogEntryRatePageContent = () => { + const { + hasFailedLoadingSource, + isLoadingSource, + isUninitialized, + loadSource, + loadSourceFailureMessage, + } = useSourceContext(); + const { hasLogAnalysisCapabilites, hasLogAnalysisReadCapabilities, @@ -36,7 +46,11 @@ export const LogEntryRatePageContent = () => { } }, [fetchJobStatus, fetchModuleDefinition, hasLogAnalysisReadCapabilities]); - if (!hasLogAnalysisCapabilites) { + if (isLoadingSource || isUninitialized) { + return ; + } else if (hasFailedLoadingSource) { + return ; + } else if (!hasLogAnalysisCapabilites) { return ; } else if (!hasLogAnalysisReadCapabilities) { return ; diff --git a/x-pack/plugins/infra/public/pages/logs/page_content.tsx b/x-pack/plugins/infra/public/pages/logs/page_content.tsx index 3ead026b10065..ed6f06deeef64 100644 --- a/x-pack/plugins/infra/public/pages/logs/page_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/page_content.tsx @@ -15,10 +15,7 @@ import { HelpCenterContent } from '../../components/help_center_content'; import { AppNavigation } from '../../components/navigation/app_navigation'; import { RoutedTabs } from '../../components/navigation/routed_tabs'; import { ColumnarPage } from '../../components/page'; -import { SourceErrorPage } from '../../components/source_error_page'; -import { SourceLoadingPage } from '../../components/source_loading_page'; import { useLogAnalysisCapabilitiesContext } from '../../containers/logs/log_analysis'; -import { useSourceContext } from '../../containers/source'; import { RedirectWithQueryParams } from '../../utils/redirect_with_query_params'; import { LogEntryCategoriesPage } from './log_entry_categories'; import { LogEntryRatePage } from './log_entry_rate'; @@ -27,7 +24,6 @@ import { StreamPage } from './stream'; export const LogsPageContent: React.FunctionComponent = () => { const uiCapabilities = useKibana().services.application?.capabilities; - const source = useSourceContext(); const logAnalysisCapabilities = useLogAnalysisCapabilitiesContext(); const streamTab = { @@ -68,35 +64,22 @@ export const LogsPageContent: React.FunctionComponent = () => { ]} readOnlyBadge={!uiCapabilities?.logs?.save} /> - {source.isLoadingSource || - (!source.isLoadingSource && !source.hasFailedLoadingSource && source.source === undefined) ? ( - - ) : source.hasFailedLoadingSource ? ( - + - ) : ( - <> - - - - - - - - - - - - - )} + + + + + + + + ); }; diff --git a/x-pack/plugins/infra/public/pages/logs/stream/page_content.tsx b/x-pack/plugins/infra/public/pages/logs/stream/page_content.tsx index 3188b3e03b015..010a17dae4ebd 100644 --- a/x-pack/plugins/infra/public/pages/logs/stream/page_content.tsx +++ b/x-pack/plugins/infra/public/pages/logs/stream/page_content.tsx @@ -4,14 +4,30 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useContext } from 'react'; - -import { Source } from '../../../containers/source'; +import React from 'react'; +import { SourceErrorPage } from '../../../components/source_error_page'; +import { SourceLoadingPage } from '../../../components/source_loading_page'; +import { useSourceContext } from '../../../containers/source'; import { LogsPageLogsContent } from './page_logs_content'; import { LogsPageNoIndicesContent } from './page_no_indices_content'; export const StreamPageContent: React.FunctionComponent = () => { - const { logIndicesExist } = useContext(Source.Context); + const { + hasFailedLoadingSource, + isLoadingSource, + isUninitialized, + loadSource, + loadSourceFailureMessage, + logIndicesExist, + } = useSourceContext(); - return <>{logIndicesExist ? : }; + if (isLoadingSource || isUninitialized) { + return ; + } else if (hasFailedLoadingSource) { + return ; + } else if (logIndicesExist) { + return ; + } else { + return ; + } };