import { i18n } from '@osd/i18n' ; import { Action , ActionExecutionContext } from 'src/plugins/ui_actions/public' ; import { NotificationsStart , OverlayStart } from 'src/core/public' ; import { EmbeddableStart } from 'src/plugins/embeddable/public/plugin' ; import { ViewMode } from '../../../../types' ; import { openAddPanelFlyout } from './open_add_panel_flyout' ; import { IContainer } from '../../../../containers' ; export const ACTION_ADD_PANEL = 'ACTION_ADD_PANEL' ; interface ActionContext { embeddable : IContainer ; } export class AddPanelAction implements Action < ActionContext > { public readonly type = ACTION_ADD_PANEL ; public readonly id = ACTION_ADD_PANEL ; constructor ( private readonly getFactory , private readonly getAllFactories , private readonly overlays , private readonly notifications , private readonly SavedObjectFinder ) { } public getDisplayName ( ) { return i18n . translate ( 'embeddableApi.addPanel.displayName' , { defaultMessage : 'Add panel' , } ) ; } public getIconType ( ) { return 'plusInCircleFilled' ; } public async isCompatible ( context ) { const { embeddable } = context ; return embeddable . getIsContainer ( ) && embeddable . getInput ( ) . viewMode === ViewMode . EDIT ; } public async execute ( context ) { const { embeddable } = context ; if ( ! embeddable . getIsContainer ( ) || ! ( await this . isCompatible ( context ) ) ) { throw new Error ( 'Context is incompatible' ) ; } openAddPanelFlyout ( { embeddable , getFactory : this . getFactory , getAllFactories : this . getAllFactories , overlays : this . overlays , notifications : this . notifications , SavedObjectFinder : this . SavedObjectFinder , } ) ; } }