@@ -22,9 +22,8 @@ import { i18n } from '@kbn/i18n';
2222import { FormattedMessage } from '@kbn/i18n/react' ;
2323
2424import { metadata } from 'ui/metadata' ;
25- import { ES_FIELD_TYPES } from '../../../../../../../../../../../src/plugins/data/public' ;
2625import { ml } from '../../../../../services/ml_api_service' ;
27- import { Field , EVENT_RATE_FIELD_ID } from '../../../../../../../common/types/fields' ;
26+ import { Field } from '../../../../../../../common/types/fields' ;
2827import { newJobCapsService } from '../../../../../services/new_job_capabilities_service' ;
2928import { useKibanaContext } from '../../../../../contexts/kibana' ;
3029import { CreateAnalyticsFormProps } from '../../hooks/use_create_analytics_form' ;
@@ -43,25 +42,7 @@ import {
4342 indexPatterns ,
4443} from '../../../../../../../../../../../src/plugins/data/public' ;
4544import { DfAnalyticsExplainResponse , FieldSelectionItem } from '../../../../common/analytics' ;
46-
47- const BASIC_NUMERICAL_TYPES = new Set ( [
48- ES_FIELD_TYPES . LONG ,
49- ES_FIELD_TYPES . INTEGER ,
50- ES_FIELD_TYPES . SHORT ,
51- ES_FIELD_TYPES . BYTE ,
52- ] ) ;
53-
54- const EXTENDED_NUMERICAL_TYPES = new Set ( [
55- ES_FIELD_TYPES . DOUBLE ,
56- ES_FIELD_TYPES . FLOAT ,
57- ES_FIELD_TYPES . HALF_FLOAT ,
58- ES_FIELD_TYPES . SCALED_FLOAT ,
59- ] ) ;
60-
61- const CATEGORICAL_TYPES = new Set ( [ 'ip' , 'keyword' , 'text' ] ) ;
62-
63- // List of system fields we want to ignore for the numeric field check.
64- const OMIT_FIELDS : string [ ] = [ '_source' , '_type' , '_index' , '_id' , '_version' , '_score' ] ;
45+ import { shouldAddAsDepVarOption , OMIT_FIELDS } from './form_options_validation' ;
6546
6647export const CreateAnalyticsForm : FC < CreateAnalyticsFormProps > = ( { actions, state } ) => {
6748 const { setFormState } = actions ;
@@ -129,23 +110,6 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
129110 }
130111 } ;
131112
132- // Regression supports numeric fields. Classification supports categorical, numeric, and boolean.
133- const shouldAddAsDepVarOption = ( field : Field ) => {
134- if ( field . id === EVENT_RATE_FIELD_ID ) return false ;
135-
136- const isBasicNumerical = BASIC_NUMERICAL_TYPES . has ( field . type ) ;
137-
138- const isSupportedByClassification =
139- isBasicNumerical ||
140- CATEGORICAL_TYPES . has ( field . type ) ||
141- field . type === ES_FIELD_TYPES . BOOLEAN ;
142-
143- if ( jobType === JOB_TYPES . REGRESSION ) {
144- return isBasicNumerical || EXTENDED_NUMERICAL_TYPES . has ( field . type ) ;
145- }
146- if ( jobType === JOB_TYPES . CLASSIFICATION ) return isSupportedByClassification ;
147- } ;
148-
149113 const onCreateOption = ( searchValue : string , flattenedOptions : EuiComboBoxOptionProps [ ] ) => {
150114 const normalizedSearchValue = searchValue . trim ( ) . toLowerCase ( ) ;
151115
@@ -159,7 +123,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
159123
160124 // Create the option if it doesn't exist.
161125 if (
162- flattenedOptions . some (
126+ ! flattenedOptions . some (
163127 ( option : EuiComboBoxOptionProps ) =>
164128 option . label . trim ( ) . toLowerCase ( ) === normalizedSearchValue
165129 )
@@ -255,7 +219,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
255219 const depVarOptions : EuiComboBoxOptionProps [ ] = [ ] ;
256220
257221 fields . forEach ( ( field : Field ) => {
258- if ( shouldAddAsDepVarOption ( field ) ) {
222+ if ( shouldAddAsDepVarOption ( field , jobType ) ) {
259223 depVarOptions . push ( { label : field . id } ) ;
260224 }
261225 } ) ;
0 commit comments