import { ActionByType , APPLY_FILTER_TRIGGER , createAction , UiActionsStart , } from '../../../ui_actions/public' ; import { createFiltersFromValueClickAction } from './filters/create_filters_from_value_click' ; import type { Filter } from '../../common/opensearch_query/filters' ; import type { ValueClickContext } from '../../../embeddable/public' ; export type ValueClickActionContext = ValueClickContext ; export const ACTION_VALUE_CLICK = 'ACTION_VALUE_CLICK' ; export function createValueClickAction ( getStartServices ) { return createAction < typeof ACTION_VALUE_CLICK > ( { type : ACTION_VALUE_CLICK , id : ACTION_VALUE_CLICK , shouldAutoExecute : async ( ) => true , execute : async ( context ) => { try { const filters = await createFiltersFromValueClickAction ( 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_EMIT_APPLY_FILTER_TRIGGER]: can\'t extract filters from action context` ) ; } } , } ) ; }