Skip to content

Commit

Permalink
[ML] Show callout when both index patterns are missing.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Oct 20, 2020
1 parent 625dc09 commit dea4599
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,6 +34,9 @@ export const useResultsViewConfig = (jobId: string) => {
const trainedModelsApiService = useTrainedModelsApiService();

const [indexPattern, setIndexPattern] = useState<IndexPattern | undefined>(undefined);
const [indexPatternErrorMessage, setIndexPatternErrorMessage] = useState<undefined | string>(
undefined
);
const [isInitialized, setIsInitialized] = useState<boolean>(false);
const [needsDestIndexPattern, setNeedsDestIndexPattern] = useState<boolean>(false);
const [isLoadingJobConfig, setIsLoadingJobConfig] = useState<boolean>(false);
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
Expand All @@ -129,6 +148,7 @@ export const useResultsViewConfig = (jobId: string) => {

return {
indexPattern,
indexPatternErrorMessage,
isInitialized,
isLoadingJobConfig,
jobCapsServiceErrorMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -33,7 +33,12 @@ interface ExplorationProps {
}

export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) => {
const { indexPattern, jobConfig, needsDestIndexPattern } = useResultsViewConfig(jobId);
const {
indexPattern,
indexPatternErrorMessage,
jobConfig,
needsDestIndexPattern,
} = useResultsViewConfig(jobId);
const [searchQuery, setSearchQuery] = useState<SavedSearchQuery>(defaultSearchQuery);
const outlierData = useOutlierData(indexPattern, jobConfig, searchQuery);

Expand Down Expand Up @@ -61,6 +66,22 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
(d) => d.id === `${resultsField}.${FEATURE_INFLUENCE}.feature_name`
) === -1;

if (indexPatternErrorMessage !== undefined) {
return (
<EuiPanel grow={false}>
<EuiCallOut
title={i18n.translate('xpack.ml.dataframe.analytics.exploration.indexError', {
defaultMessage: 'An error occurred loading the index data.',
})}
color="danger"
iconType="cross"
>
<p>{indexPatternErrorMessage}</p>
</EuiCallOut>
</EuiPanel>
);
}

return (
<>
{typeof jobConfig?.description !== 'undefined' && (
Expand Down

0 comments on commit dea4599

Please sign in to comment.