2023-12-14 14:44:30 +00:00
|
|
|
import type { EntityTypeValue } from "@appsmith/entities/DataTree/types";
|
2023-10-22 06:46:31 +00:00
|
|
|
import { ACTION_TYPE, JSACTION_TYPE } from "@appsmith/entities/DataTree/types";
|
2023-10-10 12:32:17 +00:00
|
|
|
import type { DataTree } from "entities/DataTree/dataTreeTypes";
|
2023-12-14 14:44:30 +00:00
|
|
|
import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory";
|
2022-12-08 12:16:41 +00:00
|
|
|
import { createSelector } from "reselect";
|
|
|
|
|
import {
|
2023-09-12 11:51:39 +00:00
|
|
|
getCurrentActions,
|
2023-05-22 12:11:02 +00:00
|
|
|
getDatasources,
|
2023-03-21 05:09:43 +00:00
|
|
|
getJSCollections,
|
2022-12-08 12:16:41 +00:00
|
|
|
getPlugins,
|
2023-09-12 11:51:39 +00:00
|
|
|
} from "@appsmith/selectors/entitiesSelector";
|
2022-12-08 12:16:41 +00:00
|
|
|
import { getWidgets } from "sagas/selectors";
|
|
|
|
|
import { getCurrentPageId } from "selectors/editorSelectors";
|
|
|
|
|
import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers";
|
2023-10-12 05:31:22 +00:00
|
|
|
import { jsCollectionIdURL, widgetURL } from "@appsmith/RouteBuilder";
|
2022-12-26 05:19:02 +00:00
|
|
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
2023-02-17 16:03:34 +00:00
|
|
|
import { createNavData } from "utils/NavigationSelector/common";
|
|
|
|
|
import { getWidgetChildrenNavData } from "utils/NavigationSelector/WidgetChildren";
|
|
|
|
|
import { getJsChildrenNavData } from "utils/NavigationSelector/JsChildren";
|
2023-04-03 10:41:15 +00:00
|
|
|
import {
|
|
|
|
|
getEntityNameAndPropertyPath,
|
|
|
|
|
isJSAction,
|
|
|
|
|
} from "@appsmith/workers/Evaluation/evaluationUtils";
|
|
|
|
|
import type { AppState } from "@appsmith/reducers";
|
2023-05-22 12:11:02 +00:00
|
|
|
import { PluginType } from "entities/Action";
|
|
|
|
|
import type { StoredDatasource } from "entities/Action";
|
|
|
|
|
import type { Datasource } from "entities/Datasource";
|
2022-12-08 12:16:41 +00:00
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
export interface NavigationData {
|
2022-12-26 05:19:02 +00:00
|
|
|
name: string;
|
|
|
|
|
id: string;
|
2023-12-14 14:44:30 +00:00
|
|
|
type: EntityTypeValue;
|
2023-09-15 15:53:51 +00:00
|
|
|
isfunction?: boolean;
|
2022-12-26 05:19:02 +00:00
|
|
|
url: string | undefined;
|
|
|
|
|
navigable: boolean;
|
2023-02-17 16:03:34 +00:00
|
|
|
children: EntityNavigationData;
|
|
|
|
|
key?: string;
|
2023-05-22 12:11:02 +00:00
|
|
|
pluginName?: string;
|
2023-09-15 15:53:51 +00:00
|
|
|
pluginId?: string;
|
2023-05-22 12:11:02 +00:00
|
|
|
isMock?: boolean;
|
|
|
|
|
datasourceId?: string;
|
|
|
|
|
actionType?: string;
|
2023-09-01 06:41:47 +00:00
|
|
|
widgetType?: string;
|
|
|
|
|
value?: boolean | string;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
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(
|
2023-09-12 11:51:39 +00:00
|
|
|
getCurrentActions,
|
2022-12-08 12:16:41 +00:00
|
|
|
getPlugins,
|
2023-03-21 05:09:43 +00:00
|
|
|
getJSCollections,
|
2022-12-08 12:16:41 +00:00
|
|
|
getWidgets,
|
|
|
|
|
getCurrentPageId,
|
2022-12-26 05:19:02 +00:00
|
|
|
getDataTree,
|
2023-05-22 12:11:02 +00:00
|
|
|
getDatasources,
|
2023-03-21 05:09:43 +00:00
|
|
|
(_: any, entityName: string | undefined) => entityName,
|
|
|
|
|
(
|
|
|
|
|
actions,
|
|
|
|
|
plugins,
|
|
|
|
|
jsActions,
|
|
|
|
|
widgets,
|
|
|
|
|
pageId,
|
|
|
|
|
dataTree: DataTree,
|
2023-05-22 12:11:02 +00:00
|
|
|
datasources: Datasource[],
|
2023-03-21 05:09:43 +00:00
|
|
|
entityName: string | undefined,
|
|
|
|
|
) => {
|
|
|
|
|
// data tree retriggers this
|
|
|
|
|
jsActions = jsActions.filter((a) => a.config.pageId === pageId);
|
2022-12-08 12:16:41 +00:00
|
|
|
const navigationData: EntityNavigationData = {};
|
2023-03-16 00:50:58 +00:00
|
|
|
if (!dataTree) return navigationData;
|
2022-12-08 12:16:41 +00:00
|
|
|
|
|
|
|
|
actions.forEach((action) => {
|
|
|
|
|
const plugin = plugins.find(
|
|
|
|
|
(plugin) => plugin.id === action.config.pluginId,
|
|
|
|
|
);
|
2023-05-22 12:11:02 +00:00
|
|
|
const datasourceId = (action.config?.datasource as StoredDatasource)?.id;
|
|
|
|
|
const datasource = datasources.find(
|
|
|
|
|
(datasource) => datasource.id === datasourceId,
|
|
|
|
|
);
|
2022-12-08 12:16:41 +00:00
|
|
|
const config = getActionConfig(action.config.pluginType);
|
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,
|
2023-12-14 14:44:30 +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-05-26 11:42:10 +00:00
|
|
|
children: {},
|
2023-05-22 12:11:02 +00:00
|
|
|
// Adding below data as it is required for analytical events
|
|
|
|
|
pluginName: plugin?.name,
|
2023-09-15 15:53:51 +00:00
|
|
|
pluginId: plugin?.id,
|
2023-05-22 12:11:02 +00:00
|
|
|
datasourceId: datasource?.id,
|
|
|
|
|
isMock: datasource?.isMock,
|
|
|
|
|
actionType:
|
|
|
|
|
action.config.pluginType === PluginType.DB ? "Query" : "API",
|
2023-02-17 16:03:34 +00:00
|
|
|
});
|
2022-12-08 12:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
jsActions.forEach((jsAction) => {
|
2023-05-26 11:42:10 +00:00
|
|
|
// dataTree for null check
|
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,
|
2023-12-14 14:44:30 +00:00
|
|
|
type: ENTITY_TYPE.JSACTION,
|
2022-12-08 12:16:41 +00:00
|
|
|
url: jsCollectionIdURL({ pageId, collectionId: jsAction.config.id }),
|
2023-02-17 16:03:34 +00:00
|
|
|
children: result?.childNavData || {},
|
|
|
|
|
});
|
2022-12-08 12:16:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Object.values(widgets).forEach((widget) => {
|
2023-05-26 11:42:10 +00:00
|
|
|
// dataTree to get entityDefinitions, for url (can use getWidgetByName?)
|
|
|
|
|
const result = getWidgetChildrenNavData(
|
|
|
|
|
widget.widgetName,
|
|
|
|
|
widget.type,
|
|
|
|
|
dataTree,
|
|
|
|
|
pageId,
|
|
|
|
|
);
|
2023-02-17 16:03:34 +00:00
|
|
|
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,
|
2023-12-14 14:44:30 +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
|
|
|
children: result?.childNavData || {},
|
2023-09-01 06:41:47 +00:00
|
|
|
widgetType: widget.type,
|
2023-02-17 16:03:34 +00:00
|
|
|
});
|
2022-12-08 12:16:41 +00:00
|
|
|
});
|
2023-03-21 05:09:43 +00:00
|
|
|
if (
|
|
|
|
|
entityName &&
|
2023-03-21 18:37:52 +00:00
|
|
|
isJSAction(dataTree[entityName]) &&
|
2023-03-21 05:09:43 +00:00
|
|
|
entityName in navigationData
|
|
|
|
|
) {
|
|
|
|
|
return {
|
|
|
|
|
...navigationData,
|
|
|
|
|
this: navigationData[entityName],
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-12-08 12:16:41 +00:00
|
|
|
return navigationData;
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-10-22 06:46:31 +00:00
|
|
|
export const getPathNavigationUrl = createSelector(
|
2023-04-03 10:41:15 +00:00
|
|
|
[
|
|
|
|
|
(state: AppState, entityName: string) =>
|
|
|
|
|
getEntitiesForNavigation(state, entityName),
|
2023-10-22 06:46:31 +00:00
|
|
|
(_, __, fullPath: string | undefined) => fullPath,
|
2023-04-03 10:41:15 +00:00
|
|
|
],
|
2023-10-22 06:46:31 +00:00
|
|
|
(entitiesForNavigation, fullPath) => {
|
|
|
|
|
if (!fullPath) return undefined;
|
|
|
|
|
const { entityName, propertyPath } = getEntityNameAndPropertyPath(fullPath);
|
|
|
|
|
const navigationData = entitiesForNavigation[entityName];
|
|
|
|
|
if (!navigationData) return undefined;
|
|
|
|
|
switch (navigationData.type) {
|
|
|
|
|
case JSACTION_TYPE: {
|
|
|
|
|
const jsPropertyNavigationData = navigationData.children[propertyPath];
|
|
|
|
|
return jsPropertyNavigationData.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ACTION_TYPE:
|
|
|
|
|
{
|
|
|
|
|
return navigationData.url;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
2023-04-03 10:41:15 +00:00
|
|
|
},
|
|
|
|
|
);
|