2021-05-27 06:41:38 +00:00
|
|
|
import { get } from "lodash";
|
2021-06-17 13:26:54 +00:00
|
|
|
import { useShowPropertyPane } from "utils/hooks/dragResizeHooks";
|
2021-03-29 15:47:22 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentWidgetId,
|
|
|
|
|
getIsPropertyPaneVisible,
|
|
|
|
|
} from "selectors/propertyPaneSelectors";
|
2021-07-20 05:18:58 +00:00
|
|
|
import { getIsTableFilterPaneVisible } from "selectors/tableFilterSelectors";
|
2021-05-27 06:41:38 +00:00
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
2021-03-29 15:47:22 +00:00
|
|
|
import { useSelector } from "store";
|
|
|
|
|
import { AppState } from "reducers";
|
2021-05-27 06:41:38 +00:00
|
|
|
import { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
|
2021-08-06 09:17:56 +00:00
|
|
|
import { APP_MODE } from "entities/App";
|
2021-03-29 15:47:22 +00:00
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
2021-05-27 06:41:38 +00:00
|
|
|
import { getWidgets } from "sagas/selectors";
|
2021-06-17 13:26:54 +00:00
|
|
|
import { useWidgetSelection } from "./useWidgetSelection";
|
2021-08-12 05:45:38 +00:00
|
|
|
import React, { ReactNode, useCallback } from "react";
|
|
|
|
|
import { stopEventPropagation } from "utils/AppsmithUtils";
|
2021-05-27 06:41:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param widgetId
|
|
|
|
|
* @param widgets
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export function getParentToOpenIfAny(
|
|
|
|
|
widgetId: string | undefined,
|
|
|
|
|
widgets: CanvasWidgetsReduxState,
|
|
|
|
|
) {
|
|
|
|
|
if (widgetId) {
|
|
|
|
|
let widget = get(widgets, widgetId, undefined);
|
|
|
|
|
|
|
|
|
|
// While this widget has a openParentPropertyPane equql to true
|
|
|
|
|
while (widget?.openParentPropertyPane) {
|
|
|
|
|
// Get parent widget props
|
|
|
|
|
const parent = get(widgets, `${widget.parentId}`, undefined);
|
|
|
|
|
|
|
|
|
|
// If parent has openParentPropertyPane = false, return the currnet parent
|
|
|
|
|
if (!parent?.openParentPropertyPane) {
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parent?.parentId && parent.parentId !== MAIN_CONTAINER_WIDGET_ID) {
|
|
|
|
|
widget = get(widgets, `${widget.parentId}`, undefined);
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-29 15:47:22 +00:00
|
|
|
|
2021-08-12 05:45:38 +00:00
|
|
|
export function ClickContentToOpenPropPane({
|
|
|
|
|
children,
|
|
|
|
|
widgetId,
|
|
|
|
|
}: {
|
|
|
|
|
widgetId: string;
|
|
|
|
|
children?: ReactNode;
|
|
|
|
|
}) {
|
|
|
|
|
const { focusWidget } = useWidgetSelection();
|
|
|
|
|
|
|
|
|
|
const openPropertyPane = useClickOpenPropPane();
|
|
|
|
|
const openPropPane = useCallback(
|
|
|
|
|
(e) => {
|
|
|
|
|
openPropertyPane(e, widgetId);
|
|
|
|
|
},
|
|
|
|
|
[widgetId, openPropertyPane],
|
|
|
|
|
);
|
|
|
|
|
const focusedWidget = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.focusedWidget,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const isResizing = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isResizing,
|
|
|
|
|
);
|
|
|
|
|
const isDragging = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
|
|
|
);
|
|
|
|
|
const isResizingOrDragging = !!isResizing || !!isDragging;
|
|
|
|
|
const handleMouseOver = (e: any) => {
|
|
|
|
|
focusWidget &&
|
|
|
|
|
!isResizingOrDragging &&
|
|
|
|
|
focusedWidget !== widgetId &&
|
|
|
|
|
focusWidget(widgetId);
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
onClick={stopEventPropagation}
|
|
|
|
|
onClickCapture={openPropPane}
|
|
|
|
|
onMouseOver={handleMouseOver}
|
|
|
|
|
style={{
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 15:47:22 +00:00
|
|
|
export const useClickOpenPropPane = () => {
|
|
|
|
|
const showPropertyPane = useShowPropertyPane();
|
2021-05-27 06:41:38 +00:00
|
|
|
const { focusWidget, selectWidget } = useWidgetSelection();
|
2021-03-29 15:47:22 +00:00
|
|
|
const isPropPaneVisible = useSelector(getIsPropertyPaneVisible);
|
2021-07-20 05:18:58 +00:00
|
|
|
const isTableFilterPaneVisible = useSelector(getIsTableFilterPaneVisible);
|
2021-05-27 06:41:38 +00:00
|
|
|
const widgets: CanvasWidgetsReduxState = useSelector(getWidgets);
|
2021-03-29 15:47:22 +00:00
|
|
|
const selectedWidgetId = useSelector(getCurrentWidgetId);
|
2021-05-27 06:41:38 +00:00
|
|
|
const focusedWidgetId = useSelector(
|
2021-03-29 15:47:22 +00:00
|
|
|
(state: AppState) => state.ui.widgetDragResize.focusedWidget,
|
|
|
|
|
);
|
|
|
|
|
// This state tells us whether a `ResizableComponent` is resizing
|
|
|
|
|
const isResizing = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isResizing,
|
|
|
|
|
);
|
|
|
|
|
const appMode = useSelector(getAppMode);
|
|
|
|
|
|
|
|
|
|
// This state tells us whether a `DraggableComponent` is dragging
|
|
|
|
|
const isDragging = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
|
|
|
);
|
2021-05-27 06:41:38 +00:00
|
|
|
|
|
|
|
|
const parentWidgetToOpen = getParentToOpenIfAny(focusedWidgetId, widgets);
|
2021-05-18 18:29:39 +00:00
|
|
|
const openPropertyPane = (e: any, targetWidgetId: string) => {
|
2021-07-20 05:18:58 +00:00
|
|
|
// ignore click captures
|
|
|
|
|
// 1. if the component was resizing or dragging coz it is handled internally in draggable component
|
|
|
|
|
// 2. table filter property pane is open
|
2021-05-18 18:29:39 +00:00
|
|
|
if (
|
|
|
|
|
isResizing ||
|
|
|
|
|
isDragging ||
|
|
|
|
|
appMode !== APP_MODE.EDIT ||
|
2021-07-20 05:18:58 +00:00
|
|
|
targetWidgetId !== focusedWidgetId ||
|
|
|
|
|
isTableFilterPaneVisible
|
2021-05-18 18:29:39 +00:00
|
|
|
)
|
|
|
|
|
return;
|
2021-03-29 15:47:22 +00:00
|
|
|
if (
|
2021-05-27 06:41:38 +00:00
|
|
|
(!isPropPaneVisible && selectedWidgetId === focusedWidgetId) ||
|
|
|
|
|
selectedWidgetId !== focusedWidgetId
|
2021-03-29 15:47:22 +00:00
|
|
|
) {
|
2021-06-17 13:26:54 +00:00
|
|
|
const isMultiSelect = e.metaKey || e.ctrlKey || e.shiftKey;
|
2021-05-27 06:41:38 +00:00
|
|
|
|
|
|
|
|
if (parentWidgetToOpen) {
|
2021-06-17 13:26:54 +00:00
|
|
|
selectWidget(parentWidgetToOpen.widgetId, isMultiSelect);
|
2021-07-08 06:30:19 +00:00
|
|
|
!isMultiSelect &&
|
|
|
|
|
showPropertyPane(parentWidgetToOpen.widgetId, undefined, true);
|
2021-05-27 06:41:38 +00:00
|
|
|
} else {
|
2021-06-17 13:26:54 +00:00
|
|
|
selectWidget(focusedWidgetId, isMultiSelect);
|
2021-05-27 06:41:38 +00:00
|
|
|
focusWidget(focusedWidgetId);
|
2021-07-08 06:30:19 +00:00
|
|
|
!isMultiSelect && showPropertyPane(focusedWidgetId, undefined, true);
|
2021-05-27 06:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-05-18 18:29:39 +00:00
|
|
|
if (isMultiSelect) {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
}
|
2021-03-29 15:47:22 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return openPropertyPane;
|
|
|
|
|
};
|