[ML] Fix Change Point embeddable infinite re-rendering on a dashboard (#184711)

## Summary

Closes https://github.com/elastic/kibana/issues/184710

Fixes embeddable rendering by preserving callback refs and memoizing
component props.
This commit is contained in:
Dima Arnautov 2024-06-04 16:23:42 +02:00 committed by GitHub
parent 9c9065d52b
commit 88833a5c76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -188,6 +188,10 @@ export const getChangePointChartEmbeddableFactory = (
pluginStart
);
const onLoading = (v: boolean) => dataLoading.next(v);
const onRenderComplete = () => dataLoading.next(false);
const onError = (error: Error) => blockingError.next(error);
return {
api,
Component: () => {
@ -242,9 +246,9 @@ export const getChangePointChartEmbeddableFactory = (
maxSeriesToPlot={maxSeriesToPlot}
dataViewId={dataViewId}
partitions={partitions}
onLoading={(v) => dataLoading.next(v)}
onRenderComplete={() => dataLoading.next(false)}
onError={(error) => blockingError.next(error)}
onLoading={onLoading}
onRenderComplete={onRenderComplete}
onError={onError}
embeddingOrigin={embeddingOrigin}
lastReloadRequestTime={lastReloadRequestTime}
/>

View file

@ -17,9 +17,9 @@ export const getChangePointDetectionComponent = (
coreStart: CoreStart,
pluginStart: AiopsPluginStartDeps
): ChangePointDetectionSharedComponent => {
return (props) => {
return React.memo((props) => {
return <ChangePointDetectionLazy coreStart={coreStart} pluginStart={pluginStart} {...props} />;
};
});
};
export type { ChangePointDetectionSharedComponent } from './change_point_detection';