import React , { useState } from 'react' ; import { useValuesList } from '../../../hooks/use_values_list' ; import { FieldValueSelection } from './field_value_selection' ; import { FieldValueSuggestionsProps } from './types' ; import { FieldValueCombobox } from './field_value_combobox' ; export function FieldValueSuggestions ( { fullWidth , sourceField , label , indexPatternTitle , selectedValue , excludedValue , filters , button , time , width , forceOpen , setForceOpen , anchorPosition , singleSelection , compressed , asFilterButton , usePrependLabel , allowAllValuesSelection , required , allowExclusions = true , cardinalityField , inspector , asCombobox = true , keepHistory = true , onChange : onSelectionChange , } ) { const [ query , setQuery ] = useState ( '' ) ; const { values , loading } = useValuesList ( { indexPatternTitle , query , sourceField , filters , time , inspector , cardinalityField , keepHistory , label , } ) ; const SelectionComponent = asCombobox ? FieldValueCombobox : FieldValueSelection ; return ( < SelectionComponent fullWidth = { fullWidth } singleSelection = { singleSelection } values = { values } label = { label } onChange = { onSelectionChange } query = { query } setQuery = { setQuery } loading = { loading } selectedValue = { selectedValue } excludedValue = { excludedValue } button = { button } forceOpen = { forceOpen } setForceOpen = { setForceOpen } anchorPosition = { anchorPosition } width = { width } compressed = { compressed } asFilterButton = { asFilterButton } usePrependLabel = { usePrependLabel } allowExclusions = { allowExclusions } allowAllValuesSelection = { singleSelection ? false : allowAllValuesSelection } required = { required } / > ) ; } export default FieldValueSuggestions ;