2023-09-12 14:14:02 +00:00
|
|
|
import { useSelector } from "react-redux";
|
2023-10-04 08:54:16 +00:00
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
2023-09-12 14:14:02 +00:00
|
|
|
|
|
|
|
|
export enum LayoutSystemFeatures {
|
2023-10-20 06:15:16 +00:00
|
|
|
ENABLE_MAIN_CONTAINER_RESIZER = "ENABLE_MAIN_CONTAINER_RESIZER",
|
|
|
|
|
ENABLE_FORKING_FROM_TEMPLATES = "ENABLE_FORKING_FROM_TEMPLATES",
|
|
|
|
|
ENABLE_CANVAS_LAYOUT_CONTROL = "ENABLE_CANVAS_LAYOUT_CONTROL",
|
|
|
|
|
ENABLE_CANVAS_OVERLAY_FOR_EDITOR_UI = "ENABLE_CANVAS_OVERLAY_FOR_EDITOR_UI",
|
2023-10-25 05:40:43 +00:00
|
|
|
ENABLE_LAYOUT_CONVERSION = "ENABLE_LAYOUT_CONVERSION",
|
2024-03-06 07:29:44 +00:00
|
|
|
ENABLE_GENERATE_CRUD_APP = "ENABLE_GENERATE_CRUD_APP",
|
2023-09-12 14:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-18 13:39:07 +00:00
|
|
|
const FIXED_LAYOUT_FEATURES: Record<LayoutSystemFeatures, boolean> = {
|
2023-09-12 14:14:02 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_FORKING_FROM_TEMPLATES]: true,
|
|
|
|
|
[LayoutSystemFeatures.ENABLE_CANVAS_LAYOUT_CONTROL]: true,
|
2023-10-18 13:39:07 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_MAIN_CONTAINER_RESIZER]: false,
|
2023-10-20 06:15:16 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_CANVAS_OVERLAY_FOR_EDITOR_UI]: false,
|
2023-10-25 05:40:43 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_LAYOUT_CONVERSION]: true,
|
2024-03-06 07:29:44 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_GENERATE_CRUD_APP]: true,
|
2023-10-18 13:39:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AUTO_LAYOUT_FEATURES: Record<LayoutSystemFeatures, boolean> = {
|
|
|
|
|
[LayoutSystemFeatures.ENABLE_FORKING_FROM_TEMPLATES]: false,
|
|
|
|
|
[LayoutSystemFeatures.ENABLE_CANVAS_LAYOUT_CONTROL]: false,
|
|
|
|
|
[LayoutSystemFeatures.ENABLE_MAIN_CONTAINER_RESIZER]: true,
|
2023-10-20 06:15:16 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_CANVAS_OVERLAY_FOR_EDITOR_UI]: false,
|
2023-10-25 05:40:43 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_LAYOUT_CONVERSION]: true,
|
2024-03-06 07:29:44 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_GENERATE_CRUD_APP]: true,
|
2023-10-18 13:39:07 +00:00
|
|
|
};
|
2023-09-12 14:14:02 +00:00
|
|
|
|
2023-10-18 13:39:07 +00:00
|
|
|
const ANVIL_FEATURES: Record<LayoutSystemFeatures, boolean> = {
|
|
|
|
|
[LayoutSystemFeatures.ENABLE_FORKING_FROM_TEMPLATES]: false,
|
|
|
|
|
[LayoutSystemFeatures.ENABLE_CANVAS_LAYOUT_CONTROL]: false,
|
2023-09-12 14:14:02 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_MAIN_CONTAINER_RESIZER]: true,
|
2023-10-20 06:15:16 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_CANVAS_OVERLAY_FOR_EDITOR_UI]: true,
|
2023-10-25 05:40:43 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_LAYOUT_CONVERSION]: false,
|
2024-03-06 07:29:44 +00:00
|
|
|
[LayoutSystemFeatures.ENABLE_GENERATE_CRUD_APP]: false,
|
2023-10-18 13:39:07 +00:00
|
|
|
};
|
2023-09-12 14:14:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This Hook is mainly written to be used as a central control to enable
|
|
|
|
|
* layout specific features based on the type of current layout.
|
|
|
|
|
* This way the components using it need not be aware of what layout it is on
|
|
|
|
|
*
|
|
|
|
|
* @returns This hook returns a method, which can be used to get a boolean corresponding to the feature supplied as argument.
|
|
|
|
|
* The boolean will indicate if the feature is enabled for the current layout
|
|
|
|
|
*/
|
|
|
|
|
export const useLayoutSystemFeatures = () => {
|
2023-10-04 08:54:16 +00:00
|
|
|
const layoutSystemType = useSelector(getLayoutSystemType);
|
2023-09-12 14:14:02 +00:00
|
|
|
|
|
|
|
|
let currentFeatureSet = {} as Record<LayoutSystemFeatures, boolean>;
|
|
|
|
|
|
2023-10-04 08:54:16 +00:00
|
|
|
switch (layoutSystemType) {
|
|
|
|
|
case LayoutSystemTypes.FIXED:
|
2023-09-12 14:14:02 +00:00
|
|
|
currentFeatureSet = FIXED_LAYOUT_FEATURES;
|
|
|
|
|
break;
|
2023-10-04 08:54:16 +00:00
|
|
|
case LayoutSystemTypes.AUTO:
|
2023-09-12 14:14:02 +00:00
|
|
|
currentFeatureSet = AUTO_LAYOUT_FEATURES;
|
|
|
|
|
break;
|
2023-10-18 13:39:07 +00:00
|
|
|
case LayoutSystemTypes.ANVIL:
|
|
|
|
|
currentFeatureSet = ANVIL_FEATURES;
|
|
|
|
|
break;
|
2023-09-12 14:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method checks if the features requested in the method,
|
|
|
|
|
* can be enabled for the given particular layout type
|
|
|
|
|
*/
|
|
|
|
|
return (checkFeaturesArray: LayoutSystemFeatures[]) => {
|
|
|
|
|
const featuresArray: boolean[] = [];
|
|
|
|
|
|
|
|
|
|
for (const checkFeature of checkFeaturesArray) {
|
|
|
|
|
featuresArray.push(!!currentFeatureSet[checkFeature]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return featuresArray;
|
|
|
|
|
};
|
|
|
|
|
};
|