import { i18n } from '@osd/i18n' ; import { Action } from 'src/plugins/ui_actions/public' ; import { ViewMode } from '../../../../types' ; import { IEmbeddable } from '../../../../embeddables' ; export const ACTION_CUSTOMIZE_PANEL = 'ACTION_CUSTOMIZE_PANEL' ; type GetUserData = ( context : ActionContext ) => Promise < { title : string | undefined ; hideTitle ? : boolean ; } > ; interface ActionContext { embeddable : IEmbeddable ; } export class CustomizePanelTitleAction implements Action < ActionContext > { public readonly type = ACTION_CUSTOMIZE_PANEL ; public id = ACTION_CUSTOMIZE_PANEL ; public order = 40 ; constructor ( private readonly getDataFromUser ) { } public getDisplayName ( ) { return i18n . translate ( 'embeddableApi.customizePanel.action.displayName' , { defaultMessage : 'Edit panel title' , } ) ; } public getIconType ( ) { return 'pencil' ; } public async isCompatible ( { embeddable } ) { return embeddable . getInput ( ) . viewMode === ViewMode . EDIT ? true : false ; } public async execute ( { embeddable } ) { const data = await this . getDataFromUser ( { embeddable } ) ; const { title , hideTitle } = data ; embeddable . updateInput ( { title , hidePanelTitles : hideTitle } ) ; } }