PromucFlow_constructor/app/client/src/layoutSystems/anvil/utils/anvilChecksUtils.ts
Ilia 26e1c88a7b
chore: move anvil widgets to wds (#35812)
## Description
- Moved Section and Zone widgets to wds folder

Fixes #35810

> [!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/10511698329>
> Commit: 67868d550cebe7b2393803c805132b548c6f1046
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10511698329&attempt=3"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Thu, 22 Aug 2024 18:06:57 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

## Summary by CodeRabbit

- **New Features**
- Introduced new `WDSSectionWidget` and `WDSZoneWidget` components,
reflecting a new namespace for widget organization.
- Added new constants and an enumeration for widget configuration in the
`wds/constants` module.

- **Improvements**
- Updated import paths for various constants and components to
streamline the codebase organization.

- **Collaboration Enhancements**
- Updated ownership in the `CODEOWNERS` file to include both the
`@appsmithorg/wds-team` and `@appsmithorg/anvil-team` for better
collaboration on widget development.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-22 20:18:20 +02:00

87 lines
2.9 KiB
TypeScript

import { call, put, select } from "redux-saga/effects";
import { updateAndSaveLayout } from "actions/pageActions";
import { updateAnvilParentPostWidgetDeletion } from "layoutSystems/anvil/utils/layouts/update/deletionUtils";
import type { FlattenedWidgetProps } from "WidgetProvider/constants";
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
import type { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
import { anvilWidgets } from "widgets/wds/constants";
import {
updateSectionWithDefaultSpaceDistribution,
updateSectionsDistributedSpace,
} from "layoutSystems/anvil/sectionSpaceDistributor/utils/spaceRedistributionSagaUtils";
import { getIsAnvilLayout } from "../integrations/selectors";
export function* updateAndSaveAnvilLayout(
widgets: CanvasWidgetsReduxState,
options?: { isRetry: boolean; shouldReplay: boolean },
) {
const isAnvilLayout: boolean = yield select(getIsAnvilLayout);
if (!isAnvilLayout || !widgets) {
yield put(updateAndSaveLayout(widgets, options));
return;
}
let updatedWidgets: CanvasWidgetsReduxState = { ...widgets };
/**
* Extract all section widgets
*/
const sections: FlattenedWidgetProps[] = Object.values(widgets).filter(
(each: FlattenedWidgetProps) => each.type === anvilWidgets.SECTION_WIDGET,
);
for (const each of sections) {
const children: string[] | undefined = each.children;
/**
* If a section doesn't have any children,
* => delete it.
*/
if (!children || !children?.length) {
let parent: FlattenedWidgetProps =
updatedWidgets[each.parentId || MAIN_CONTAINER_WIDGET_ID];
if (parent) {
parent = {
...parent,
children: parent.children?.filter(
(id: string) => id !== each.widgetId,
),
};
delete updatedWidgets[each.widgetId];
updatedWidgets = updateAnvilParentPostWidgetDeletion(
{ ...updatedWidgets, [parent.widgetId]: parent },
parent.widgetId,
each.widgetId,
each.type,
);
}
} else if (each.zoneCount !== each.children?.length) {
// update the section with the new space distribution
updatedWidgets = yield call(
updateSectionsDistributedSpace,
updatedWidgets,
each,
);
/**
* If section's zone count doesn't match it's child count,
* => update the zone count.
*/
updatedWidgets = {
...updatedWidgets,
[each.widgetId]: {
...updatedWidgets[each.widgetId],
zoneCount: each.children?.length,
},
};
} else if (!each.spaceDistributed) {
// update the section with the default space distribution
updatedWidgets = yield call(
updateSectionWithDefaultSpaceDistribution,
updatedWidgets,
each,
);
}
}
yield put(updateAndSaveLayout(updatedWidgets, options));
}