import React , { useEffect } from 'react' ; import { AggParamEditorProps } from '../agg_param_props' ; import { StringParamEditor } from './string' ; import { search } from '../../../../data/public' ; import { SimpleNumberList } from './components/simple_number_list' ; const { isNumberType } = search . aggs ; export function IncludeExcludeParamEditor ( props ) { const { agg , value , setValue } = props ; const isAggOfNumberType = isNumberType ( agg ) ; useEffect ( ( ) => { if ( isAggOfNumberType && ! Array . isArray ( value ) && value !== undefined ) { const numberArray = value . split ( '|' ) . map ( ( item ) => parseFloat ( item ) ) . filter ( ( number ) => Number . isFinite ( number ) ) ; setValue ( numberArray . length ? numberArray : [ '' ] ) ; } else if ( ! isAggOfNumberType && Array . isArray ( value ) && value !== undefined ) { setValue ( value . filter ( ( item ) => item !== '' ) . join ( '|' ) ) ; } } , [ isAggOfNumberType , setValue , value ] ) ; return isAggOfNumberType ? ( < SimpleNumberList { ... props } value = { value as Array < number | '' > } />) : (<StringParamEditor {...props} value={value as string}/ > ) ; }