2021-09-09 15:10:22 +00:00
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
2021-06-28 07:11:47 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useDispatch } from "react-redux";
|
2022-08-24 12:16:32 +00:00
|
|
|
import { AppState } from "@appsmith/reducers";
|
2021-08-06 09:17:56 +00:00
|
|
|
import { APP_MODE } from "entities/App";
|
2021-06-28 07:11:47 +00:00
|
|
|
import { getWidget } from "sagas/selectors";
|
2021-07-14 16:30:10 +00:00
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
2022-11-28 08:13:17 +00:00
|
|
|
import { useSelector } from "react-redux";
|
2022-05-25 09:46:14 +00:00
|
|
|
import { updateWidgetMetaPropAndEval } from "actions/metaActions";
|
2021-09-09 15:10:22 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2021-06-28 07:11:47 +00:00
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
const WidgetTypes = WidgetFactory.widgetTypes;
|
|
|
|
|
|
2021-06-28 07:11:47 +00:00
|
|
|
export const useCanvasMinHeightUpdateHook = (
|
|
|
|
|
widgetId: string,
|
|
|
|
|
minHeight = 0,
|
|
|
|
|
) => {
|
|
|
|
|
const widget = useSelector((state: AppState) => getWidget(state, widgetId));
|
|
|
|
|
const dispatch = useDispatch();
|
2021-07-14 16:30:10 +00:00
|
|
|
const appMode = useSelector(getAppMode);
|
|
|
|
|
const canUpdateWidgetMinHeight =
|
|
|
|
|
appMode === APP_MODE.EDIT &&
|
|
|
|
|
widgetId !== MAIN_CONTAINER_WIDGET_ID &&
|
|
|
|
|
widget &&
|
|
|
|
|
widget.type === WidgetTypes.CANVAS_WIDGET;
|
2021-06-28 07:11:47 +00:00
|
|
|
useEffect(() => {
|
2021-07-14 16:30:10 +00:00
|
|
|
if (canUpdateWidgetMinHeight && widget.minHeight !== minHeight) {
|
2022-05-25 09:46:14 +00:00
|
|
|
dispatch(updateWidgetMetaPropAndEval(widgetId, "minHeight", minHeight));
|
2021-06-28 07:11:47 +00:00
|
|
|
}
|
|
|
|
|
}, [minHeight]);
|
|
|
|
|
};
|