2024-08-06 14:52:22 +00:00
|
|
|
import type { AppState } from "ee/reducers";
|
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-07-05 08:27:59 +00:00
|
|
|
const applicationLayoutSystemType =
|
2023-10-04 08:54:16 +00:00
|
|
|
state.ui.applications?.currentApplication?.applicationDetail?.appPositioning
|
2024-07-05 08:27:59 +00:00
|
|
|
?.type;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-05 08:27:59 +00:00
|
|
|
// Check if the application has a defined appPositioning type
|
|
|
|
|
if (applicationLayoutSystemType) {
|
2024-04-12 17:24:04 +00:00
|
|
|
// Get the layout system type based on the appPositioning type
|
2024-07-05 08:27:59 +00:00
|
|
|
const layoutSystemType = LayoutSystemTypes[applicationLayoutSystemType];
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-07-05 08:27:59 +00:00
|
|
|
return layoutSystemType;
|
2023-10-04 08:54:16 +00:00
|
|
|
}
|
2024-09-18 16:35:28 +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);
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-02-27 04:41:55 +00:00
|
|
|
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;
|