2020-03-27 09:02:11 +00:00
|
|
|
import { createSelector } from "reselect";
|
|
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import { 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-05-15 13:12:07 +00:00
|
|
|
export const getIsDraggingOrResizing = (state: AppState) =>
|
|
|
|
|
state.ui.widgetDragResize.isResizing || state.ui.widgetDragResize.isDragging;
|
|
|
|
|
|
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;
|
|
|
|
|
},
|
|
|
|
|
);
|