PromucFlow_constructor/app/client/src/selectors/layoutSystemSelectors.ts
Ashok Kumar M 7b527c9024
chore: Merge wds and anvil feature flags (#32609)
[![workerB](https://img.shields.io/endpoint?url=https%3A%2F%2Fworkerb.linearb.io%2Fv2%2Fbadge%2Fprivate%2FU2FsdGVkX1LNwrMHgs05enX0VDk8QxZH7uP7Ii4HE%2Fcollaboration.svg%3FcacheSeconds%3D60)](https://workerb.linearb.io/v2/badge/collaboration-page?magicLinkId=M7zehz4)
## Description

Cleaning up three patterns of checks to enable wds and anvil into two.
wds and anvil had to have different flags coz anvil had to play catch up
with wds, now that's not the case so it does not make sense to have two
flags.

Old patterns
- checking if the wds feature flag is enabled
- checking if the anvil feature flag is enabled
- checking if the layout system of the app is anvil

New Pattern
- checking if anvil feature flag is enabled (used only for creating an
anvil app)
- checking if layout system of the app is anvil

Fixes #32590
_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/8663918496>
> Commit: e10cc2a84ed680b29c49c5b2e8175df4c18da2f8
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8663918496&attempt=1"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->

















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

- **Refactor**
- Consolidated the usage of layout system checks across the application
to use a unified Anvil layout selector, enhancing consistency in
layout-related conditional logic.
- **Bug Fixes**
- Removed outdated feature flags related to the Anvil + WDS integration,
ensuring the application's feature toggling aligns with the current
development strategy.
- **Tests**
- Updated unit tests to align with the new method of layout system
determination, ensuring test environments accurately reflect production
behavior.
- **Chores**
- Cleaned up redundant code and feature flags that are no longer in use,
simplifying the codebase and reducing potential for errors.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-04-12 22:54:04 +05:30

50 lines
1.7 KiB
TypeScript

import type { AppState } from "@appsmith/reducers";
import { getIsAnvilLayoutEnabled } from "layoutSystems/anvil/integrations/selectors";
import { getAnvilWidgetDOMId } from "layoutSystems/common/utils/LayoutElementPositionsObserver/utils";
import { LayoutSystemTypes } from "layoutSystems/types";
/**
* Returns the layout system type based on the state of the application.
* @param state - The current state of the application.
* @returns The layout system type.
*/
export const getLayoutSystemType = (state: AppState) => {
// Check if the application has a defined appPositioning type
if (
state.ui.applications?.currentApplication?.applicationDetail?.appPositioning
?.type
) {
// Get the layout system type based on the appPositioning type
const layoutSystemType =
LayoutSystemTypes[
state.ui.applications.currentApplication?.applicationDetail
?.appPositioning?.type
];
// If the layout system type is not ANVIL, return it
if (layoutSystemType !== LayoutSystemTypes.ANVIL) {
return layoutSystemType;
}
// Check if the ANVIL layout system is enabled
const isAnvilEnabled = getIsAnvilLayoutEnabled(state);
// If ANVIL is enabled, return ANVIL as the layout system type
if (isAnvilEnabled) {
return LayoutSystemTypes.ANVIL;
}
}
// If no layout system type is found, return FIXED as the default layout system type
return LayoutSystemTypes.FIXED;
};
export const getWidgetSelectorByWidgetId = (
state: AppState,
widgetId: string,
) => {
const layoutSystemType = getLayoutSystemType(state);
switch (layoutSystemType) {
case LayoutSystemTypes.ANVIL:
return getAnvilWidgetDOMId(widgetId);
default:
return widgetId;
}
};