import { i18n } from '@osd/i18n' ; import { CoreStart } from 'src/core/public' ; import { IEmbeddable , ViewMode , EmbeddableStart } from '../../embeddable_plugin' ; import { DASHBOARD_CONTAINER_TYPE , DashboardContainer } from '../embeddable' ; import { ActionByType , IncompatibleActionError } from '../../ui_actions_plugin' ; import { openReplacePanelFlyout } from './open_replace_panel_flyout' ; export const ACTION_REPLACE_PANEL = 'replacePanel' ; function isDashboard ( embeddable ) { return embeddable . type === DASHBOARD_CONTAINER_TYPE ; } export interface ReplacePanelActionContext { embeddable : IEmbeddable ; } export class ReplacePanelAction implements ActionByType < typeof ACTION_REPLACE_PANEL > { public readonly type = ACTION_REPLACE_PANEL ; public readonly id = ACTION_REPLACE_PANEL ; public order = 3 ; constructor ( private core , private savedobjectfinder , private notifications , private getEmbeddableFactories ) { } public getDisplayName ( { embeddable } ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } return i18n . translate ( 'dashboard.panel.removePanel.replacePanel' , { defaultMessage : 'Replace panel' , } ) ; } public getIconType ( { embeddable } ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } return 'dqlOperand' ; } public async isCompatible ( { embeddable } ) { if ( embeddable . getInput ( ) . viewMode ) { if ( embeddable . getInput ( ) . viewMode === ViewMode . VIEW ) { return false ; } } return Boolean ( embeddable . parent && isDashboard ( embeddable . parent ) ) ; } public async execute ( { embeddable } ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } const view = embeddable ; const dash = embeddable . parent ; openReplacePanelFlyout ( { embeddable : dash , core : this . core , savedObjectFinder : this . savedobjectfinder , notifications : this . notifications , panelToRemove : view , getEmbeddableFactories : this . getEmbeddableFactories , } ) ; } }