[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>
This commit is contained in:
Corey Robertson 2021-08-25 14:42:45 -04:00 committed by GitHub
parent 0897999f91
commit 0a7b8cad18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) => {
@ -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();
}
}
},
});