Skip to content

Commit

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

* WIP

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Corey Robertson <[email protected]>
  • Loading branch information
kibanamachine and Corey Robertson authored Mar 4, 2021
1 parent 961af39 commit 7088fa9
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 7088fa9

Please sign in to comment.