66
77import React , { useState , FC } from 'react' ;
88
9- import { EuiSpacer , EuiText } from '@elastic/eui' ;
9+ import { EuiCallOut , EuiSpacer , EuiText } from '@elastic/eui' ;
10+
11+ import { i18n } from '@kbn/i18n' ;
1012
1113import {
1214 useColorRange ,
@@ -15,7 +17,8 @@ import {
1517} from '../../../../../components/color_range_legend' ;
1618import { SavedSearchQuery } from '../../../../../contexts/ml' ;
1719
18- import { defaultSearchQuery , useResultsViewConfig } from '../../../../common' ;
20+ import { defaultSearchQuery , isOutlierAnalysis , useResultsViewConfig } from '../../../../common' ;
21+ import { FEATURE_INFLUENCE } from '../../../../common/constants' ;
1922
2023import { ExpandableSectionAnalytics , ExpandableSectionResults } from '../expandable_section' ;
2124import { ExplorationQueryBar } from '../exploration_query_bar' ;
@@ -39,6 +42,24 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
3942 const featureCount = getFeatureCount ( jobConfig ?. dest ?. results_field || '' , tableItems ) ;
4043 const colorRange = useColorRange ( COLOR_RANGE . BLUE , COLOR_RANGE_SCALE . INFLUENCER , featureCount ) ;
4144
45+ // Show the color range only if feature influence is enabled and there's more than 0 features.
46+ const showColorRange =
47+ featureCount > 0 &&
48+ isOutlierAnalysis ( jobConfig ?. analysis ) &&
49+ jobConfig ?. analysis . outlier_detection . compute_feature_influence === true ;
50+
51+ const resultsField = jobConfig ?. dest . results_field ?? '' ;
52+
53+ // Identify if the results index has a legacy feature influence format.
54+ // If feature influence was enabled for the legacy job we'll show a callout
55+ // with some additional information for a workaround.
56+ const showLegacyFeatureInfluenceFormatCallout =
57+ isOutlierAnalysis ( jobConfig ?. analysis ) &&
58+ jobConfig ?. analysis . outlier_detection . compute_feature_influence === true &&
59+ columnsWithCharts . findIndex (
60+ ( d ) => d . id === `${ resultsField } .${ FEATURE_INFLUENCE } .feature_name`
61+ ) === - 1 ;
62+
4263 return (
4364 < >
4465 { typeof jobConfig ?. description !== 'undefined' && (
@@ -55,8 +76,26 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
5576 </ >
5677 ) }
5778 { typeof jobConfig ?. id === 'string' && < ExpandableSectionAnalytics jobId = { jobConfig ?. id } /> }
79+ { showLegacyFeatureInfluenceFormatCallout && (
80+ < >
81+ < EuiCallOut
82+ size = "s"
83+ title = { i18n . translate (
84+ 'xpack.ml.dataframe.analytics.outlierExploration.legacyFeatureInfluenceFormatCalloutTitle' ,
85+ {
86+ defaultMessage :
87+ 'Color coded table cells based on feature influence are not available, because this results index uses an unsupported legacy format. Please clone an rerun the job to enable support for color coding.' ,
88+ }
89+ ) }
90+ iconType = "pin"
91+ />
92+ < EuiSpacer size = "m" />
93+ </ >
94+ ) }
5895 < ExpandableSectionResults
59- colorRange = { featureCount > 0 ? colorRange : undefined }
96+ colorRange = {
97+ showColorRange && ! showLegacyFeatureInfluenceFormatCallout ? colorRange : undefined
98+ }
6099 indexData = { outlierData }
61100 indexPattern = { indexPattern }
62101 jobConfig = { jobConfig }
0 commit comments