import React from 'react' ; import { Action , ActionContext as Context , ActionDefinition } from './action' ; import { Presentable , PresentableGrouping } from '../util/presentable' ; import { uiToReactComponent } from '../../../opensearch_dashboards_react/public' ; import { ActionType } from '../types' ; internal export class ActionInternal < A extends ActionDefinition = ActionDefinition > implements Action < Context < A > > , Presentable < Context < A > > { constructor ( public readonly definition ) { } public readonly id : string = this . definition . id ; public readonly type : ActionType = this . definition . type || '' ; public readonly order : number = this . definition . order || 0 ; public readonly MenuItem ? = this . definition . MenuItem ; public readonly ReactMenuItem ? = this . MenuItem ? uiToReactComponent ( this . MenuItem ) : undefined ; public readonly grouping ? : PresentableGrouping < Context < A > > = this . definition . grouping ; public execute ( context ) { return this . definition . execute ( context ) ; } public getIconType ( context ) { if ( ! this . definition . getIconType ) return undefined ; return this . definition . getIconType ( context ) ; } public getDisplayName ( context ) { if ( ! this . definition . getDisplayName ) return `Action: ${ this . id }` ; return this . definition . getDisplayName ( context ) ; } public getDisplayNameTooltip ( context ) { if ( ! this . definition . getDisplayNameTooltip ) return '' ; return this . definition . getDisplayNameTooltip ( context ) ; } public async isCompatible ( context ) { if ( ! this . definition . isCompatible ) return true ; return await this . definition . isCompatible ( context ) ; } public async getHref ( context ) { if ( ! this . definition . getHref ) return undefined ; return await this . definition . getHref ( context ) ; } public async shouldAutoExecute ( context ) { if ( ! this . definition . shouldAutoExecute ) return false ; return this . definition . shouldAutoExecute ( context ) ; } }