PromucFlow_constructor/app/client/src/utils/hooks/useCanvasMinHeightUpdateHook.ts
Sangeeth Sivan e9d719103c
chore: code split sagas and reducer's index file (#16261)
* chore: code split sagas and reducers index file

* fix: update imports

* chore: remove acl reducers file on ce

* fix: code split reducers properly

* chore: remove unnecessary import

* chore: split root sagas file
2022-08-24 17:46:32 +05:30

32 lines
1.1 KiB
TypeScript

import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import { AppState } from "@appsmith/reducers";
import { APP_MODE } from "entities/App";
import { getWidget } from "sagas/selectors";
import { getAppMode } from "selectors/applicationSelectors";
import { useSelector } from "store";
import { updateWidgetMetaPropAndEval } from "actions/metaActions";
import WidgetFactory from "utils/WidgetFactory";
const WidgetTypes = WidgetFactory.widgetTypes;
export const useCanvasMinHeightUpdateHook = (
widgetId: string,
minHeight = 0,
) => {
const widget = useSelector((state: AppState) => getWidget(state, widgetId));
const dispatch = useDispatch();
const appMode = useSelector(getAppMode);
const canUpdateWidgetMinHeight =
appMode === APP_MODE.EDIT &&
widgetId !== MAIN_CONTAINER_WIDGET_ID &&
widget &&
widget.type === WidgetTypes.CANVAS_WIDGET;
useEffect(() => {
if (canUpdateWidgetMinHeight && widget.minHeight !== minHeight) {
dispatch(updateWidgetMetaPropAndEval(widgetId, "minHeight", minHeight));
}
}, [minHeight]);
};