import { i18n } from '@osd/i18n' ; import { IEmbeddable } from '../../embeddable_plugin' ; import { ActionByType , IncompatibleActionError } from '../../ui_actions_plugin' ; import { DASHBOARD_CONTAINER_TYPE , DashboardContainer } from '../embeddable' ; export const ACTION_EXPAND_PANEL = 'togglePanel' ; function isDashboard ( embeddable ) { return embeddable . type === DASHBOARD_CONTAINER_TYPE ; } function isExpanded ( embeddable ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } return embeddable . id === embeddable . parent . getInput ( ) . expandedPanelId ; } export interface ExpandPanelActionContext { embeddable : IEmbeddable ; } export class ExpandPanelAction implements ActionByType < typeof ACTION_EXPAND_PANEL > { public readonly type = ACTION_EXPAND_PANEL ; public readonly id = ACTION_EXPAND_PANEL ; public order = 7 ; constructor ( ) { } public getDisplayName ( { embeddable } ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } return isExpanded ( embeddable ) ? i18n . translate ( 'dashboard.actions.toggleExpandPanelMenuItem.expandedDisplayName' , { defaultMessage : 'Minimize' , } ) : i18n . translate ( 'dashboard.actions.toggleExpandPanelMenuItem.notExpandedDisplayName' , { defaultMessage : 'Maximize panel' , } ) ; } public getIconType ( { embeddable } ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } return isExpanded ( embeddable ) ? 'expand' : 'expand' ; } public async isCompatible ( { embeddable } ) { return Boolean ( embeddable . parent && isDashboard ( embeddable . parent ) ) ; } public async execute ( { embeddable } ) { if ( ! embeddable . parent || ! isDashboard ( embeddable . parent ) ) { throw new IncompatibleActionError ( ) ; } const newValue = isExpanded ( embeddable ) ? undefined : embeddable . id ; embeddable . parent . updateInput ( { expandedPanelId : newValue , } ) ; } }