2020-03-27 09:02:11 +00:00
|
|
|
import { createSelector } from "reselect";
|
2022-08-24 12:16:32 +00:00
|
|
|
import { AppState } from "@appsmith/reducers";
|
2022-09-14 06:55:08 +00:00
|
|
|
import {
|
|
|
|
|
CanvasWidgetsReduxState,
|
|
|
|
|
FlattenedWidgetProps,
|
|
|
|
|
} from "reducers/entityReducers/canvasWidgetsReducer";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { getExistingWidgetNames } from "sagas/selectors";
|
2020-04-03 09:32:13 +00:00
|
|
|
import { getNextEntityName } from "utils/AppsmithUtils";
|
2020-03-27 09:02:11 +00:00
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2022-09-15 05:44:11 +00:00
|
|
|
import {
|
|
|
|
|
getFocusedWidget,
|
|
|
|
|
getLastSelectedWidget,
|
|
|
|
|
getSelectedWidgets,
|
|
|
|
|
} from "./ui";
|
2022-09-14 06:55:08 +00:00
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
|
|
|
|
import { get } from "lodash";
|
|
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
|
|
|
|
import { APP_MODE } from "entities/App";
|
|
|
|
|
import { getIsTableFilterPaneVisible } from "selectors/tableFilterSelectors";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
2022-05-15 13:12:07 +00:00
|
|
|
export const getIsDraggingOrResizing = (state: AppState) =>
|
|
|
|
|
state.ui.widgetDragResize.isResizing || state.ui.widgetDragResize.isDragging;
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
export const getIsResizing = (state: AppState) =>
|
|
|
|
|
state.ui.widgetDragResize.isResizing;
|
|
|
|
|
|
2020-03-27 09:02:11 +00:00
|
|
|
const getCanvasWidgets = (state: AppState) => state.entities.canvasWidgets;
|
|
|
|
|
export const getModalDropdownList = createSelector(
|
|
|
|
|
getCanvasWidgets,
|
2020-12-24 04:32:25 +00:00
|
|
|
(widgets) => {
|
2020-03-27 09:02:11 +00:00
|
|
|
const modalWidgets = Object.values(widgets).filter(
|
2021-09-09 15:10:22 +00:00
|
|
|
(widget: FlattenedWidgetProps) => widget.type === "MODAL_WIDGET",
|
2020-03-27 09:02:11 +00:00
|
|
|
);
|
|
|
|
|
if (modalWidgets.length === 0) return undefined;
|
|
|
|
|
|
|
|
|
|
return modalWidgets.map((widget: FlattenedWidgetProps) => ({
|
|
|
|
|
id: widget.widgetId,
|
|
|
|
|
label: widget.widgetName,
|
2020-04-20 05:42:46 +00:00
|
|
|
value: `${widget.widgetName}`,
|
2020-03-27 09:02:11 +00:00
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-04-03 09:32:13 +00:00
|
|
|
|
|
|
|
|
export const getNextModalName = createSelector(
|
|
|
|
|
getExistingWidgetNames,
|
2021-09-09 15:10:22 +00:00
|
|
|
(names) => {
|
|
|
|
|
const prefix =
|
|
|
|
|
WidgetFactory.widgetConfigMap.get("MODAL_WIDGET")?.widgetName || "";
|
|
|
|
|
return getNextEntityName(prefix, names);
|
|
|
|
|
},
|
2020-04-03 09:32:13 +00:00
|
|
|
);
|
2022-02-09 11:41:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Selector to get the parent widget of a particaular widget with id as a prop
|
|
|
|
|
*/
|
|
|
|
|
export const getParentWidget = createSelector(
|
|
|
|
|
getCanvasWidgets,
|
|
|
|
|
(state: AppState, widgetId: string) => widgetId,
|
|
|
|
|
(canvasWidgets, widgetId: string): FlattenedWidgetProps | undefined => {
|
|
|
|
|
if (canvasWidgets.hasOwnProperty(widgetId)) {
|
|
|
|
|
const widget = canvasWidgets[widgetId];
|
|
|
|
|
if (widget.parentId && canvasWidgets.hasOwnProperty(widget.parentId)) {
|
|
|
|
|
const parent = canvasWidgets[widget.parentId];
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
},
|
|
|
|
|
);
|
2022-08-19 10:10:36 +00:00
|
|
|
|
|
|
|
|
export const getFocusedParentToOpen = createSelector(
|
|
|
|
|
getCanvasWidgets,
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.focusedWidget,
|
|
|
|
|
(canvasWidgets, focusedWidgetId) => {
|
|
|
|
|
return getParentToOpenIfAny(focusedWidgetId, canvasWidgets);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getParentToOpenSelector = (widgetId: string) => {
|
|
|
|
|
return createSelector(getCanvasWidgets, (canvasWidgets) => {
|
|
|
|
|
return getParentToOpenIfAny(widgetId, canvasWidgets);
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-09-14 06:55:08 +00:00
|
|
|
|
|
|
|
|
// Check if widget is in the list of selected widgets
|
|
|
|
|
export const isWidgetSelected = (widgetId: string) => {
|
|
|
|
|
return createSelector(getSelectedWidgets, (widgets): boolean =>
|
|
|
|
|
widgets.includes(widgetId),
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isCurrentWidgetFocused = (widgetId: string) => {
|
|
|
|
|
return createSelector(
|
|
|
|
|
getFocusedWidget,
|
|
|
|
|
(widget): boolean => widget === widgetId,
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Check if current widget is the last selected widget
|
|
|
|
|
export const isCurrentWidgetLastSelected = (widgetId: string) => {
|
|
|
|
|
return createSelector(
|
2022-09-15 05:44:11 +00:00
|
|
|
getLastSelectedWidget,
|
2022-09-14 06:55:08 +00:00
|
|
|
(widget): boolean => widget === widgetId,
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Check if current widget is one of multiple selected widgets
|
|
|
|
|
export const isMultiSelectedWidget = (widgetId: string) => {
|
|
|
|
|
return createSelector(
|
|
|
|
|
getSelectedWidgets,
|
|
|
|
|
(widgets): boolean => widgets.length > 1 && widgets.includes(widgetId),
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function getParentToOpenIfAny(
|
|
|
|
|
widgetId: string | undefined,
|
|
|
|
|
widgets: CanvasWidgetsReduxState,
|
|
|
|
|
) {
|
|
|
|
|
if (widgetId) {
|
|
|
|
|
let widget = get(widgets, widgetId, undefined);
|
|
|
|
|
|
|
|
|
|
// While this widget has a openParentPropertyPane equal to true
|
|
|
|
|
while (widget?.openParentPropertyPane) {
|
|
|
|
|
// Get parent widget props
|
|
|
|
|
const parent = get(widgets, `${widget.parentId}`, undefined);
|
|
|
|
|
|
|
|
|
|
// If parent has openParentPropertyPane = false, return the current parent
|
|
|
|
|
if (!parent?.openParentPropertyPane) {
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parent?.parentId && parent.parentId !== MAIN_CONTAINER_WIDGET_ID) {
|
|
|
|
|
widget = get(widgets, `${widget.parentId}`, undefined);
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const shouldWidgetIgnoreClicksSelector = (widgetId: string) => {
|
|
|
|
|
return createSelector(
|
|
|
|
|
getFocusedWidget,
|
|
|
|
|
getIsTableFilterPaneVisible,
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isResizing,
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isDragging,
|
|
|
|
|
getAppMode,
|
|
|
|
|
(
|
|
|
|
|
focusedWidgetId,
|
|
|
|
|
isTableFilterPaneVisible,
|
|
|
|
|
isResizing,
|
|
|
|
|
isDragging,
|
|
|
|
|
appMode,
|
|
|
|
|
) => {
|
|
|
|
|
const isFocused = focusedWidgetId === widgetId;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
isResizing ||
|
|
|
|
|
isDragging ||
|
|
|
|
|
appMode !== APP_MODE.EDIT ||
|
|
|
|
|
!isFocused ||
|
|
|
|
|
isTableFilterPaneVisible
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|