2022-12-26 05:19:02 +00:00
|
|
|
import {
|
|
|
|
|
DataTree,
|
2023-02-17 16:03:34 +00:00
|
|
|
DataTreeAppsmith,
|
2022-12-26 05:19:02 +00:00
|
|
|
ENTITY_TYPE,
|
|
|
|
|
} from "entities/DataTree/dataTreeFactory";
|
2022-12-08 12:16:41 +00:00
|
|
|
import { createSelector } from "reselect";
|
|
|
|
|
import {
|
|
|
|
|
getActionsForCurrentPage,
|
|
|
|
|
getJSCollectionsForCurrentPage,
|
|
|
|
|
getPlugins,
|
|
|
|
|
} from "selectors/entitiesSelector";
|
|
|
|
|
import { getWidgets } from "sagas/selectors";
|
|
|
|
|
import { getCurrentPageId } from "selectors/editorSelectors";
|
|
|
|
|
import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers";
|
2023-02-21 13:38:16 +00:00
|
|
|
import { jsCollectionIdURL, widgetURL } from "RouteBuilder";
|
2022-12-26 05:19:02 +00:00
|
|
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
2023-02-17 16:03:34 +00:00
|
|
|
import { getActionChildrenNavData } from "utils/NavigationSelector/ActionChildren";
|
|
|
|
|
import { createNavData } from "utils/NavigationSelector/common";
|
|
|
|
|
import { getWidgetChildrenNavData } from "utils/NavigationSelector/WidgetChildren";
|
|
|
|
|
import { getJsChildrenNavData } from "utils/NavigationSelector/JsChildren";
|
|
|
|
|
import { getAppsmithNavData } from "utils/NavigationSelector/AppsmithNavData";
|
2022-12-08 12:16:41 +00:00
|
|
|
|
2022-12-26 05:19:02 +00:00
|
|
|
export type NavigationData = {
|
|
|
|
|
name: string;
|
|
|
|
|
id: string;
|
|
|
|
|
type: ENTITY_TYPE;
|
|
|
|
|
url: string | undefined;
|
|
|
|
|
navigable: boolean;
|
2023-02-17 16:03:34 +00:00
|
|
|
children: EntityNavigationData;
|
|
|
|
|
peekable: boolean;
|
|
|
|
|
peekData?: unknown;
|
|
|
|
|
key?: string;
|
2022-12-26 05:19:02 +00:00
|
|
|
};
|
|
|
|
|
export type EntityNavigationData = Record<string, NavigationData>;
|
2022-12-08 12:16:41 +00:00
|
|
|
|
|
|
|
|
export const getEntitiesForNavigation = createSelector(
|
|
|
|
|
getActionsForCurrentPage,
|
|
|
|
|
getPlugins,
|
|
|
|
|
getJSCollectionsForCurrentPage,
|
|
|
|
|
getWidgets,
|
|
|
|
|
getCurrentPageId,
|
2022-12-26 05:19:02 +00:00
|
|
|
getDataTree,
|
|
|
|
|
(actions, plugins, jsActions, widgets, pageId, dataTree: DataTree) => {
|
2022-12-08 12:16:41 +00:00
|
|
|
const navigationData: EntityNavigationData = {};
|
|
|
|
|
|
|
|
|
|
actions.forEach((action) => {
|
|
|
|
|
const plugin = plugins.find(
|
|
|
|
|
(plugin) => plugin.id === action.config.pluginId,
|
|
|
|
|
);
|
|
|
|
|
const config = getActionConfig(action.config.pluginType);
|
2023-02-17 16:03:34 +00:00
|
|
|
const result = getActionChildrenNavData(action, dataTree);
|
2022-12-15 04:06:13 +00:00
|
|
|
if (!config) return;
|
2023-02-17 16:03:34 +00:00
|
|
|
navigationData[action.config.name] = createNavData({
|
2022-12-08 12:16:41 +00:00
|
|
|
id: action.config.id,
|
2023-02-17 16:03:34 +00:00
|
|
|
name: action.config.name,
|
2022-12-08 12:16:41 +00:00
|
|
|
type: ENTITY_TYPE.ACTION,
|
2022-12-15 04:06:13 +00:00
|
|
|
url: config.getURL(
|
2022-12-08 12:16:41 +00:00
|
|
|
pageId,
|
|
|
|
|
action.config.id,
|
|
|
|
|
action.config.pluginType,
|
|
|
|
|
plugin,
|
|
|
|
|
),
|
2023-02-17 16:03:34 +00:00
|
|
|
peekable: true,
|
|
|
|
|
peekData: result?.peekData,
|
|
|
|
|
children: result?.childNavData || {},
|
|
|
|
|
});
|
2022-12-08 12:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
jsActions.forEach((jsAction) => {
|
2023-02-17 16:03:34 +00:00
|
|
|
const result = getJsChildrenNavData(jsAction, pageId, dataTree);
|
|
|
|
|
navigationData[jsAction.config.name] = createNavData({
|
2022-12-08 12:16:41 +00:00
|
|
|
id: jsAction.config.id,
|
2023-02-17 16:03:34 +00:00
|
|
|
name: jsAction.config.name,
|
2022-12-08 12:16:41 +00:00
|
|
|
type: ENTITY_TYPE.JSACTION,
|
|
|
|
|
url: jsCollectionIdURL({ pageId, collectionId: jsAction.config.id }),
|
2023-02-17 16:03:34 +00:00
|
|
|
peekable: true,
|
|
|
|
|
peekData: result?.peekData,
|
|
|
|
|
children: result?.childNavData || {},
|
|
|
|
|
});
|
2022-12-08 12:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Object.values(widgets).forEach((widget) => {
|
2023-02-17 16:03:34 +00:00
|
|
|
const result = getWidgetChildrenNavData(widget, dataTree, pageId);
|
|
|
|
|
navigationData[widget.widgetName] = createNavData({
|
2022-12-08 12:16:41 +00:00
|
|
|
id: widget.widgetId,
|
2023-02-17 16:03:34 +00:00
|
|
|
name: widget.widgetName,
|
2022-12-08 12:16:41 +00:00
|
|
|
type: ENTITY_TYPE.WIDGET,
|
2023-02-21 13:38:16 +00:00
|
|
|
url: widgetURL({ pageId, selectedWidgets: [widget.widgetId] }),
|
2023-02-17 16:03:34 +00:00
|
|
|
peekable: true,
|
|
|
|
|
peekData: result?.peekData,
|
|
|
|
|
children: result?.childNavData || {},
|
|
|
|
|
});
|
2022-12-08 12:16:41 +00:00
|
|
|
});
|
2023-02-17 16:03:34 +00:00
|
|
|
navigationData["appsmith"] = getAppsmithNavData(
|
|
|
|
|
dataTree.appsmith as DataTreeAppsmith,
|
|
|
|
|
);
|
2022-12-08 12:16:41 +00:00
|
|
|
return navigationData;
|
|
|
|
|
},
|
|
|
|
|
);
|