import { ActionByType , APPLY_FILTER_TRIGGER , createAction , UiActionsStart , } from '../../../ui_actions/public' ; import { createFiltersFromRangeSelectAction } from './filters/create_filters_from_range_select' ; import type { RangeSelectContext } from '../../../embeddable/public' ; export type SelectRangeActionContext = RangeSelectContext ; export const ACTION_SELECT_RANGE = 'ACTION_SELECT_RANGE' ; export function createSelectRangeAction ( getStartServices ) { return createAction < typeof ACTION_SELECT_RANGE > ( { type : ACTION_SELECT_RANGE , id : ACTION_SELECT_RANGE , shouldAutoExecute : async ( ) => true , execute : async ( context ) => { try { const filters = await createFiltersFromRangeSelectAction ( context . data ) ; if ( filters . length > 0 ) { await getStartServices ( ) . uiActions . getTrigger ( APPLY_FILTER_TRIGGER ) . exec ( { filters , embeddable : context . embeddable , timeFieldName : context . data . timeFieldName , } ) ; } } catch ( e ) { console . warn ( `Error [ACTION_SELECT_RANGE]: can\'t extract filters from action context` ) ; } } , } ) ; }