From cf6c77194b49f08cc34d31cd12b495411ff7be1f Mon Sep 17 00:00:00 2001 From: Ankita Kinger Date: Thu, 14 Dec 2023 20:14:30 +0530 Subject: [PATCH] chore: Refactoring entity types and updating DS action create permission to fix some bugs on EE (#29573) ## 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 ## 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. --- .../ErrorLogs/getLogIconForEntity.tsx | 8 +- .../editorComponents/GPT/trigger.tsx | 4 +- .../ce/entities/DataTree/dataTreeAction.ts | 6 +- .../ce/entities/DataTree/dataTreeJSAction.ts | 6 +- .../ce/entities/DataTree/isDynamicEntity.ts | 12 +- app/client/src/ce/entities/DataTree/types.ts | 29 +-- .../src/ce/hooks/datasourceEditorHooks.tsx | 8 +- app/client/src/ce/hooks/index.ts | 2 +- .../Linting/utils/getEntityDependencies.ts | 15 +- .../Linting/utils/getEntityUniqueIdForLogs.ts | 4 +- .../src/ce/reducers/entityReducers/index.ts | 6 + app/client/src/ce/reducers/index.tsx | 1 + .../ce/reducers/uiReducers/explorerReducer.ts | 6 +- .../permissionPageHelpers.tsx | 25 ++- .../getEntityPeekData.ts | 10 +- .../autocomplete/entityDefGeneratorMap.ts | 20 +- .../src/ce/utils/getEntityPayloadInfo.ts | 8 +- .../Evaluation/evaluationUtils.test.ts | 16 +- .../ce/workers/Evaluation/evaluationUtils.ts | 14 +- .../Evaluation/getEntityForEvalContextMap.ts | 4 +- .../utils/getEntityDependenciesByType.ts | 14 +- .../ActionCreator/helpers.tsx | 2 +- .../editorComponents/ActionCreator/types.ts | 7 +- .../CodeEditor/EditorConfig.ts | 4 +- .../CodeEditor/commandsHelper.ts | 4 +- .../CodeEditor/generateQuickCommands.tsx | 20 +- .../CodeEditor/hintHelpers.ts | 4 +- .../editorComponents/CodeEditor/index.tsx | 7 +- .../editorComponents/GlobalSearch/utils.tsx | 17 +- .../fields/EmbeddedDatasourcePathField.tsx | 7 +- .../ActionConstants.tsx | 4 +- app/client/src/ee/entities/DataTree/types.ts | 10 +- .../src/entities/DataTree/dataTreeFactory.ts | 11 +- .../entities/DataTree/dataTreeWidget.test.ts | 6 +- .../src/entities/DataTree/dataTreeWidget.ts | 6 +- .../Editor/DataSourceEditor/DSFormHeader.tsx | 1 + .../pages/Editor/DataSourceEditor/hooks.ts | 13 +- .../DatasourceInfo/DatasourceStructure.tsx | 12 +- .../DatasourceViewModeSchema.tsx | 13 +- .../DatasourceInfo/GoogleSheetSchema.tsx | 13 +- .../Actions/ActionEntityContextMenu.tsx | 4 +- .../Explorer/Entity/EntityProperties.tsx | 175 ++++++++++++------ .../JSActions/JSActionContextMenu.tsx | 4 +- .../Explorer/Widgets/WidgetContextMenu.tsx | 4 +- .../Editor/IDE/LeftPane/DataSidePane.tsx | 4 +- .../IntegrationEditor/DatasourceCard.tsx | 12 +- .../sagas/ActionExecution/PluginActionSaga.ts | 11 +- .../src/selectors/navigationSelectors.ts | 12 +- .../__tests__/index.test.ts | 6 +- .../utils/NavigationSelector/JsChildren.ts | 6 +- .../NavigationSelector/WidgetChildren.ts | 4 +- .../src/utils/NavigationSelector/common.ts | 4 +- .../src/utils/WidgetLoadingStateUtils.test.ts | 12 +- .../autocomplete/CodemirrorTernService.ts | 8 +- .../__tests__/AutocompleteSortRules.test.ts | 4 +- .../autocomplete/__tests__/TernServer.test.ts | 30 +-- .../__tests__/dataTreeTypeDefCreator.test.ts | 8 +- app/client/src/utils/widgetRenderUtils.tsx | 4 +- .../JSObject/__test__/mutation.test.ts | 4 +- .../Evaluation/__tests__/Actions.test.ts | 4 +- .../Evaluation/__tests__/evaluate.test.ts | 4 +- .../Evaluation/__tests__/evaluation.test.ts | 10 +- .../Evaluation/__tests__/timeout.test.ts | 4 +- .../Evaluation/fns/__tests__/interval.test.ts | 4 +- .../workers/common/DataTreeEvaluator/index.ts | 10 +- .../mockData/ArrayAccessorTree.ts | 34 ++-- .../mockData/NestedArrayAccessorTree.ts | 42 ++--- .../mockData/mockConfigTree.ts | 10 +- .../mockData/mockUnEvalTree.ts | 12 +- 69 files changed, 470 insertions(+), 359 deletions(-) diff --git a/app/client/src/ce/components/editorComponents/Debugger/ErrorLogs/getLogIconForEntity.tsx b/app/client/src/ce/components/editorComponents/Debugger/ErrorLogs/getLogIconForEntity.tsx index 99dce79afb..0e02f7ae03 100644 --- a/app/client/src/ce/components/editorComponents/Debugger/ErrorLogs/getLogIconForEntity.tsx +++ b/app/client/src/ce/components/editorComponents/Debugger/ErrorLogs/getLogIconForEntity.tsx @@ -9,23 +9,23 @@ import { JsFileIconV2, } from "pages/Editor/Explorer/ExplorerIcons"; import { getAssetUrl } from "@appsmith/utils/airgapHelpers"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; export const getIconForEntity: Record< string, (props: LogItemProps, pluginGroups: Record) => any > = { - [ENTITY_TYPE_VALUE.WIDGET]: (props) => { + [ENTITY_TYPE.WIDGET]: (props) => { if (props.source?.pluginType) { return ( ); } }, - [ENTITY_TYPE_VALUE.JSACTION]: () => { + [ENTITY_TYPE.JSACTION]: () => { return JsFileIconV2(16, 16, true, true); }, - [ENTITY_TYPE_VALUE.ACTION]: (props, pluginGroups) => { + [ENTITY_TYPE.ACTION]: (props, pluginGroups) => { const { iconId, source } = props; if (source?.pluginType === PluginType.API && source.httpMethod) { // If the source is an API action. diff --git a/app/client/src/ce/components/editorComponents/GPT/trigger.tsx b/app/client/src/ce/components/editorComponents/GPT/trigger.tsx index b2f735238f..744ad08273 100644 --- a/app/client/src/ce/components/editorComponents/GPT/trigger.tsx +++ b/app/client/src/ce/components/editorComponents/GPT/trigger.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import type { TEditorModes } from "components/editorComponents/CodeEditor/EditorConfig"; import type { FeatureFlags } from "@appsmith/entities/FeatureFlag"; -import type { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; +import type { EntityTypeValue } from "@appsmith/entities/DataTree/types"; export const APPSMITH_AI = "Appsmith AI"; @@ -17,7 +17,7 @@ export const getAIContext = ({ cursorPosition, editor, }: { - entityType?: ENTITY_TYPE; + entityType?: EntityTypeValue; slashIndex?: number; currentLineValue?: string; cursorPosition: CodeMirror.Position; diff --git a/app/client/src/ce/entities/DataTree/dataTreeAction.ts b/app/client/src/ce/entities/DataTree/dataTreeAction.ts index 5daeac109d..5f973d5e83 100644 --- a/app/client/src/ce/entities/DataTree/dataTreeAction.ts +++ b/app/client/src/ce/entities/DataTree/dataTreeAction.ts @@ -1,5 +1,5 @@ import type { DependencyMap, DynamicPath } from "utils/DynamicBindingUtils"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { ActionData } from "@appsmith/reducers/entityReducers/actionsReducer"; import { getBindingAndReactivePathsOfAction, @@ -67,7 +67,7 @@ export const generateDataTreeAction = ( headers: action.data?.headers, }, config: action.config.actionConfiguration, - ENTITY_TYPE: ENTITY_TYPE_VALUE.ACTION, + ENTITY_TYPE: ENTITY_TYPE.ACTION, datasourceUrl, }, configEntity: { @@ -76,7 +76,7 @@ export const generateDataTreeAction = ( pluginId: action.config.pluginId, pluginType: action.config.pluginType, dynamicBindingPathList, - ENTITY_TYPE: ENTITY_TYPE_VALUE.ACTION, + ENTITY_TYPE: ENTITY_TYPE.ACTION, bindingPaths, reactivePaths, dependencyMap, diff --git a/app/client/src/ce/entities/DataTree/dataTreeJSAction.ts b/app/client/src/ce/entities/DataTree/dataTreeJSAction.ts index 8add6cc7d2..cc27443440 100644 --- a/app/client/src/ce/entities/DataTree/dataTreeJSAction.ts +++ b/app/client/src/ce/entities/DataTree/dataTreeJSAction.ts @@ -1,4 +1,4 @@ -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { JSCollectionData } from "@appsmith/reducers/entityReducers/jsActionsReducer"; import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory"; import type { DependencyMap } from "utils/DynamicBindingUtils"; @@ -62,7 +62,7 @@ export const generateDataTreeJSAction = ( ...variableList, ...actionsData, body: removeThisReference, - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, actionId: js.config.id, }, configEntity: { @@ -70,7 +70,7 @@ export const generateDataTreeJSAction = ( meta: meta, name: js.config.name, pluginType: js.config.pluginType, - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, bindingPaths: bindingPaths, // As all js object function referred to as action is user javascript code, we add them as binding paths. reactivePaths: { ...bindingPaths }, dynamicBindingPathList: dynamicBindingPathList, diff --git a/app/client/src/ce/entities/DataTree/isDynamicEntity.ts b/app/client/src/ce/entities/DataTree/isDynamicEntity.ts index 9d667e1ace..5233234749 100644 --- a/app/client/src/ce/entities/DataTree/isDynamicEntity.ts +++ b/app/client/src/ce/entities/DataTree/isDynamicEntity.ts @@ -5,8 +5,8 @@ import type { WidgetEntity, } from "@appsmith/entities/DataTree/types"; import { - type ENTITY_TYPE, - ENTITY_TYPE_VALUE, + type EntityTypeValue, + ENTITY_TYPE, } from "entities/DataTree/dataTreeFactory"; import type { DataTreeEntity } from "entities/DataTree/dataTreeTypes"; @@ -17,9 +17,9 @@ export function isDynamicEntity( ): entity is DynamicEntityType { return ( [ - ENTITY_TYPE_VALUE.JSACTION, - ENTITY_TYPE_VALUE.WIDGET, - ENTITY_TYPE_VALUE.ACTION, - ] as Array + ENTITY_TYPE.JSACTION, + ENTITY_TYPE.WIDGET, + ENTITY_TYPE.ACTION, + ] as Array ).includes(entity.ENTITY_TYPE); } diff --git a/app/client/src/ce/entities/DataTree/types.ts b/app/client/src/ce/entities/DataTree/types.ts index 17678d2bdd..ae545f3727 100644 --- a/app/client/src/ce/entities/DataTree/types.ts +++ b/app/client/src/ce/entities/DataTree/types.ts @@ -22,15 +22,18 @@ import type { ModuleInstance } from "@appsmith/constants/ModuleInstanceConstants export type ActionDispatcher = (...args: any[]) => ActionDescription; -export enum ENTITY_TYPE { - ACTION = "ACTION", - WIDGET = "WIDGET", - APPSMITH = "APPSMITH", - JSACTION = "JSACTION", -} +export const ENTITY_TYPE = { + ACTION: "ACTION", + WIDGET: "WIDGET", + APPSMITH: "APPSMITH", + JSACTION: "JSACTION", +} as const; export const JSACTION_TYPE = ENTITY_TYPE.JSACTION; export const ACTION_TYPE = ENTITY_TYPE.ACTION; +type ValueOf = T[keyof T]; +export type EntityTypeValue = ValueOf; + export enum EvaluationSubstitutionType { TEMPLATE = "TEMPLATE", PARAMETER = "PARAMETER", @@ -49,7 +52,7 @@ export interface ActionEntity { isExecutionSuccess: boolean; headers?: unknown; }; - ENTITY_TYPE: ENTITY_TYPE.ACTION; + ENTITY_TYPE: typeof ENTITY_TYPE.ACTION; config: Partial; datasourceUrl: string; } @@ -58,7 +61,7 @@ export interface ActionEntityConfig extends EntityConfig { dynamicBindingPathList: DynamicPath[]; bindingPaths: Record; reactivePaths: Record; - ENTITY_TYPE: ENTITY_TYPE.ACTION; + ENTITY_TYPE: typeof ENTITY_TYPE.ACTION; dependencyMap: DependencyMap; logBlackList: Record; pluginType: PluginType; @@ -86,7 +89,7 @@ export interface JSActionEntityConfig extends EntityConfig { dependencyMap: DependencyMap; pluginType: PluginType.JS; name: string; - ENTITY_TYPE: ENTITY_TYPE.JSACTION; + ENTITY_TYPE: typeof ENTITY_TYPE.JSACTION; actionId: string; moduleId?: string; moduleInstanceId?: string; @@ -96,7 +99,7 @@ export interface JSActionEntityConfig extends EntityConfig { export interface JSActionEntity { [propName: string]: any; body: string; - ENTITY_TYPE: ENTITY_TYPE.JSACTION; + ENTITY_TYPE: typeof ENTITY_TYPE.JSACTION; actionId: string; } export type PagelistEntity = Page[]; @@ -134,7 +137,7 @@ export interface WidgetConfig extends EntityConfig { reactivePaths: Record; triggerPaths: Record; validationPaths: Record; - ENTITY_TYPE: ENTITY_TYPE.WIDGET; + ENTITY_TYPE: typeof ENTITY_TYPE.WIDGET; logBlackList: Record; propertyOverrideDependency: PropertyOverrideDependency; overridingPropertyPaths: OverridingPropertyPaths; @@ -158,7 +161,7 @@ export type UnEvalTreeEntityObject = export interface WidgetEntity extends WidgetProps { meta: Record; - ENTITY_TYPE: ENTITY_TYPE.WIDGET; + ENTITY_TYPE: typeof ENTITY_TYPE.WIDGET; } export type DataTreeEntityObject = | ActionEntity @@ -177,7 +180,7 @@ export interface WidgetEntityConfig } export interface AppsmithEntity extends Omit { - ENTITY_TYPE: ENTITY_TYPE.APPSMITH; + ENTITY_TYPE: typeof ENTITY_TYPE.APPSMITH; store: Record; theme: AppTheme["properties"]; } diff --git a/app/client/src/ce/hooks/datasourceEditorHooks.tsx b/app/client/src/ce/hooks/datasourceEditorHooks.tsx index 631b7e7707..cee9b49272 100644 --- a/app/client/src/ce/hooks/datasourceEditorHooks.tsx +++ b/app/client/src/ce/hooks/datasourceEditorHooks.tsx @@ -55,11 +55,11 @@ export const useHeaderActions = ( ); if (editorType === EditorNames.APPLICATION) { - const canCreateDatasourceActions = hasCreateDSActionPermissionInApp( - isFeatureEnabled, - datasource?.userPermissions ?? [], + const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({ + isEnabled: isFeatureEnabled, + dsPermissions: datasource?.userPermissions ?? [], pagePermissions, - ); + }); const canCreatePages = getHasCreatePagePermission( isFeatureEnabled, userAppPermissions, diff --git a/app/client/src/ce/hooks/index.ts b/app/client/src/ce/hooks/index.ts index 03e0e0e80e..a0180f9168 100644 --- a/app/client/src/ce/hooks/index.ts +++ b/app/client/src/ce/hooks/index.ts @@ -5,7 +5,7 @@ import { import { matchPath } from "react-router"; export const EditorNames = { - APPLICATION: "appEditor", + APPLICATION: "app", }; export interface EditorType { diff --git a/app/client/src/ce/plugins/Linting/utils/getEntityDependencies.ts b/app/client/src/ce/plugins/Linting/utils/getEntityDependencies.ts index 87838b0fc0..b298ff3849 100644 --- a/app/client/src/ce/plugins/Linting/utils/getEntityDependencies.ts +++ b/app/client/src/ce/plugins/Linting/utils/getEntityDependencies.ts @@ -3,7 +3,7 @@ import { convertPathToString, getEntityNameAndPropertyPath, } from "@appsmith/workers/Evaluation/evaluationUtils"; -import { ENTITY_TYPE_VALUE } from "@appsmith/entities/DataTree/types"; +import { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; import type { DependencyMap as TDependencyMap } from "utils/DynamicBindingUtils"; import { getPropertyPath } from "utils/DynamicBindingUtils"; import { getDynamicBindings } from "utils/DynamicBindingUtils"; @@ -23,11 +23,10 @@ export const getDependencies: Record< string, (entity: IEntity) => TDependencyMap > = { - [ENTITY_TYPE_VALUE.ACTION]: (entity) => + [ENTITY_TYPE.ACTION]: (entity) => getActionDependencies(entity as ActionEntity), - [ENTITY_TYPE_VALUE.JSACTION]: (entity) => - getJSDependencies(entity as JSEntity), - [ENTITY_TYPE_VALUE.WIDGET]: (entity) => + [ENTITY_TYPE.JSACTION]: (entity) => getJSDependencies(entity as JSEntity), + [ENTITY_TYPE.WIDGET]: (entity) => getWidgetDependencies(entity as WidgetEntity), }; @@ -35,11 +34,11 @@ export const getPathDependencies: Record< string, (entity: IEntity, fullPropertyPath: string) => TDependencyMap > = { - [ENTITY_TYPE_VALUE.ACTION]: (entity, fullPropertyPath) => + [ENTITY_TYPE.ACTION]: (entity, fullPropertyPath) => getActionPropertyPathDependencies(entity as ActionEntity, fullPropertyPath), - [ENTITY_TYPE_VALUE.JSACTION]: (entity, fullPropertyPath) => + [ENTITY_TYPE.JSACTION]: (entity, fullPropertyPath) => getJSPropertyPathDependencies(entity as JSEntity, fullPropertyPath), - [ENTITY_TYPE_VALUE.WIDGET]: (entity, fullPropertyPath) => + [ENTITY_TYPE.WIDGET]: (entity, fullPropertyPath) => getWidgetPropertyPathDependencies(entity as WidgetEntity, fullPropertyPath), }; diff --git a/app/client/src/ce/plugins/Linting/utils/getEntityUniqueIdForLogs.ts b/app/client/src/ce/plugins/Linting/utils/getEntityUniqueIdForLogs.ts index f9e0db610f..814da7957f 100644 --- a/app/client/src/ce/plugins/Linting/utils/getEntityUniqueIdForLogs.ts +++ b/app/client/src/ce/plugins/Linting/utils/getEntityUniqueIdForLogs.ts @@ -1,12 +1,12 @@ import type { JSActionEntity } from "@appsmith/entities/DataTree/types"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { DataTreeEntity } from "entities/DataTree/dataTreeTypes"; const entityUniqueIdGetterMap: Record< string, (entity: DataTreeEntity) => string > = { - [ENTITY_TYPE_VALUE.JSACTION]: (entity) => { + [ENTITY_TYPE.JSACTION]: (entity) => { return (entity as JSActionEntity).actionId; }, }; diff --git a/app/client/src/ce/reducers/entityReducers/index.ts b/app/client/src/ce/reducers/entityReducers/index.ts index 728408b482..079f9450c3 100644 --- a/app/client/src/ce/reducers/entityReducers/index.ts +++ b/app/client/src/ce/reducers/entityReducers/index.ts @@ -15,6 +15,8 @@ import canvasLevelsReducer from "reducers/entityReducers/autoHeightReducers/canv /* Reducers which are integrated into the core system when registering a pluggable module or done so by a module that is designed to be eventually pluggable */ import layoutElementPositionsReducer from "layoutSystems/anvil/integrations/reducers/layoutElementPositionsReducer"; +import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants"; +import type { AppState } from ".."; export const entityReducerObject = { canvasWidgets: canvasWidgetsReducer, @@ -31,4 +33,8 @@ export const entityReducerObject = { autoHeightLayoutTree: autoHeightLayoutTreeReducer, canvasLevels: canvasLevelsReducer, layoutElementPositions: layoutElementPositionsReducer, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + moduleInstanceEntities: (state: AppState, action: ReduxAction) => { + return {}; + }, }; diff --git a/app/client/src/ce/reducers/index.tsx b/app/client/src/ce/reducers/index.tsx index 9dc8ca10a2..1c3ec6f302 100644 --- a/app/client/src/ce/reducers/index.tsx +++ b/app/client/src/ce/reducers/index.tsx @@ -159,6 +159,7 @@ export interface AppState { autoHeightLayoutTree: AutoHeightLayoutTreeReduxState; canvasLevels: CanvasLevelsReduxState; layoutElementPositions: LayoutElementPositionsReduxState; + moduleInstanceEntities: any; }; evaluations: { tree: EvaluatedTreeState; diff --git a/app/client/src/ce/reducers/uiReducers/explorerReducer.ts b/app/client/src/ce/reducers/uiReducers/explorerReducer.ts index 55cc2482e2..f572978630 100644 --- a/app/client/src/ce/reducers/uiReducers/explorerReducer.ts +++ b/app/client/src/ce/reducers/uiReducers/explorerReducer.ts @@ -5,7 +5,7 @@ import { ReduxActionErrorTypes, } from "@appsmith/constants/ReduxActionConstants"; import get from "lodash/get"; -import type { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; +import type { EntityTypeValue } from "entities/DataTree/dataTreeFactory"; import { DEFAULT_ENTITY_EXPLORER_WIDTH } from "constants/AppConstants"; export enum ExplorerPinnedState { @@ -25,7 +25,7 @@ export interface ExplorerReduxState { active: boolean; entityInfo: { show: boolean; - entityType?: ENTITY_TYPE; + entityType?: EntityTypeValue; entityId: string; entityName?: string; }; @@ -44,7 +44,7 @@ export const initialState: ExplorerReduxState = { export const setEntityInfo = ( state: ExplorerReduxState, - action: ReduxAction<{ entityId: string; entityType: ENTITY_TYPE }>, + action: ReduxAction<{ entityId: string; entityType: EntityTypeValue }>, ) => ({ ...state, entityInfo: { diff --git a/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx b/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx index 04a00accf0..621a016ceb 100644 --- a/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx +++ b/app/client/src/ce/utils/BusinessFeatures/permissionPageHelpers.tsx @@ -40,6 +40,7 @@ import { hasExecuteActionPermission as hasExecuteActionPermission_EE } from "@ap import { hasAuditLogsReadPermission as hasAuditLogsReadPermission_CE } from "ce/utils/permissionHelpers"; import { hasAuditLogsReadPermission as hasAuditLogsReadPermission_EE } from "@appsmith/utils/permissionHelpers"; +import { EditorNames } from "@appsmith/hooks"; export const getHasCreateWorkspacePermission = ( isEnabled: boolean, @@ -153,13 +154,19 @@ export const getHasAuditLogsReadPermission = ( else return hasAuditLogsReadPermission_CE(permissions); }; -export const hasCreateDSActionPermissionInApp = ( - isEnabled: boolean, - dsPermissions?: string[], - pagePermissions?: string[], -) => { - return ( - getHasCreateDatasourceActionPermission(isEnabled, dsPermissions) && - getHasCreateActionPermission(isEnabled, pagePermissions) - ); +export const hasCreateDSActionPermissionInApp = ({ + dsPermissions, + editorType, + isEnabled, + pagePermissions, +}: { + dsPermissions?: string[]; + editorType?: string; + isEnabled: boolean; + pagePermissions?: string[]; +}) => { + return !editorType || editorType === EditorNames.APPLICATION + ? getHasCreateDatasourceActionPermission(isEnabled, dsPermissions) && + getHasCreateActionPermission(isEnabled, pagePermissions) + : getHasCreateDatasourceActionPermission(isEnabled, dsPermissions); }; diff --git a/app/client/src/ce/utils/FilterInternalProperties/getEntityPeekData.ts b/app/client/src/ce/utils/FilterInternalProperties/getEntityPeekData.ts index d6ac292afe..8d2f9c408f 100644 --- a/app/client/src/ce/utils/FilterInternalProperties/getEntityPeekData.ts +++ b/app/client/src/ce/utils/FilterInternalProperties/getEntityPeekData.ts @@ -1,4 +1,4 @@ -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { ActionEntity, WidgetEntity, @@ -24,13 +24,13 @@ export const getEntityPeekData: Record< configTree: ConfigTree; }) => unknown > = { - [ENTITY_TYPE_VALUE.ACTION]: ({ dataTree, objectName }) => { + [ENTITY_TYPE.ACTION]: ({ dataTree, objectName }) => { return getActionChildrenPeekData(objectName, dataTree)?.peekData; }, - [ENTITY_TYPE_VALUE.APPSMITH]: ({ dataTree }) => { + [ENTITY_TYPE.APPSMITH]: ({ dataTree }) => { return getAppsmithPeekData(dataTree).peekData; }, - [ENTITY_TYPE_VALUE.JSACTION]: ({ dataTree, dataTreeEntity, jsActions }) => { + [ENTITY_TYPE.JSACTION]: ({ dataTree, dataTreeEntity, jsActions }) => { const entity = dataTreeEntity as ActionEntity; const jsAction = jsActions.find( (jsAction) => jsAction.config.id === entity.actionId, @@ -39,7 +39,7 @@ export const getEntityPeekData: Record< ? getJsActionPeekData(jsAction, dataTree)?.peekData : entity; }, - [ENTITY_TYPE_VALUE.WIDGET]: ({ + [ENTITY_TYPE.WIDGET]: ({ configTree, dataTree, dataTreeEntity, diff --git a/app/client/src/ce/utils/autocomplete/entityDefGeneratorMap.ts b/app/client/src/ce/utils/autocomplete/entityDefGeneratorMap.ts index 6aed38df67..b577541dff 100644 --- a/app/client/src/ce/utils/autocomplete/entityDefGeneratorMap.ts +++ b/app/client/src/ce/utils/autocomplete/entityDefGeneratorMap.ts @@ -5,7 +5,7 @@ import { type ActionEntity, type AppsmithEntity, type JSActionEntity, - ENTITY_TYPE_VALUE, + ENTITY_TYPE, } from "@appsmith/entities/DataTree/types"; import type { ConfigTree, @@ -41,7 +41,7 @@ export type EntityDefGeneratorMap = Record< >; export const entityDefGeneratorMap: EntityDefGeneratorMap = { - [ENTITY_TYPE_VALUE.ACTION]: (props) => { + [ENTITY_TYPE.ACTION]: (props) => { const { def, entity, entityMap, entityName, extraDefsToDefine } = props; def[entityName] = entityDefinitions.ACTION( entity as ActionEntity, @@ -49,22 +49,22 @@ export const entityDefGeneratorMap: EntityDefGeneratorMap = { ); flattenDef(def, entityName); entityMap.set(entityName, { - type: ENTITY_TYPE_VALUE.ACTION, + type: ENTITY_TYPE.ACTION, subType: "ACTION", }); }, - [ENTITY_TYPE_VALUE.APPSMITH]: (props) => { + [ENTITY_TYPE.APPSMITH]: (props) => { const { def, entity, entityMap, extraDefsToDefine } = props; def.appsmith = entityDefinitions.APPSMITH( entity as AppsmithEntity, extraDefsToDefine, ); entityMap.set("appsmith", { - type: ENTITY_TYPE_VALUE.APPSMITH, - subType: ENTITY_TYPE_VALUE.APPSMITH, + type: ENTITY_TYPE.APPSMITH, + subType: ENTITY_TYPE.APPSMITH, }); }, - [ENTITY_TYPE_VALUE.JSACTION]: (props) => { + [ENTITY_TYPE.JSACTION]: (props) => { const { configTree, def, @@ -97,11 +97,11 @@ export const entityDefGeneratorMap: EntityDefGeneratorMap = { def[entityName] = jsPropertiesDef; entityMap.set(entityName, { - type: ENTITY_TYPE_VALUE.JSACTION, + type: ENTITY_TYPE.JSACTION, subType: "JSACTION", }); }, - [ENTITY_TYPE_VALUE.WIDGET]: (props) => { + [ENTITY_TYPE.WIDGET]: (props) => { const { configTree, def, @@ -132,7 +132,7 @@ export const entityDefGeneratorMap: EntityDefGeneratorMap = { flattenDef(def, entityName); entityMap.set(entityName, { - type: ENTITY_TYPE_VALUE.WIDGET, + type: ENTITY_TYPE.WIDGET, subType: widgetType, }); } diff --git a/app/client/src/ce/utils/getEntityPayloadInfo.ts b/app/client/src/ce/utils/getEntityPayloadInfo.ts index 1552f4714b..be68792e9e 100644 --- a/app/client/src/ce/utils/getEntityPayloadInfo.ts +++ b/app/client/src/ce/utils/getEntityPayloadInfo.ts @@ -5,7 +5,7 @@ import type { } from "@appsmith/entities/DataTree/types"; import { type WidgetEntityConfig, - ENTITY_TYPE_VALUE, + ENTITY_TYPE, } from "@appsmith/entities/DataTree/types"; import type { PluginType } from "entities/Action"; @@ -17,7 +17,7 @@ export const getEntityPayloadInfo: Record< pluginType?: PluginType | string; } > = { - [ENTITY_TYPE_VALUE.WIDGET]: (entityConfig) => { + [ENTITY_TYPE.WIDGET]: (entityConfig) => { const config = entityConfig as WidgetEntityConfig; return { iconId: config.widgetId, @@ -25,7 +25,7 @@ export const getEntityPayloadInfo: Record< pluginType: config.type, }; }, - [ENTITY_TYPE_VALUE.JSACTION]: (entityConfig) => { + [ENTITY_TYPE.JSACTION]: (entityConfig) => { const config = entityConfig as JSActionEntityConfig; return { iconId: config.actionId, @@ -33,7 +33,7 @@ export const getEntityPayloadInfo: Record< pluginType: config.pluginType, }; }, - [ENTITY_TYPE_VALUE.ACTION]: (entityConfig) => { + [ENTITY_TYPE.ACTION]: (entityConfig) => { const config = entityConfig as ActionEntityConfig; return { iconId: config.pluginId, diff --git a/app/client/src/ce/workers/Evaluation/evaluationUtils.test.ts b/app/client/src/ce/workers/Evaluation/evaluationUtils.test.ts index 802feace21..a5159dec45 100644 --- a/app/client/src/ce/workers/Evaluation/evaluationUtils.test.ts +++ b/app/client/src/ce/workers/Evaluation/evaluationUtils.test.ts @@ -10,7 +10,7 @@ import type { JSActionEntity, } from "@appsmith/entities/DataTree/types"; import { - ENTITY_TYPE_VALUE, + ENTITY_TYPE, EvaluationSubstitutionType, } from "entities/DataTree/dataTreeFactory"; import type { @@ -64,7 +64,7 @@ const BASE_WIDGET: WidgetEntity = { type: "SKELETON_WIDGET", parentId: "0", version: 1, - ENTITY_TYPE: ENTITY_TYPE_VALUE.WIDGET, + ENTITY_TYPE: ENTITY_TYPE.WIDGET, meta: {}, }; @@ -76,7 +76,7 @@ const BASE_WIDGET_CONFIG: WidgetEntityConfig = { reactivePaths: {}, triggerPaths: {}, validationPaths: {}, - ENTITY_TYPE: ENTITY_TYPE_VALUE.WIDGET, + ENTITY_TYPE: ENTITY_TYPE.WIDGET, privateWidgets: {}, propertyOverrideDependency: {}, overridingPropertyPaths: {}, @@ -480,7 +480,7 @@ describe("4. translateDiffEvent", () => { diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, { JsObject: { - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, } as unknown as DataTreeEntity, }), ), @@ -861,7 +861,7 @@ describe("convertJSFunctionsToString", () => { }, name: "JSObject1", actionId: "63ef4cb1a01b764626f2a6e5", - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, pluginType: PluginType.JS, bindingPaths: { body: EvaluationSubstitutionType.SMART_SUBSTITUTE, @@ -884,7 +884,7 @@ describe("convertJSFunctionsToString", () => { }, }, JSObject2: { - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, meta: { myFun1: { arguments: [], @@ -942,7 +942,7 @@ describe("convertJSFunctionsToString", () => { JSObject1: { myFun1: JSObject1MyFun1, body: 'export default {\nmyFun1: ()=>{ \n\treturn "name"\n} \n}', - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, actionId: "63ef4cb1a01b764626f2a6e5", }, @@ -952,7 +952,7 @@ describe("convertJSFunctionsToString", () => { myFun1: JSObject2MyFun1, myFun2: JSObject2MyFun2, body: "export default {\n\tmyVar1: [],\n\tmyVar2: {},\n\tmyFun1: () => {\n\t\t//write code here\n\t},\n\tmyFun2: async () => {\n\t\t//use async-await or promises\n\t}\n}", - ENTITY_TYPE: ENTITY_TYPE_VALUE.JSACTION, + ENTITY_TYPE: ENTITY_TYPE.JSACTION, actionId: "63f78437d1a4ef55755952f1", }, diff --git a/app/client/src/ce/workers/Evaluation/evaluationUtils.ts b/app/client/src/ce/workers/Evaluation/evaluationUtils.ts index 258ab304e3..b9d5223354 100644 --- a/app/client/src/ce/workers/Evaluation/evaluationUtils.ts +++ b/app/client/src/ce/workers/Evaluation/evaluationUtils.ts @@ -13,7 +13,7 @@ import type { DataTree, ConfigTree, } from "entities/DataTree/dataTreeTypes"; -import { ENTITY_TYPE_VALUE } from "@appsmith/entities/DataTree/types"; +import { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; import _, { difference, find, get, has, isEmpty, isNil, set } from "lodash"; import type { WidgetTypeConfigMap } from "WidgetProvider/factory"; import { PluginType } from "entities/Action"; @@ -357,7 +357,7 @@ export function isWidget( return ( typeof entity === "object" && "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.WIDGET + entity.ENTITY_TYPE === ENTITY_TYPE.WIDGET ); } @@ -373,7 +373,7 @@ export function isAction( return ( typeof entity === "object" && "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.ACTION + entity.ENTITY_TYPE === ENTITY_TYPE.ACTION ); } @@ -383,7 +383,7 @@ export function isAppsmithEntity( return ( typeof entity === "object" && "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.APPSMITH + entity.ENTITY_TYPE === ENTITY_TYPE.APPSMITH ); } @@ -391,7 +391,7 @@ export function isJSAction(entity: DataTreeEntity): entity is JSActionEntity { return ( typeof entity === "object" && "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.JSACTION + entity.ENTITY_TYPE === ENTITY_TYPE.JSACTION ); } /** @@ -408,7 +408,7 @@ export function isJSActionConfig( return ( typeof entity === "object" && "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.JSACTION + entity.ENTITY_TYPE === ENTITY_TYPE.JSACTION ); } @@ -416,7 +416,7 @@ export function isJSObject(entity: DataTreeEntity): entity is JSActionEntity { return ( typeof entity === "object" && "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.JSACTION && + entity.ENTITY_TYPE === ENTITY_TYPE.JSACTION && "pluginType" in entity && entity.pluginType === PluginType.JS ); diff --git a/app/client/src/ce/workers/Evaluation/getEntityForEvalContextMap.ts b/app/client/src/ce/workers/Evaluation/getEntityForEvalContextMap.ts index 3e3ab3c7fb..8f9c9f3b77 100644 --- a/app/client/src/ce/workers/Evaluation/getEntityForEvalContextMap.ts +++ b/app/client/src/ce/workers/Evaluation/getEntityForEvalContextMap.ts @@ -1,4 +1,4 @@ -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { DataTreeEntity } from "entities/DataTree/dataTreeTypes"; import { getJSActionForEvalContext } from "workers/Evaluation/getJSActionForEvalContext"; @@ -6,7 +6,7 @@ export const getEntityForEvalContextMap: Record< string, (entityName: string, entity: DataTreeEntity) => unknown > = { - [ENTITY_TYPE_VALUE.JSACTION]: (entityName, entity) => { + [ENTITY_TYPE.JSACTION]: (entityName, entity) => { return getJSActionForEvalContext(entityName, entity); }, }; diff --git a/app/client/src/ce/workers/common/DependencyMap/utils/getEntityDependenciesByType.ts b/app/client/src/ce/workers/common/DependencyMap/utils/getEntityDependenciesByType.ts index da9056f717..e4324c63ad 100644 --- a/app/client/src/ce/workers/common/DependencyMap/utils/getEntityDependenciesByType.ts +++ b/app/client/src/ce/workers/common/DependencyMap/utils/getEntityDependenciesByType.ts @@ -3,7 +3,7 @@ import { getEntityNameAndPropertyPath, isATriggerPath, } from "@appsmith/workers/Evaluation/evaluationUtils"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { ActionEntity, ActionEntityConfig, @@ -20,7 +20,7 @@ import type { DataTreeEntityObject } from "@appsmith/entities/DataTree/types"; import { getDependencyFromEntityPath } from "workers/common/DependencyMap/utils/getEntityDependencies"; export const getDependencies = { - [ENTITY_TYPE_VALUE.ACTION]: ( + [ENTITY_TYPE.ACTION]: ( entity: DataTreeEntityObject, entityConfig: DataTreeEntityConfig, allKeys: Record, @@ -31,7 +31,7 @@ export const getDependencies = { allKeys, ); }, - [ENTITY_TYPE_VALUE.JSACTION]: ( + [ENTITY_TYPE.JSACTION]: ( entity: DataTreeEntityObject, entityConfig: DataTreeEntityConfig, allKeys: Record, @@ -42,7 +42,7 @@ export const getDependencies = { allKeys, ); }, - [ENTITY_TYPE_VALUE.WIDGET]: ( + [ENTITY_TYPE.WIDGET]: ( entity: DataTreeEntityObject, entityConfig: DataTreeEntityConfig, ) => { @@ -166,7 +166,7 @@ export function getActionDependencies( } export const getPathDependencies = { - [ENTITY_TYPE_VALUE.ACTION]: ( + [ENTITY_TYPE.ACTION]: ( entity: DataTreeEntity, entityConfig: DataTreeEntityConfig, fullPropertyPath: string, @@ -179,7 +179,7 @@ export const getPathDependencies = { allKeys, ); }, - [ENTITY_TYPE_VALUE.JSACTION]: ( + [ENTITY_TYPE.JSACTION]: ( entity: DataTreeEntity, entityConfig: DataTreeEntityConfig, fullPropertyPath: string, @@ -192,7 +192,7 @@ export const getPathDependencies = { allKeys, ); }, - [ENTITY_TYPE_VALUE.WIDGET]: ( + [ENTITY_TYPE.WIDGET]: ( entity: DataTreeEntity, entityConfig: DataTreeEntityConfig, fullPropertyPath: string, diff --git a/app/client/src/components/editorComponents/ActionCreator/helpers.tsx b/app/client/src/components/editorComponents/ActionCreator/helpers.tsx index 8d743418d4..b9af4dbb39 100644 --- a/app/client/src/components/editorComponents/ActionCreator/helpers.tsx +++ b/app/client/src/components/editorComponents/ActionCreator/helpers.tsx @@ -110,7 +110,7 @@ export function getFieldFromValue( const entity = dataTree && dataTree[entityProps.entityName]; if (entity && "ENTITY_TYPE" in entity) { - if (isAction(entity)) { + if (isAction(entity as DataTreeEntity)) { // get fields for API action return getActionEntityFields( fields, diff --git a/app/client/src/components/editorComponents/ActionCreator/types.ts b/app/client/src/components/editorComponents/ActionCreator/types.ts index cff39c8abb..83110b7959 100644 --- a/app/client/src/components/editorComponents/ActionCreator/types.ts +++ b/app/client/src/components/editorComponents/ActionCreator/types.ts @@ -3,7 +3,10 @@ import type { TreeDropdownOption, IconName, } from "design-system-old"; -import type { ENTITY_TYPE, MetaArgs } from "@appsmith/entities/DataTree/types"; +import type { + EntityTypeValue, + MetaArgs, +} from "@appsmith/entities/DataTree/types"; import type React from "react"; import type { AdditionalDynamicDataTree } from "utils/autocomplete/customTreeTypeDefCreator"; import type { FieldType, ViewTypes, AppsmithFunction } from "./constants"; @@ -157,7 +160,7 @@ export interface AppsmithFunctionConfigType { export interface DataTreeForActionCreator { [key: string]: { - ENTITY_TYPE?: ENTITY_TYPE; + ENTITY_TYPE?: EntityTypeValue; meta?: Record; }; } diff --git a/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts b/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts index a146df613d..bc8aceac9f 100644 --- a/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts +++ b/app/client/src/components/editorComponents/CodeEditor/EditorConfig.ts @@ -1,5 +1,5 @@ import type CodeMirror from "codemirror"; -import type { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; +import type { EntityTypeValue } from "@appsmith/entities/DataTree/types"; import type { DataTree } from "entities/DataTree/dataTreeTypes"; import type { AutocompleteDataType } from "utils/autocomplete/AutocompleteDataType"; import type { EntityNavigationData } from "selectors/navigationSelectors"; @@ -55,7 +55,7 @@ export const EditorThemes: Record = { export interface FieldEntityInformation { entityName?: string; expectedType?: AutocompleteDataType; - entityType?: ENTITY_TYPE; + entityType?: EntityTypeValue; entityId?: string; propertyPath?: string; isTriggerPath?: boolean; diff --git a/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts b/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts index 801306adb0..ea3fc9d6ee 100644 --- a/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts +++ b/app/client/src/components/editorComponents/CodeEditor/commandsHelper.ts @@ -8,7 +8,7 @@ import { generateQuickCommands } from "./generateQuickCommands"; import type { Datasource } from "entities/Datasource"; import AnalyticsUtil from "utils/AnalyticsUtil"; import log from "loglevel"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import { checkIfCursorInsideBinding } from "components/editorComponents/CodeEditor/codeEditorUtils"; import type { SlashCommandPayload } from "entities/Action"; import type { FeatureFlags } from "@appsmith/entities/FeatureFlag"; @@ -51,7 +51,7 @@ export const slashCommandHintHelper: HintHelper = ( // @ts-expect-error: Types are not available editor.closeHint(); const { entityType } = entityInfo; - const currentEntityType = entityType || ENTITY_TYPE_VALUE.ACTION; + const currentEntityType = entityType || ENTITY_TYPE.ACTION; const filteredEntitiesForSuggestions = entitiesForSuggestions.filter( (entity) => { return entity.type !== currentEntityType; diff --git a/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx b/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx index 0b8904348a..4f0d8f8985 100644 --- a/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx +++ b/app/client/src/components/editorComponents/CodeEditor/generateQuickCommands.tsx @@ -4,7 +4,7 @@ import type { CommandsCompletion } from "utils/autocomplete/CodemirrorTernServic import ReactDOM from "react-dom"; import type { SlashCommandPayload } from "entities/Action"; import { SlashCommand } from "entities/Action"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import { EntityIcon, JsFileIconV2 } from "pages/Editor/Explorer/ExplorerIcons"; import { getAssetUrl } from "@appsmith/utils/airgapHelpers"; import type { FeatureFlags } from "@appsmith/entities/FeatureFlag"; @@ -15,7 +15,7 @@ import AnalyticsUtil from "utils/AnalyticsUtil"; import BetaCard from "../BetaCard"; import type { NavigationData } from "selectors/navigationSelectors"; import type { AIEditorContext } from "@appsmith/components/editorComponents/GPT"; -import type { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; +import type { EntityTypeValue } from "@appsmith/entities/DataTree/types"; export enum Shortcuts { PLUS = "PLUS", @@ -116,7 +116,7 @@ export function Command(props: { export const generateQuickCommands = ( entitiesForSuggestions: NavigationData[], - currentEntityType: ENTITY_TYPE, + currentEntityType: EntityTypeValue, searchText: string, { aiContext, @@ -160,19 +160,19 @@ export const generateQuickCommands = ( const name = suggestion.name; return { text: - suggestion.type === ENTITY_TYPE_VALUE.ACTION + suggestion.type === ENTITY_TYPE.ACTION ? `{{${name}.data}}` - : suggestion.type === ENTITY_TYPE_VALUE.JSACTION + : suggestion.type === ENTITY_TYPE.JSACTION ? `{{${name}.}}` : `{{${name}}}`, displayText: `${name}`, className: "CodeMirror-commands", data: suggestion, - triggerCompletionsPostPick: suggestion.type !== ENTITY_TYPE_VALUE.ACTION, + triggerCompletionsPostPick: suggestion.type !== ENTITY_TYPE.ACTION, render: (element: HTMLElement, _: unknown, data: CommandsCompletion) => { let icon = null; const completionData = data.data as NavigationData; - if (completionData.type === ENTITY_TYPE_VALUE.JSACTION) { + if (completionData.type === ENTITY_TYPE.JSACTION) { icon = JsFileIconV2(16, 16); } else if ( completionData.pluginId && @@ -246,7 +246,7 @@ export const generateQuickCommands = ( commonCommands.unshift(askGPT); } - if (currentEntityType !== ENTITY_TYPE_VALUE.JSACTION) { + if (currentEntityType !== ENTITY_TYPE.JSACTION) { // New binding command is not applicable in JS Objects commonCommands.push(newBinding); } @@ -259,7 +259,7 @@ export const generateQuickCommands = ( filteredCommands.push(...commonCommandsMatchingSearchText); - if (currentEntityType !== ENTITY_TYPE_VALUE.JSACTION) { + if (currentEntityType !== ENTITY_TYPE.JSACTION) { // Binding suggestions and create query commands are not applicable in JS Objects // Get top 5 matching suggestions @@ -277,7 +277,7 @@ export const generateQuickCommands = ( filteredCommands.push(...suggestionsMatchingSearchText); } - if (currentEntityType === ENTITY_TYPE_VALUE.WIDGET) { + if (currentEntityType === ENTITY_TYPE.WIDGET) { const createNewCommands: CommandsCompletion[] = []; createNewCommands.push(...datasourceCommands); diff --git a/app/client/src/components/editorComponents/CodeEditor/hintHelpers.ts b/app/client/src/components/editorComponents/CodeEditor/hintHelpers.ts index 11f793aba1..03f8a5a5a3 100644 --- a/app/client/src/components/editorComponents/CodeEditor/hintHelpers.ts +++ b/app/client/src/components/editorComponents/CodeEditor/hintHelpers.ts @@ -8,7 +8,7 @@ import { checkIfCursorInsideBinding, isCursorOnEmptyToken, } from "components/editorComponents/CodeEditor/codeEditorUtils"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import { isEmpty, isString } from "lodash"; import type { getAllDatasourceTableKeys } from "@appsmith/selectors/entitiesSelector"; import { @@ -48,7 +48,7 @@ export const bindingHintHelper: HintHelper = (editor: CodeMirror.Editor) => { const entityType = entityInformation?.entityType; let shouldShow = false; - if (entityType === ENTITY_TYPE_VALUE.JSACTION) { + if (entityType === ENTITY_TYPE.JSACTION) { if (additionalData?.enableAIAssistance) { shouldShow = !isAISlashCommand(editor); } else { diff --git a/app/client/src/components/editorComponents/CodeEditor/index.tsx b/app/client/src/components/editorComponents/CodeEditor/index.tsx index 3818364a7f..50f6e25daa 100644 --- a/app/client/src/components/editorComponents/CodeEditor/index.tsx +++ b/app/client/src/components/editorComponents/CodeEditor/index.tsx @@ -30,7 +30,7 @@ import type { WrappedFieldInputProps } from "redux-form"; import _, { debounce, isEqual, isNumber } from "lodash"; import scrollIntoView from "scroll-into-view-if-needed"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import type { EvaluationSubstitutionType } from "@appsmith/entities/DataTree/types"; import type { DataTree } from "entities/DataTree/dataTreeTypes"; import { Skin } from "constants/DefaultTheme"; @@ -550,8 +550,7 @@ class CodeEditor extends Component { getEditorIdentifier(this.props) !== getEditorIdentifier(prevProps); const entityInformation = this.getEntityInformation(); - const isWidgetType = - entityInformation.entityType === ENTITY_TYPE_VALUE.WIDGET; + const isWidgetType = entityInformation.entityType === ENTITY_TYPE.WIDGET; const hasFocusedValueChanged = getEditorIdentifier(this.props) !== this.props.focusedProperty; @@ -1010,7 +1009,7 @@ class CodeEditor extends Component { } if (navigationData.url) { - if (navigationData.type === ENTITY_TYPE_VALUE.ACTION) { + if (navigationData.type === ENTITY_TYPE.ACTION) { AnalyticsUtil.logEvent("EDIT_ACTION_CLICK", { actionId: navigationData?.id, datasourceId: navigationData?.datasourceId, diff --git a/app/client/src/components/editorComponents/GlobalSearch/utils.tsx b/app/client/src/components/editorComponents/GlobalSearch/utils.tsx index 34f4d8edb0..85a50725f6 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/utils.tsx +++ b/app/client/src/components/editorComponents/GlobalSearch/utils.tsx @@ -8,7 +8,7 @@ import type { ValidationTypes } from "constants/WidgetValidation"; import type { Datasource } from "entities/Datasource"; import { PluginPackageName, PluginType } from "entities/Action"; import type { WidgetType } from "constants/WidgetConstants"; -import type { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; +import type { EntityTypeValue } from "entities/DataTree/dataTreeFactory"; import { getPluginByPackageName } from "@appsmith/selectors/entitiesSelector"; import type { AppState } from "@appsmith/reducers"; import WidgetFactory from "WidgetProvider/factory"; @@ -91,19 +91,20 @@ export interface SnippetBody { shortTitle?: string; } -export type FilterEntity = WidgetType | ENTITY_TYPE; +export type FilterEntity = WidgetType | EntityTypeValue; -export const filterEntityTypeLabels: Partial> = { - ACTION: "All Queries", - WIDGET: "All Widgets", - JSACTION: "JS Objects", -}; +export const filterEntityTypeLabels: Partial> = + { + ACTION: "All Queries", + WIDGET: "All Widgets", + JSACTION: "JS Objects", + }; export const getSnippetFilterLabel = (state: AppState, label: string) => { return ( WidgetFactory.widgetConfigMap.get(label as WidgetType)?.widgetName || getPluginByPackageName(state, label)?.name || - filterEntityTypeLabels[label as ENTITY_TYPE] || + filterEntityTypeLabels[label as EntityTypeValue] || label ); }; diff --git a/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx b/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx index bb49c11bf8..40e76fb901 100644 --- a/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx +++ b/app/client/src/components/editorComponents/form/fields/EmbeddedDatasourcePathField.tsx @@ -35,7 +35,7 @@ import { Indices } from "constants/Layers"; import { getExpectedValue } from "utils/validation/common"; import { ValidationTypes } from "constants/WidgetValidation"; import type { DataTree } from "entities/DataTree/dataTreeTypes"; -import { ENTITY_TYPE_VALUE } from "entities/DataTree/dataTreeFactory"; +import { ENTITY_TYPE } from "entities/DataTree/dataTreeFactory"; import { getDataTree } from "selectors/dataTreeSelectors"; import type { KeyValuePair } from "entities/Action"; import equal from "fast-deep-equal/es6"; @@ -424,10 +424,7 @@ class EmbeddedDatasourcePathComponent extends React.Component< if (!entity) return ""; - if ( - "ENTITY_TYPE" in entity && - entity.ENTITY_TYPE === ENTITY_TYPE_VALUE.ACTION - ) { + if ("ENTITY_TYPE" in entity && entity.ENTITY_TYPE === ENTITY_TYPE.ACTION) { let evaluatedPath = "path" in entity.config ? entity.config.path : ""; if (evaluatedPath) { diff --git a/app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx b/app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx index c673a0684f..297e0e3073 100644 --- a/app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx +++ b/app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx @@ -7,7 +7,7 @@ import apiActionEditorConfig from "constants/AppsmithActionConstants/formConfig/ import saasActionSettingsConfig from "constants/AppsmithActionConstants/formConfig/GoogleSheetsSettingsConfig"; import apiActionDependencyConfig from "constants/AppsmithActionConstants/formConfig/ApiDependencyConfigs"; import apiActionDatasourceFormButtonConfig from "constants/AppsmithActionConstants/formConfig/ApiDatasourceFormsButtonConfig"; -import type { ENTITY_TYPE } from "@appsmith/entities/DataTree/types"; +import type { EntityTypeValue } from "@appsmith/entities/DataTree/types"; export interface ExecuteActionPayloadEvent { type: EventType; @@ -21,7 +21,7 @@ export interface ExecutionResult { export interface TriggerSource { id: string; name: string; - entityType?: ENTITY_TYPE; + entityType?: EntityTypeValue; collectionId?: string; isJSAction?: boolean; actionId?: string; diff --git a/app/client/src/ee/entities/DataTree/types.ts b/app/client/src/ee/entities/DataTree/types.ts index 1accdbad9e..f2079897f5 100644 --- a/app/client/src/ee/entities/DataTree/types.ts +++ b/app/client/src/ee/entities/DataTree/types.ts @@ -1,8 +1,10 @@ export * from "ce/entities/DataTree/types"; import { ENTITY_TYPE as CE_ENTITY_TYPE } from "ce/entities/DataTree/types"; -export type ENTITY_TYPE = CE_ENTITY_TYPE; - -export const ENTITY_TYPE_VALUE = { +export const ENTITY_TYPE = { ...CE_ENTITY_TYPE, -}; + MODULE_INSTANCE: "MODULE_INSTANCE", +} as const; + +type ValueOf = T[keyof T]; +export type EntityTypeValue = ValueOf; diff --git a/app/client/src/entities/DataTree/dataTreeFactory.ts b/app/client/src/entities/DataTree/dataTreeFactory.ts index d422abafd3..aedfea2bcb 100644 --- a/app/client/src/entities/DataTree/dataTreeFactory.ts +++ b/app/client/src/entities/DataTree/dataTreeFactory.ts @@ -3,14 +3,14 @@ import { generateDataTreeJSAction } from "@appsmith/entities/DataTree/dataTreeJS import { generateDataTreeWidget } from "entities/DataTree/dataTreeWidget"; import log from "loglevel"; import { - ENTITY_TYPE_VALUE, + ENTITY_TYPE, EvaluationSubstitutionType, } from "@appsmith/entities/DataTree/types"; import { generateDataTreeModuleInputs } from "@appsmith/entities/DataTree/utils"; import type { DataTreeSeed, AppsmithEntity, - ENTITY_TYPE, + EntityTypeValue, } from "@appsmith/entities/DataTree/types"; import type { unEvalAndConfigTree, @@ -110,8 +110,7 @@ export class DataTreeFactory { store: appData.store, theme, } as AppsmithEntity; - (dataTree.appsmith as AppsmithEntity).ENTITY_TYPE = - ENTITY_TYPE_VALUE.APPSMITH; + (dataTree.appsmith as AppsmithEntity).ENTITY_TYPE = ENTITY_TYPE.APPSMITH; const startMetaWidgets = performance.now(); @@ -141,5 +140,5 @@ export class DataTreeFactory { } } -export { ENTITY_TYPE_VALUE, EvaluationSubstitutionType }; -export type { ENTITY_TYPE }; +export { ENTITY_TYPE, EvaluationSubstitutionType }; +export type { EntityTypeValue }; diff --git a/app/client/src/entities/DataTree/dataTreeWidget.test.ts b/app/client/src/entities/DataTree/dataTreeWidget.test.ts index 1cdad2d850..3c360285b7 100644 --- a/app/client/src/entities/DataTree/dataTreeWidget.test.ts +++ b/app/client/src/entities/DataTree/dataTreeWidget.test.ts @@ -4,7 +4,7 @@ import { getSetterConfig, } from "entities/DataTree/dataTreeWidget"; import { - ENTITY_TYPE_VALUE, + ENTITY_TYPE, EvaluationSubstitutionType, } from "entities/DataTree/dataTreeFactory"; import WidgetFactory from "WidgetProvider/factory"; @@ -226,7 +226,7 @@ describe("generateDataTreeWidget", () => { topRow: 0, widgetId: "123", widgetName: "Input1", - ENTITY_TYPE: ENTITY_TYPE_VALUE.WIDGET, + ENTITY_TYPE: ENTITY_TYPE.WIDGET, componentWidth: 0, componentHeight: 0, defaultText: "", @@ -248,7 +248,7 @@ describe("generateDataTreeWidget", () => { }; const expectedConfig = { - ENTITY_TYPE: ENTITY_TYPE_VALUE.WIDGET, + ENTITY_TYPE: ENTITY_TYPE.WIDGET, widgetId: "123", bindingPaths, reactivePaths: { diff --git a/app/client/src/entities/DataTree/dataTreeWidget.ts b/app/client/src/entities/DataTree/dataTreeWidget.ts index 7212413591..cfe6484c37 100644 --- a/app/client/src/entities/DataTree/dataTreeWidget.ts +++ b/app/client/src/entities/DataTree/dataTreeWidget.ts @@ -8,7 +8,7 @@ import type { WidgetEntityConfig, WidgetEntity, } from "@appsmith/entities/DataTree/types"; -import { ENTITY_TYPE_VALUE } from "./dataTreeFactory"; +import { ENTITY_TYPE } from "./dataTreeFactory"; import type { OverridingPropertyPaths, PropertyOverrideDependency, @@ -295,7 +295,7 @@ const generateDataTreeWidgetWithoutMeta = ( const dataTreeWidgetWithoutMetaProps = _.merge( { - ENTITY_TYPE: ENTITY_TYPE_VALUE.WIDGET, + ENTITY_TYPE: ENTITY_TYPE.WIDGET, }, _.omit(widget, widgetPathsToOmit), unInitializedDefaultProps, @@ -329,7 +329,7 @@ const generateDataTreeWidgetWithoutMeta = ( triggerPaths, validationPaths, dependencyMap, - ENTITY_TYPE: ENTITY_TYPE_VALUE.WIDGET, + ENTITY_TYPE: ENTITY_TYPE.WIDGET, privateWidgets: { ...widget.privateWidgets, }, diff --git a/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx b/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx index 59074acf28..3892634ca4 100644 --- a/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx +++ b/app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx @@ -1,3 +1,4 @@ +/* DO NOT INTRODUCE PAGE AND APPLICATION DEPENDENCIES IN THIS COMPONENT */ import React, { useState } from "react"; import FormTitle from "./FormTitle"; import { getAssetUrl } from "@appsmith/utils/airgapHelpers"; diff --git a/app/client/src/pages/Editor/DataSourceEditor/hooks.ts b/app/client/src/pages/Editor/DataSourceEditor/hooks.ts index 4deddac244..9a445bc9fd 100644 --- a/app/client/src/pages/Editor/DataSourceEditor/hooks.ts +++ b/app/client/src/pages/Editor/DataSourceEditor/hooks.ts @@ -23,6 +23,8 @@ import { getPagePermissions, } from "selectors/editorSelectors"; import { get } from "lodash"; +import { useEditorType } from "@appsmith/hooks"; +import history from "utils/history"; interface FetchPreviewData { datasourceId: string; @@ -146,15 +148,18 @@ export const useShowPageGenerationOnHeader = ( getGenerateCRUDEnabledPluginMap, ); + const editorType = useEditorType(history.location.pathname); + const canCreatePages = getHasCreatePagePermission( isGACEnabled, userAppPermissions, ); - const canCreateDatasourceActions = hasCreateDSActionPermissionInApp( - isGACEnabled, - datasourcePermissions, + const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({ + isEnabled: isGACEnabled, + dsPermissions: datasourcePermissions, pagePermissions, - ); + editorType, + }); const canGeneratePage = canCreateDatasourceActions && canCreatePages; diff --git a/app/client/src/pages/Editor/DatasourceInfo/DatasourceStructure.tsx b/app/client/src/pages/Editor/DatasourceInfo/DatasourceStructure.tsx index 84b01264bf..f5c6383588 100644 --- a/app/client/src/pages/Editor/DatasourceInfo/DatasourceStructure.tsx +++ b/app/client/src/pages/Editor/DatasourceInfo/DatasourceStructure.tsx @@ -21,6 +21,8 @@ import { Virtuoso } from "react-virtuoso"; import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; import { FEATURE_FLAG } from "@appsmith/entities/FeatureFlag"; import { hasCreateDSActionPermissionInApp } from "@appsmith/utils/BusinessFeatures/permissionPageHelpers"; +import { useEditorType } from "@appsmith/hooks"; +import history from "utils/history"; interface DatasourceStructureItemProps { dbStructure: DatasourceTable; @@ -62,12 +64,14 @@ const DatasourceStructureItem = memo((props: DatasourceStructureItemProps) => { const datasourcePermissions = datasource?.userPermissions || []; const pagePermissions = useSelector(getPagePermissions); const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); + const editorType = useEditorType(history.location.pathname); - const canCreateDatasourceActions = hasCreateDSActionPermissionInApp( - isFeatureEnabled, - datasourcePermissions, + const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({ + isEnabled: isFeatureEnabled, + dsPermissions: datasourcePermissions, pagePermissions, - ); + editorType, + }); const onSelect = () => { setActive(false); diff --git a/app/client/src/pages/Editor/DatasourceInfo/DatasourceViewModeSchema.tsx b/app/client/src/pages/Editor/DatasourceInfo/DatasourceViewModeSchema.tsx index 7edd24fd85..ccc3728ce8 100644 --- a/app/client/src/pages/Editor/DatasourceInfo/DatasourceViewModeSchema.tsx +++ b/app/client/src/pages/Editor/DatasourceInfo/DatasourceViewModeSchema.tsx @@ -47,6 +47,8 @@ import { TableWrapper, ViewModeSchemaContainer, } from "./SchemaViewModeCSS"; +import { useEditorType } from "@appsmith/hooks"; +import history from "utils/history"; interface Props { datasource: Datasource; @@ -73,16 +75,19 @@ const DatasourceViewModeSchema = (props: Props) => { const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); + const editorType = useEditorType(history.location.pathname); + const canCreatePages = getHasCreatePagePermission( isFeatureEnabled, userAppPermissions, ); - const canCreateDatasourceActions = hasCreateDSActionPermissionInApp( - isFeatureEnabled, - datasourcePermissions, + const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({ + isEnabled: isFeatureEnabled, + dsPermissions: datasourcePermissions, pagePermissions, - ); + editorType, + }); const applicationId: string = useSelector(getCurrentApplicationId); const { pageId: currentPageId } = useParams(); diff --git a/app/client/src/pages/Editor/DatasourceInfo/GoogleSheetSchema.tsx b/app/client/src/pages/Editor/DatasourceInfo/GoogleSheetSchema.tsx index 4c717d24e6..1117b3d704 100644 --- a/app/client/src/pages/Editor/DatasourceInfo/GoogleSheetSchema.tsx +++ b/app/client/src/pages/Editor/DatasourceInfo/GoogleSheetSchema.tsx @@ -48,6 +48,8 @@ import Entity from "../Explorer/Entity"; import DatasourceField from "./DatasourceField"; import { setEntityCollapsibleState } from "actions/editorContextActions"; import ItemLoadingIndicator from "./ItemLoadingIndicator"; +import { useEditorType } from "@appsmith/hooks"; +import history from "utils/history"; interface Props { datasourceId: string; @@ -343,16 +345,19 @@ function GoogleSheetSchema(props: Props) { const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled); + const editorType = useEditorType(history.location.pathname); + const canCreatePages = getHasCreatePagePermission( isFeatureEnabled, userAppPermissions, ); - const canCreateDatasourceActions = hasCreateDSActionPermissionInApp( - isFeatureEnabled, - datasourcePermissions, + const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({ + isEnabled: isFeatureEnabled, + dsPermissions: datasourcePermissions, pagePermissions, - ); + editorType, + }); const refreshSpreadSheetButton = (option: DropdownOption) => (