import { last } from 'lodash' ; import moment from 'moment' ; import { opensearchFilters , IFieldType , RangeFilterParams } from '../../../public' ; import { getIndexPatterns } from '../../../public/services' ; import { deserializeAggConfig } from '../../search/expressions/utils' ; import type { RangeSelectContext } from '../../../../embeddable/public' ; export async function createFiltersFromRangeSelectAction ( event ) { const column = event . table . columns [ event . column ] ; if ( ! column || ! column . meta ) { return [ ] ; } const indexPattern = await getIndexPatterns ( ) . get ( column . meta . indexPatternId ) ; const aggConfig = deserializeAggConfig ( { ... column . meta , indexPattern , } ) ; const field = aggConfig . params . field ; if ( ! field || event . range . length <= 1 ) { return [ ] ; } const min = event . range [ 0 ] ; const max = last ( event . range ) ; if ( min === max ) { return [ ] ; } const isDate = field . type === 'date' ; const range = { gte : isDate ? moment ( min ) . toISOString ( ) : min , lt : isDate ? moment ( max ) . toISOString ( ) : max , } ; if ( isDate ) { range . format = 'strict_date_optional_time' ; } return opensearchFilters . mapAndFlattenFilters ( [ opensearchFilters . buildRangeFilter ( field , range , indexPattern ) , ] ) ; }