Skip to content

Commit

Permalink
[Canvas] Fix reports embeddables (#93482)
Browse files Browse the repository at this point in the history
* wip

* WIP

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
Corey Robertson and kibanamachine committed Mar 4, 2021
1 parent 32e1a52 commit 5f8524f
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CANVAS_EMBEDDABLE_CLASSNAME } from '../../../common/lib';
const { embeddable: strings } = RendererStrings;

const embeddablesRegistry: {
[key: string]: IEmbeddable;
[key: string]: IEmbeddable | Promise<IEmbeddable>;
} = {};

const renderEmbeddableFactory = (core: CoreStart, plugins: StartDeps) => {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
}
},
});
Expand Down

0 comments on commit 5f8524f

Please sign in to comment.