PromucFlow_constructor/app/client/test/factories/WidgetFactoryUtils.ts
Vemparala Surya Vamsi b122c8195f
chore: decouple widget-config.json from main chunk (#36924)
## Description
We decoupled the widget-config.json file (177KB when zipped) from the
main bundle and implemented lazy loading during DSL migrations. This
optimisation reduces the size of the main chunk by 10%, which should
lead to better performance, specifically improving FCP and LCP, as the
main chunk's fetch and evaluation times are reduced

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11384816747>
> Commit: ae14b3f40c4c1ef77250157e56aed97acae5cbaf
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11384816747&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Thu, 17 Oct 2024 15:04:34 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Enhanced migration logic for DSL widgets with asynchronous operations.
	- Improved performance with lazy loading of widget configurations.
	- Added optional properties to page response data structures.

- **Bug Fixes**
	- Resolved issues with dynamic binding path migrations.

- **Tests**
- Updated test cases to handle asynchronous operations for better
reliability and accuracy.

- **Chores**
- Improved type safety and error handling in widget factory utilities
and mock functions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-10-17 20:48:39 +05:30

41 lines
1.3 KiB
TypeScript

import { makeFactory } from "factory.ts";
import type { WidgetProps } from "widgets/BaseWidget";
import type { DSLWidget } from "WidgetProvider/constants";
import defaultTemplate from "templates/default";
import { WidgetTypeFactories } from "./Widgets/WidgetTypeFactories";
const defaultMainContainer: DSLWidget = {
...(defaultTemplate as unknown as DSLWidget),
canExtend: true,
renderMode: "PAGE",
version: 1,
isLoading: false,
} as DSLWidget;
export const mainContainerFactory = makeFactory({ ...defaultMainContainer });
export const widgetCanvasFactory = makeFactory(mainContainerFactory.build());
const buildChild = (child: Partial<WidgetProps>): WidgetProps => {
return WidgetTypeFactories[child.type || "CANVAS_WIDGET"].build({
...child,
});
};
export const buildChildren = (children: Partial<WidgetProps>[]) => {
try {
return children.map((child) => {
return buildChild(child);
});
} catch (error) {
// eslint-disable-next-line no-console
console.error("Check if child widget data provided");
}
};
export const buildDslWithChildren = (childData: Partial<WidgetProps>[]) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const children: any = buildChildren(childData);
return widgetCanvasFactory.build({
children,
});
};