From dea4599c69bf32ed9310394ca33efca610baeb9e Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Tue, 20 Oct 2020 23:28:40 +0200 Subject: [PATCH] [ML] Show callout when both index patterns are missing. --- .../common/use_results_view_config.ts | 22 +++++++++++++++- .../outlier_exploration.tsx | 25 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts index 7d2ca86a38083..81c2e246120c0 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts @@ -6,6 +6,8 @@ import { useEffect, useState } from 'react'; +import { i18n } from '@kbn/i18n'; + import { IndexPattern } from '../../../../../../../src/plugins/data/public'; import { extractErrorMessage } from '../../../../common/util/errors'; @@ -32,6 +34,9 @@ export const useResultsViewConfig = (jobId: string) => { const trainedModelsApiService = useTrainedModelsApiService(); const [indexPattern, setIndexPattern] = useState(undefined); + const [indexPatternErrorMessage, setIndexPatternErrorMessage] = useState( + undefined + ); const [isInitialized, setIsInitialized] = useState(false); const [needsDestIndexPattern, setNeedsDestIndexPattern] = useState(false); const [isLoadingJobConfig, setIsLoadingJobConfig] = useState(false); @@ -105,7 +110,11 @@ export const useResultsViewConfig = (jobId: string) => { setNeedsDestIndexPattern(true); const sourceIndex = jobConfigUpdate.source.index[0]; const sourceIndexPatternId = getIndexPatternIdFromName(sourceIndex) || sourceIndex; - indexP = await mlContext.indexPatterns.get(sourceIndexPatternId); + try { + indexP = await mlContext.indexPatterns.get(sourceIndexPatternId); + } catch (e) { + indexP = undefined; + } } if (indexP !== undefined) { @@ -114,6 +123,16 @@ export const useResultsViewConfig = (jobId: string) => { setIndexPattern(indexP); setIsInitialized(true); setIsLoadingJobConfig(false); + } else { + setIndexPatternErrorMessage( + i18n.translate( + 'xpack.ml.dataframe.analytics.results.indexPatternsMissingErrorMessage', + { + defaultMessage: + 'To view this page, a Kibana index pattern is necessary for either the destination or source index of this analytics job.', + } + ) + ); } } catch (e) { setJobCapsServiceErrorMessage(extractErrorMessage(e)); @@ -129,6 +148,7 @@ export const useResultsViewConfig = (jobId: string) => { return { indexPattern, + indexPatternErrorMessage, isInitialized, isLoadingJobConfig, jobCapsServiceErrorMessage, diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx index 0c6f01e1544a3..9e30ed3cdfe95 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/outlier_exploration/outlier_exploration.tsx @@ -6,7 +6,7 @@ import React, { useState, FC } from 'react'; -import { EuiCallOut, EuiSpacer, EuiText } from '@elastic/eui'; +import { EuiCallOut, EuiPanel, EuiSpacer, EuiText } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; @@ -33,7 +33,12 @@ interface ExplorationProps { } export const OutlierExploration: FC = React.memo(({ jobId }) => { - const { indexPattern, jobConfig, needsDestIndexPattern } = useResultsViewConfig(jobId); + const { + indexPattern, + indexPatternErrorMessage, + jobConfig, + needsDestIndexPattern, + } = useResultsViewConfig(jobId); const [searchQuery, setSearchQuery] = useState(defaultSearchQuery); const outlierData = useOutlierData(indexPattern, jobConfig, searchQuery); @@ -61,6 +66,22 @@ export const OutlierExploration: FC = React.memo(({ jobId }) = (d) => d.id === `${resultsField}.${FEATURE_INFLUENCE}.feature_name` ) === -1; + if (indexPatternErrorMessage !== undefined) { + return ( + + +

{indexPatternErrorMessage}

+
+
+ ); + } + return ( <> {typeof jobConfig?.description !== 'undefined' && (