From 504436c998e5de2a9b2a773eac1e4235c5ab1978 Mon Sep 17 00:00:00 2001 From: Sanveer Singh Osahan Date: Tue, 16 May 2023 18:40:52 +0530 Subject: [PATCH] chore: Server Side Event for running action (#23379) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Server Side Event to capture run action. Determines if action is user initiated or not. Fixes #23127 #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] Jest - [ ] 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 - [ ] 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 - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: “sneha122” <“sneha@appsmith.com”> --- app/client/src/api/ActionAPI.tsx | 1 + app/client/src/sagas/ActionExecution/PluginActionSaga.ts | 6 ++++++ .../java/com/appsmith/external/dtos/ExecuteActionDTO.java | 2 ++ .../solutions/ce/ActionExecutionSolutionCEImpl.java | 8 +++++++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/client/src/api/ActionAPI.tsx b/app/client/src/api/ActionAPI.tsx index 11c353a6ad..3aac744840 100644 --- a/app/client/src/api/ActionAPI.tsx +++ b/app/client/src/api/ActionAPI.tsx @@ -56,6 +56,7 @@ export interface ExecuteActionRequest extends APIRequest { | Record | Record>> >; + analyticsProperties?: Record; } export type ExecuteActionResponse = ApiResponse & { diff --git a/app/client/src/sagas/ActionExecution/PluginActionSaga.ts b/app/client/src/sagas/ActionExecution/PluginActionSaga.ts index f1349a936c..90bc6b33a6 100644 --- a/app/client/src/sagas/ActionExecution/PluginActionSaga.ts +++ b/app/client/src/sagas/ActionExecution/PluginActionSaga.ts @@ -716,6 +716,8 @@ function* runActionSaga( executePluginActionSaga, id, paginationField, + {}, + true, ); payload = executePluginActionResponse.payload; isError = executePluginActionResponse.isError; @@ -1100,6 +1102,7 @@ function* executePluginActionSaga( actionOrActionId: PageAction | string, paginationField?: PaginationField, params?: Record, + isUserInitiated?: boolean, ) { let pluginAction; let actionId; @@ -1151,6 +1154,9 @@ function* executePluginActionSaga( actionId: actionId, viewMode: appMode === APP_MODE.PUBLISHED, paramProperties: {}, + analyticsProperties: { + isUserInitiated: !!isUserInitiated, + }, }; if (paginationField) { diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/ExecuteActionDTO.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/ExecuteActionDTO.java index 7cb3873eff..7890daa087 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/ExecuteActionDTO.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/dtos/ExecuteActionDTO.java @@ -41,6 +41,8 @@ public class ExecuteActionDTO { Map invertParameterMap; // e.g. {"k1":"Text1.text","k2":"Table1.data", "k3": "Api1.data"} + Map analyticsProperties; + @JsonIgnore long totalReadableByteCount; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java index c47ffec66b..a7ab2e8b14 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java @@ -308,6 +308,7 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE dto.setViewMode(executeActionDTO.getViewMode()); dto.setParamProperties(executeActionDTO.getParamProperties()); dto.setPaginationField(executeActionDTO.getPaginationField()); + dto.setAnalyticsProperties(executeActionDTO.getAnalyticsProperties()); return Mono.empty(); }); } @@ -1043,6 +1044,10 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE paramsList = new ArrayList<>(); } List executionParams = paramsList.stream().map(param -> param.getValue()).collect(Collectors.toList()); + Map analyticsProperties = executeActionDto.getAnalyticsProperties(); + if (analyticsProperties == null) { + analyticsProperties = new HashMap<>(); + } data.putAll(Map.of( "request", request, @@ -1052,7 +1057,8 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE "statusCode", ObjectUtils.defaultIfNull(actionExecutionResult.getStatusCode(), ""), "timeElapsed", timeElapsed, "actionCreated", DateUtils.ISO_FORMATTER.format(action.getCreatedAt()), - "actionId", ObjectUtils.defaultIfNull(action.getId(), "") + "actionId", ObjectUtils.defaultIfNull(action.getId(), ""), + "isUserInitiated", ObjectUtils.defaultIfNull(analyticsProperties.get("isUserInitiated"), false) )); data.putAll(Map.of( FieldName.ACTION_EXECUTION_REQUEST_PARAMS_SIZE, executeActionDto.getTotalReadableByteCount(),