import { ExistsFilter , isExistsFilter } from '@kbn/es-query' ; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import { useValuesList } from '../../../../hooks/use_values_list' ; import { FilterProps } from './columns/filter_expanded' ; import { useAppIndexPatternContext } from '../hooks/use_app_index_pattern' ; import { ESFilter } from '../../../../../../../../src/core/types/elasticsearch' ; import { PersistableFilter } from '../../../../../../lens/common' ; export function useFilterValues ( { field , series , baseFilters , label } , query ? ) { const { indexPatterns } = useAppIndexPatternContext ( series . dataType ) ; const queryFilters = [ ] ; baseFilters ?. forEach ( ( qFilter ) => { if ( qFilter . query ) { queryFilters . push ( qFilter . query ) ; } if ( isExistsFilter ( qFilter ) ) { queryFilters . push ( { exists : qFilter . query . exists } as estypes . QueryDslQueryContainer ) ; } } ) ; return useValuesList ( { query , label : label ?? field , sourceField : field , time : series . time , keepHistory : true , filters : queryFilters , indexPatternTitle : indexPatterns [ series . dataType ] ?. title , } ) ; }