77 */
88
99import { i18n } from '@kbn/i18n' ;
10- import { PresentationContainer } from '@kbn/presentation-containers' ;
11- import { EmbeddableApiContext } from '@kbn/presentation-publishing' ;
10+ import { apiCanAddNewPanel , EmbeddableApiContext } from '@kbn/presentation-publishing' ;
1211import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public' ;
1312import {
1413 ADD_IMAGE_EMBEDDABLE_ACTION_ID ,
1514 IMAGE_EMBEDDABLE_TYPE ,
1615} from '../image_embeddable/constants' ;
1716import { uiActionsService } from '../services/kibana_services' ;
1817
19- const parentApiIsCompatible = async (
20- parentApi : unknown
21- ) : Promise < PresentationContainer | undefined > => {
22- const { apiIsPresentationContainer } = await import ( '@kbn/presentation-containers' ) ;
23- // we cannot have an async type check, so return the casted parentApi rather than a boolean
24- return apiIsPresentationContainer ( parentApi ) ? ( parentApi as PresentationContainer ) : undefined ;
25- } ;
26-
2718export const registerCreateImageAction = ( ) => {
2819 uiActionsService . registerAction < EmbeddableApiContext > ( {
2920 id : ADD_IMAGE_EMBEDDABLE_ACTION_ID ,
3021 getIconType : ( ) => 'image' ,
3122 isCompatible : async ( { embeddable : parentApi } ) => {
32- return Boolean ( await parentApiIsCompatible ( parentApi ) ) ;
23+ return apiCanAddNewPanel ( parentApi ) ;
3324 } ,
3425 execute : async ( { embeddable : parentApi } ) => {
35- const presentationContainerParent = await parentApiIsCompatible ( parentApi ) ;
36- if ( ! presentationContainerParent ) throw new IncompatibleActionError ( ) ;
37-
26+ if ( ! apiCanAddNewPanel ( parentApi ) ) throw new IncompatibleActionError ( ) ;
3827 const { openImageEditor } = await import ( '../components/image_editor/open_image_editor' ) ;
3928 try {
40- const imageConfig = await openImageEditor ( { parentApi : presentationContainerParent } ) ;
29+ const imageConfig = await openImageEditor ( { parentApi } ) ;
4130
42- presentationContainerParent . addNewPanel ( {
31+ parentApi . addNewPanel ( {
4332 panelType : IMAGE_EMBEDDABLE_TYPE ,
4433 initialState : { imageConfig } ,
4534 } ) ;
@@ -54,4 +43,9 @@ export const registerCreateImageAction = () => {
5443 } ) ;
5544
5645 uiActionsService . attachAction ( 'ADD_PANEL_TRIGGER' , ADD_IMAGE_EMBEDDABLE_ACTION_ID ) ;
46+ if ( uiActionsService . hasTrigger ( 'ADD_CANVAS_ELEMENT_TRIGGER' ) ) {
47+ // Because Canvas is not enabled in Serverless, this trigger might not be registered - only attach
48+ // the create action if the Canvas-specific trigger does indeed exist.
49+ uiActionsService . attachAction ( 'ADD_CANVAS_ELEMENT_TRIGGER' , ADD_IMAGE_EMBEDDABLE_ACTION_ID ) ;
50+ }
5751} ;
0 commit comments