From 0a7b8cad189dd3ec5a440bcf32cd66d28ce170b0 Mon Sep 17 00:00:00 2001 From: Corey Robertson Date: Wed, 25 Aug 2021 14:42:45 -0400 Subject: [PATCH] [Canvas] Fix reports embeddables (#93482) (#109952) * wip * WIP Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../renderers/embeddable/embeddable.tsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx index e9050d313fba..73e839433c25 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx @@ -24,7 +24,7 @@ import { CANVAS_EMBEDDABLE_CLASSNAME } from '../../../common/lib'; const { embeddable: strings } = RendererStrings; const embeddablesRegistry: { - [key: string]: IEmbeddable; + [key: string]: IEmbeddable | Promise; } = {}; const renderEmbeddableFactory = (core: CoreStart, plugins: StartDeps) => { @@ -67,7 +67,15 @@ export const embeddableRendererFactory = ( throw new EmbeddableFactoryNotFoundError(embeddableType); } - const embeddableObject = await factory.createFromSavedObject(input.id, input); + const embeddablePromise = factory + .createFromSavedObject(input.id, input) + .then((embeddable) => { + embeddablesRegistry[uniqueId] = embeddable; + return embeddable; + }); + embeddablesRegistry[uniqueId] = embeddablePromise; + + const embeddableObject = await (async () => embeddablePromise)(); const palettes = await plugins.charts.palettes.getPalettes(); @@ -105,8 +113,12 @@ export const embeddableRendererFactory = ( return ReactDOM.unmountComponentAtNode(domNode); }); } else { - embeddablesRegistry[uniqueId].updateInput(input); - embeddablesRegistry[uniqueId].reload(); + const embeddable = embeddablesRegistry[uniqueId]; + + if ('updateInput' in embeddable) { + embeddable.updateInput(input); + embeddable.reload(); + } } }, });