import { keys , partition } from 'lodash' ; import { Filter , isRangeFilter , RangeFilter , TimeRange } from '../../../../common' ; import { convertRangeFilterToTimeRangeString } from './change_time_filter' ; export function extractTimeFilter ( timeFieldName , filters ) { const [ timeRangeFilter , restOfFilters ] = partition ( filters , ( obj ) => { let key ; if ( isRangeFilter ( obj ) ) { key = keys ( obj . range ) [ 0 ] ; } return Boolean ( key && key === timeFieldName ) ; } ) ; return { restOfFilters , timeRangeFilter : timeRangeFilter [ 0 ] as RangeFilter | undefined , } ; } export function extractTimeRange ( filters , timeFieldName ? ) { if ( ! timeFieldName ) return { restOfFilters : filters , timeRange : undefined } ; const { timeRangeFilter , restOfFilters } = extractTimeFilter ( timeFieldName , filters ) ; return { restOfFilters , timeRange : timeRangeFilter ? convertRangeFilterToTimeRangeString ( timeRangeFilter ) : undefined , } ; }