Skip to content

Commit b9c6184

Browse files
committed
Add image embeddable to Canvas
1 parent 57f1cd6 commit b9c6184

2 files changed

Lines changed: 13 additions & 18 deletions

File tree

src/plugins/image_embeddable/public/actions/create_image_action.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,28 @@
77
*/
88

99
import { 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';
1211
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
1312
import {
1413
ADD_IMAGE_EMBEDDABLE_ACTION_ID,
1514
IMAGE_EMBEDDABLE_TYPE,
1615
} from '../image_embeddable/constants';
1716
import { 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-
2718
export 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
};

src/plugins/image_embeddable/public/components/image_editor/open_image_editor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import React from 'react';
1010

11-
import { PresentationContainer, tracksOverlays } from '@kbn/presentation-containers';
11+
import { CanAddNewPanel } from '@kbn/presentation-publishing';
12+
import { tracksOverlays } from '@kbn/presentation-containers';
1213
import { toMountPoint } from '@kbn/react-kibana-mount';
1314
import { FilesContext } from '@kbn/shared-ux-file-context';
1415

@@ -22,7 +23,7 @@ export const openImageEditor = async ({
2223
parentApi,
2324
initialImageConfig,
2425
}: {
25-
parentApi: PresentationContainer;
26+
parentApi: CanAddNewPanel;
2627
initialImageConfig?: ImageConfig;
2728
}): Promise<ImageConfig> => {
2829
const { ImageEditorFlyout } = await import('./image_editor_flyout');

0 commit comments

Comments
 (0)