2023-10-04 08:54:16 +00:00
|
|
|
import type { AppState } from "@appsmith/reducers";
|
2024-04-12 17:24:04 +00:00
|
|
|
import { getIsAnvilLayoutEnabled } from "layoutSystems/anvil/integrations/selectors";
|
2024-02-27 04:41:55 +00:00
|
|
|
import { getAnvilWidgetDOMId } from "layoutSystems/common/utils/LayoutElementPositionsObserver/utils";
|
2023-10-04 08:54:16 +00:00
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
|
|
|
|
|
/**
|
2024-04-12 17:24:04 +00:00
|
|
|
* 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.
|
2023-10-04 08:54:16 +00:00
|
|
|
*/
|
|
|
|
|
export const getLayoutSystemType = (state: AppState) => {
|
2024-04-12 17:24:04 +00:00
|
|
|
// Check if the application has a defined appPositioning type
|
2023-10-04 08:54:16 +00:00
|
|
|
if (
|
|
|
|
|
state.ui.applications?.currentApplication?.applicationDetail?.appPositioning
|
|
|
|
|
?.type
|
|
|
|
|
) {
|
2024-04-12 17:24:04 +00:00
|
|
|
// 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;
|
|
|
|
|
}
|
2023-10-04 08:54:16 +00:00
|
|
|
}
|
2024-04-12 17:24:04 +00:00
|
|
|
// If no layout system type is found, return FIXED as the default layout system type
|
2023-10-04 08:54:16 +00:00
|
|
|
return LayoutSystemTypes.FIXED;
|
|
|
|
|
};
|
2024-02-27 04:41:55 +00:00
|
|
|
|
|
|
|
|
export const getWidgetSelectorByWidgetId = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
widgetId: string,
|
|
|
|
|
) => {
|
|
|
|
|
const layoutSystemType = getLayoutSystemType(state);
|
|
|
|
|
switch (layoutSystemType) {
|
|
|
|
|
case LayoutSystemTypes.ANVIL:
|
|
|
|
|
return getAnvilWidgetDOMId(widgetId);
|
|
|
|
|
default:
|
|
|
|
|
return widgetId;
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-04-16 08:41:09 +00:00
|
|
|
|
|
|
|
|
export const isFixedLayoutSelector = (state: AppState) =>
|
|
|
|
|
getLayoutSystemType(state) === LayoutSystemTypes.FIXED;
|