## Description Refactoring entity types and updating DS action create permission to fix some bugs on EE #### PR fixes following issue(s) Fixes # (issue number) #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] JUnit - [x] Jest - [x] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Streamlined entity type naming conventions across the application for better consistency. - Enhanced type definitions for improved code clarity and maintainability. - Updated function calls to use object parameters with named properties for better readability. - **New Features** - Introduced a new entity type for module instances, expanding the application's data handling capabilities. - **Bug Fixes** - Corrected improper type assertions to ensure accurate entity recognition and processing. - **Documentation** - Added comments to clarify the non-introduction of certain dependencies in specific components. - **Style** - Adjusted import statements to align with the updated naming conventions. - **Tests** - Updated test cases to reflect changes in entity type references and assertions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
172 lines
5.4 KiB
TypeScript
172 lines
5.4 KiB
TypeScript
import type { EntityTypeValue } from "@appsmith/entities/DataTree/types";
|
|
import { ACTION_TYPE, JSACTION_TYPE } from "@appsmith/entities/DataTree/types";
|
|
import type { DataTree } from "entities/DataTree/dataTreeTypes";
|
|
import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory";
|
|
import { createSelector } from "reselect";
|
|
import {
|
|
getCurrentActions,
|
|
getDatasources,
|
|
getJSCollections,
|
|
getPlugins,
|
|
} from "@appsmith/selectors/entitiesSelector";
|
|
import { getWidgets } from "sagas/selectors";
|
|
import { getCurrentPageId } from "selectors/editorSelectors";
|
|
import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers";
|
|
import { jsCollectionIdURL, widgetURL } from "@appsmith/RouteBuilder";
|
|
import { getDataTree } from "selectors/dataTreeSelectors";
|
|
import { createNavData } from "utils/NavigationSelector/common";
|
|
import { getWidgetChildrenNavData } from "utils/NavigationSelector/WidgetChildren";
|
|
import { getJsChildrenNavData } from "utils/NavigationSelector/JsChildren";
|
|
import {
|
|
getEntityNameAndPropertyPath,
|
|
isJSAction,
|
|
} from "@appsmith/workers/Evaluation/evaluationUtils";
|
|
import type { AppState } from "@appsmith/reducers";
|
|
import { PluginType } from "entities/Action";
|
|
import type { StoredDatasource } from "entities/Action";
|
|
import type { Datasource } from "entities/Datasource";
|
|
|
|
export interface NavigationData {
|
|
name: string;
|
|
id: string;
|
|
type: EntityTypeValue;
|
|
isfunction?: boolean;
|
|
url: string | undefined;
|
|
navigable: boolean;
|
|
children: EntityNavigationData;
|
|
key?: string;
|
|
pluginName?: string;
|
|
pluginId?: string;
|
|
isMock?: boolean;
|
|
datasourceId?: string;
|
|
actionType?: string;
|
|
widgetType?: string;
|
|
value?: boolean | string;
|
|
}
|
|
export type EntityNavigationData = Record<string, NavigationData>;
|
|
|
|
export const getEntitiesForNavigation = createSelector(
|
|
getCurrentActions,
|
|
getPlugins,
|
|
getJSCollections,
|
|
getWidgets,
|
|
getCurrentPageId,
|
|
getDataTree,
|
|
getDatasources,
|
|
(_: any, entityName: string | undefined) => entityName,
|
|
(
|
|
actions,
|
|
plugins,
|
|
jsActions,
|
|
widgets,
|
|
pageId,
|
|
dataTree: DataTree,
|
|
datasources: Datasource[],
|
|
entityName: string | undefined,
|
|
) => {
|
|
// data tree retriggers this
|
|
jsActions = jsActions.filter((a) => a.config.pageId === pageId);
|
|
const navigationData: EntityNavigationData = {};
|
|
if (!dataTree) return navigationData;
|
|
|
|
actions.forEach((action) => {
|
|
const plugin = plugins.find(
|
|
(plugin) => plugin.id === action.config.pluginId,
|
|
);
|
|
const datasourceId = (action.config?.datasource as StoredDatasource)?.id;
|
|
const datasource = datasources.find(
|
|
(datasource) => datasource.id === datasourceId,
|
|
);
|
|
const config = getActionConfig(action.config.pluginType);
|
|
if (!config) return;
|
|
navigationData[action.config.name] = createNavData({
|
|
id: action.config.id,
|
|
name: action.config.name,
|
|
type: ENTITY_TYPE.ACTION,
|
|
url: config.getURL(
|
|
pageId,
|
|
action.config.id,
|
|
action.config.pluginType,
|
|
plugin,
|
|
),
|
|
children: {},
|
|
// Adding below data as it is required for analytical events
|
|
pluginName: plugin?.name,
|
|
pluginId: plugin?.id,
|
|
datasourceId: datasource?.id,
|
|
isMock: datasource?.isMock,
|
|
actionType:
|
|
action.config.pluginType === PluginType.DB ? "Query" : "API",
|
|
});
|
|
});
|
|
|
|
jsActions.forEach((jsAction) => {
|
|
// dataTree for null check
|
|
const result = getJsChildrenNavData(jsAction, pageId, dataTree);
|
|
navigationData[jsAction.config.name] = createNavData({
|
|
id: jsAction.config.id,
|
|
name: jsAction.config.name,
|
|
type: ENTITY_TYPE.JSACTION,
|
|
url: jsCollectionIdURL({ pageId, collectionId: jsAction.config.id }),
|
|
children: result?.childNavData || {},
|
|
});
|
|
});
|
|
|
|
Object.values(widgets).forEach((widget) => {
|
|
// dataTree to get entityDefinitions, for url (can use getWidgetByName?)
|
|
const result = getWidgetChildrenNavData(
|
|
widget.widgetName,
|
|
widget.type,
|
|
dataTree,
|
|
pageId,
|
|
);
|
|
navigationData[widget.widgetName] = createNavData({
|
|
id: widget.widgetId,
|
|
name: widget.widgetName,
|
|
type: ENTITY_TYPE.WIDGET,
|
|
url: widgetURL({ pageId, selectedWidgets: [widget.widgetId] }),
|
|
children: result?.childNavData || {},
|
|
widgetType: widget.type,
|
|
});
|
|
});
|
|
if (
|
|
entityName &&
|
|
isJSAction(dataTree[entityName]) &&
|
|
entityName in navigationData
|
|
) {
|
|
return {
|
|
...navigationData,
|
|
this: navigationData[entityName],
|
|
};
|
|
}
|
|
return navigationData;
|
|
},
|
|
);
|
|
export const getPathNavigationUrl = createSelector(
|
|
[
|
|
(state: AppState, entityName: string) =>
|
|
getEntitiesForNavigation(state, entityName),
|
|
(_, __, fullPath: string | undefined) => fullPath,
|
|
],
|
|
(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;
|
|
}
|
|
},
|
|
);
|