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";
|
|
|
|
|
|
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
|
|
|
);
|