2023-09-06 12:15:04 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import type { CanvasWidgetStructure } from "WidgetProvider/constants";
|
|
|
|
|
import type BaseWidget from "widgets/BaseWidget";
|
|
|
|
|
import WidgetFactory from ".";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { withBaseWidgetHOC } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
|
2023-09-06 12:15:04 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function to create builder for the widgets and register them in widget factory
|
|
|
|
|
* Note: Ideally we should do this on the widfactory itself. but introducing the withMeta
|
|
|
|
|
* HOC in the widget factory file leads to the circular dependency hence we have
|
|
|
|
|
* extracted this into a seperate file to break the circular reference.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
export const registerWidgets = (widgets: (typeof BaseWidget)[]) => {
|
|
|
|
|
const widgetAndBuilders = widgets.map((widget) => {
|
2023-09-11 15:55:11 +00:00
|
|
|
const { eagerRender = false, needsMeta = false } = widget.getConfig();
|
2023-09-06 12:15:04 +00:00
|
|
|
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-09-11 15:55:11 +00:00
|
|
|
const ProfiledWidget: any = withBaseWidgetHOC(
|
|
|
|
|
widget,
|
|
|
|
|
needsMeta,
|
|
|
|
|
eagerRender,
|
|
|
|
|
);
|
2023-09-06 12:15:04 +00:00
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
widget,
|
|
|
|
|
(widgetProps: CanvasWidgetStructure) => (
|
|
|
|
|
<ProfiledWidget {...widgetProps} key={widgetProps.widgetId} />
|
|
|
|
|
),
|
|
|
|
|
] as [
|
|
|
|
|
typeof BaseWidget,
|
|
|
|
|
(widgetProps: CanvasWidgetStructure) => React.ReactNode,
|
|
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
WidgetFactory.initialize(widgetAndBuilders);
|
|
|
|
|
};
|