2021-09-08 17:32:22 +00:00
|
|
|
import {
|
|
|
|
|
all,
|
|
|
|
|
select,
|
|
|
|
|
put,
|
|
|
|
|
takeEvery,
|
|
|
|
|
debounce,
|
|
|
|
|
call,
|
|
|
|
|
take,
|
2022-03-17 12:05:17 +00:00
|
|
|
takeLatest,
|
2021-09-08 17:32:22 +00:00
|
|
|
} from "redux-saga/effects";
|
|
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
ReduxActionErrorTypes,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2021-09-08 17:32:22 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentApplicationId,
|
|
|
|
|
getCurrentPageId,
|
2022-05-19 13:13:51 +00:00
|
|
|
getIsSavingEntity,
|
2021-09-08 17:32:22 +00:00
|
|
|
} from "selectors/editorSelectors";
|
|
|
|
|
import { getJSCollection, getJSCollections } from "selectors/entitiesSelector";
|
2022-06-21 13:57:34 +00:00
|
|
|
import {
|
|
|
|
|
JSCollectionData,
|
|
|
|
|
JSCollectionDataState,
|
|
|
|
|
} from "reducers/entityReducers/jsActionsReducer";
|
2022-08-04 05:40:44 +00:00
|
|
|
import { createNewJSFunctionName } from "utils/AppsmithUtils";
|
|
|
|
|
import { getQueryParams } from "utils/URLUtils";
|
2021-09-08 17:32:22 +00:00
|
|
|
import { JSCollection, JSAction } from "entities/JSCollection";
|
|
|
|
|
import { createJSCollectionRequest } from "actions/jsActionActions";
|
|
|
|
|
import history from "utils/history";
|
2021-11-08 06:49:22 +00:00
|
|
|
import { executeFunction } from "./EvaluationsSaga";
|
2021-09-23 07:21:57 +00:00
|
|
|
import { getJSCollectionIdFromURL } from "pages/Editor/Explorer/helpers";
|
2021-09-28 07:31:46 +00:00
|
|
|
import {
|
|
|
|
|
getDifferenceInJSCollection,
|
2021-11-08 06:49:22 +00:00
|
|
|
JSUpdate,
|
2021-09-28 07:31:46 +00:00
|
|
|
pushLogsForObjectUpdate,
|
2021-10-26 12:53:58 +00:00
|
|
|
createDummyJSCollectionActions,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "utils/JSPaneUtils";
|
2022-03-17 12:05:17 +00:00
|
|
|
import JSActionAPI, {
|
2022-06-21 13:57:34 +00:00
|
|
|
JSCollectionCreateUpdateResponse,
|
2022-03-17 12:05:17 +00:00
|
|
|
RefactorAction,
|
|
|
|
|
SetFunctionPropertyPayload,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "api/JSActionAPI";
|
2022-03-17 12:05:17 +00:00
|
|
|
import ActionAPI from "api/ActionAPI";
|
2021-09-08 17:32:22 +00:00
|
|
|
import {
|
|
|
|
|
updateJSCollectionSuccess,
|
|
|
|
|
refactorJSCollectionAction,
|
2021-11-08 06:49:22 +00:00
|
|
|
updateJSCollectionBodySuccess,
|
2022-03-17 12:05:17 +00:00
|
|
|
updateJSFunction,
|
2022-04-13 06:17:56 +00:00
|
|
|
executeJSFunctionInit,
|
2021-09-23 07:21:57 +00:00
|
|
|
} from "actions/jsPaneActions";
|
2022-06-15 15:37:41 +00:00
|
|
|
import { getCurrentWorkspaceId } from "@appsmith/selectors/workspaceSelectors";
|
2021-09-08 17:32:22 +00:00
|
|
|
import { getPluginIdOfPackageName } from "sagas/selectors";
|
chore: import common variables from design system (#17600)
* Delete CommonComponentProps, Classes, import them from design-system
* Delete Icon.test.tsx
* Remove color utils, add import from design-system
* Remove Variant, add import from design-system
* Remove unused toast parameters from common
* use design-system version 28-alpha-7
* Move ThemeProp from ads/common to widgets/constants
* fix import
* Delete index.ts
* feat: migrated form group from ads folder to design system repository (#17400)
* feat: migrated form group from ads folder to design system repo
* fix: formGroup label color fix
* DS version updated
* Updated Label Config
* chore: Flapdoodle version upgrade to 3.5.0 (#17609)
* chore: code split tenant API CE (#17596)
## Description
We shouldn't expose tenant config on CE , so on CE, we should only return the necessary user permissions hard coded on the saga.
## Type of change
- New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
- Manual
## Checklist:
- [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
* chore: BaseAppsmithRepo code split (#17614)
* chore: Updating the tenant API to return the complete object instead of just the configuration (#17615)
* Fix sandbox iframe default setting (#17618)
* feat: upgrade hooks | audit logs (#17525)
* feat: Text Widget Reskinning (#17298)
* feat: Use truncate button color from theme
* fix: Update Truncate Button Color validation regex
* feat: Maintain Focus and Context Phase 1 (#16317)
* fix: update regex and test case for organisation website (#17612)
* chore: Add properties to analytics event (#17621)
* feat: enabled setTimeout/clearTimeout APIs (#17445)
* Update top contributors
* fix: ms sql default port updated to 1433 (#17342)
* fix: removed global style from design system dropdown component (#17392)
* bug: removed global style from design system dropdown component
* changed design system package version
* fix: Dropdown background fix - design system
* design-system - dropdown background color fix
* DS version updated
* chore: Fixing broken client build (#17634)
## Description
EE client build is broken due to not following proper code splitting strategy; one file in particularly didn't get split earlier and changes to that file broke the client build on EE.
This PR fixes the issues.
* Fix/16994 refactor common datatype handling (#17429)
* fix:Add array datatype to execute request
* feat: Consume and store type of array elements in Param class (#16994)
* Append param instead of clientDataType in varargs (#16994)
* Refactor common data type handling w.r.t newer structure (#16994)
This commit takes care of the following items:
- It minimizes the number of usage to the older stringToKnownDataTypeConverter method
- Modifies the existing test cases to conform to the newer structure
- Marks stringToKnownDataTypeConverter method as deprecated to discourage further use
* Remove comma delimited numbers from valid test cases (#16994)
* Fix extracting clientDataType from varargs in MySQL (#16994)
* Pass param as a dedicated parameter in json smart replacement (#16994)
* Remove varargs from json smart replacement method (#16994)
* Move BsonType to mongoplugin module (#16994)
* Introduce NullArrayType and refactor BsonType test cases (#16994)
* Add new test cases on numeric string with leading zero (#16994)
* Refactor test case name (#16994)
* Add comment on the ordering of Json and Bson types (#16994)
* Add comment on the ordering of Json and Bson types (#16994)
* Add NullArrayType in Postgres and introduce postgres-specific types (#16994)
* Add data type test cases for Postgres and change as per review comments (#16994)
Co-authored-by: ChandanBalajiBP <chandan@appsmith.com>
* feat: Update invite modal submit when we have tabs in modal (#17608)
## Description
> Update invite modal submit when we have tabs in modal.
Fixes [#16741](https://github.com/appsmithorg/appsmith/issues/16741)
## Type of change
- New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
> Tested it locally.
## Checklist:
- [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
* feat: AST based entity refactor (#17434)
* task: AST based entity refactor
* implemented refactor logic
* jest cases with string manipulation using AST logic
* comments and indentation
* added evalVersion to request
* chore: Added feature flag for datasource environments (#17657)
chore: Added Feature flag for datasource environments
* chore: Corrected analytics event for instance setting events (#17622)
* Update top contributors
* Fix typo in cloud-hosting check and NPE from Segment (#17692)
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
* fix: remove file references on click of cancel button (#17664)
* fix: table does not show data issue fixed (#17459)
* chore: Add recommended indexes (#17704)
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
* chore: Added workspace details to user invite analytic event (#17644)
## Description
This PR adds the workspace details to user invite analytics event
## Type of change
- New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
- Manually on local
## Checklist:
- [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
- [x] New and existing unit tests pass locally with my changes
* chore: Correct the toast font on windows (#17671)
* fix: JS option missing for Label Font Style in Input widget (#17631)
* fix: replace time based action to event based (#17586)
* fix: replace time based action to event based
- The delete datasource button was getting reset to it's original state after a static time of 2200ms
- Replaced this to reset on completion of deletion instead
* fix: removed unused functions
* fix: updated the condition to show confirm delete icon
* Updated Label Config
* test: Add cypress tests for template phase 2 (#17036)
Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
* Change Segment CDN to our proxy (#17714)
* chore: Fixing prettier formatting for AnalyticsUtil.tsx
* chore: Adding base repository function to add user permissions to generic domain object (#17733)
## Description
Adding base function to set the user permissions for a user in any domain object.
As part of this, we also add default permission group to the `SeedMongoData`. Without this fix, the JUnit tests go into an infinite loop. Also fixing the `ExampleWorkspaceClonerTest` file.
## Type of change
- Bug fix (non-breaking change which fixes an issue)
## How Has This Been Tested?
- JUnit
## Checklist:
- [ ] My code follows the style guidelines of this project
- [ ] 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
- [ ] 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
* Update top contributors
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Nikhil Nandagopal <nikhil.nandagopal@gmail.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com>
Co-authored-by: Trisha Anand <trisha@appsmith.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: f0c1s <anubhav@appsmith.com>
Co-authored-by: Dhruvik Neharia <dhruvik@appsmith.com>
Co-authored-by: Hetu Nandu <hetu@appsmith.com>
Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: arunvjn <32433245+arunvjn@users.noreply.github.com>
Co-authored-by: Appsmith Bot <74705725+appsmith-bot@users.noreply.github.com>
Co-authored-by: Vaibhav Tanwar <40293928+vaibh1297@users.noreply.github.com>
Co-authored-by: subratadeypappu <subrata@appsmith.com>
Co-authored-by: ChandanBalajiBP <chandan@appsmith.com>
Co-authored-by: Ankita Kinger <ankita@appsmith.com>
Co-authored-by: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com>
Co-authored-by: Vishnu Gp <vishnu@appsmith.com>
Co-authored-by: Keyur Paralkar <keyur@appsmith.com>
Co-authored-by: sneha122 <sneha@appsmith.com>
Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com>
Co-authored-by: sanjus-robotic-studio <58104863+sanjus-robotic-studio@users.noreply.github.com>
Co-authored-by: Ayush Pahwa <ayush@appsmith.com>
Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com>
Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
Co-authored-by: Arpit Mohan <arpit@appsmith.com>
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
Co-authored-by: Nikhil Nandagopal <nikhil.nandagopal@gmail.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com>
Co-authored-by: Trisha Anand <trisha@appsmith.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: f0c1s <anubhav@appsmith.com>
Co-authored-by: Dhruvik Neharia <dhruvik@appsmith.com>
Co-authored-by: Hetu Nandu <hetu@appsmith.com>
Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: arunvjn <32433245+arunvjn@users.noreply.github.com>
Co-authored-by: Appsmith Bot <74705725+appsmith-bot@users.noreply.github.com>
Co-authored-by: Vaibhav Tanwar <40293928+vaibh1297@users.noreply.github.com>
Co-authored-by: subratadeypappu <subrata@appsmith.com>
Co-authored-by: ChandanBalajiBP <chandan@appsmith.com>
Co-authored-by: Ankita Kinger <ankita@appsmith.com>
Co-authored-by: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com>
Co-authored-by: Vishnu Gp <vishnu@appsmith.com>
Co-authored-by: Keyur Paralkar <keyur@appsmith.com>
Co-authored-by: sneha122 <sneha@appsmith.com>
Co-authored-by: sanjus-robotic-studio <58104863+sanjus-robotic-studio@users.noreply.github.com>
Co-authored-by: Ayush Pahwa <ayush@appsmith.com>
Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com>
Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2022-10-31 01:24:47 +00:00
|
|
|
import { Toaster, Variant } from "design-system";
|
2022-10-17 15:16:38 +00:00
|
|
|
import { PluginPackageName, PluginType } from "entities/Action";
|
2021-09-08 17:32:22 +00:00
|
|
|
import {
|
|
|
|
|
createMessage,
|
|
|
|
|
ERROR_JS_COLLECTION_RENAME_FAIL,
|
2021-09-28 07:31:46 +00:00
|
|
|
JS_EXECUTION_SUCCESS,
|
|
|
|
|
JS_EXECUTION_FAILURE,
|
|
|
|
|
JS_EXECUTION_FAILURE_TOASTER,
|
2022-04-28 16:51:02 +00:00
|
|
|
JS_EXECUTION_SUCCESS_TOASTER,
|
2021-09-28 07:31:46 +00:00
|
|
|
JS_FUNCTION_CREATE_SUCCESS,
|
|
|
|
|
JS_FUNCTION_DELETE_SUCCESS,
|
|
|
|
|
JS_FUNCTION_UPDATE_SUCCESS,
|
2022-02-11 18:08:46 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2021-09-08 17:32:22 +00:00
|
|
|
import { validateResponse } from "./ErrorSagas";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
2021-09-28 07:31:46 +00:00
|
|
|
import { ENTITY_TYPE, PLATFORM_ERROR } from "entities/AppsmithConsole";
|
2021-09-08 17:32:22 +00:00
|
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
2022-06-21 13:57:34 +00:00
|
|
|
import PageApi, { FetchPageResponse } from "api/PageApi";
|
2021-09-08 17:32:22 +00:00
|
|
|
import { updateCanvasWithDSL } from "sagas/PageSagas";
|
2022-03-17 12:05:17 +00:00
|
|
|
import { set } from "lodash";
|
2021-12-07 09:45:18 +00:00
|
|
|
import { updateReplayEntity } from "actions/pageActions";
|
2022-03-25 10:43:26 +00:00
|
|
|
import { jsCollectionIdURL } from "RouteBuilder";
|
2022-06-21 13:57:34 +00:00
|
|
|
import { ApiResponse } from "api/ApiResponses";
|
|
|
|
|
import { shouldBeDefined } from "utils/helpers";
|
2022-04-06 07:22:18 +00:00
|
|
|
import { ModalType } from "reducers/uiReducers/modalActionReducer";
|
|
|
|
|
import { requestModalConfirmationSaga } from "sagas/UtilSagas";
|
|
|
|
|
import { UserCancelledActionExecutionError } from "sagas/ActionExecution/errorUtils";
|
2022-05-07 16:03:03 +00:00
|
|
|
import { APP_MODE } from "entities/App";
|
|
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
2022-09-14 15:34:10 +00:00
|
|
|
import AnalyticsUtil, { EventLocation } from "utils/AnalyticsUtil";
|
2022-10-13 20:13:44 +00:00
|
|
|
import { DebugButton } from "../components/editorComponents/Debugger/DebugCTA";
|
2022-09-24 10:01:52 +00:00
|
|
|
import { checkAndLogErrorsIfCyclicDependency } from "./helper";
|
2021-09-08 17:32:22 +00:00
|
|
|
|
2022-09-14 15:34:10 +00:00
|
|
|
function* handleCreateNewJsActionSaga(
|
|
|
|
|
action: ReduxAction<{ pageId: string; from: EventLocation }>,
|
|
|
|
|
) {
|
2022-06-15 15:37:41 +00:00
|
|
|
const workspaceId: string = yield select(getCurrentWorkspaceId);
|
2022-06-21 13:57:34 +00:00
|
|
|
const applicationId: string = yield select(getCurrentApplicationId);
|
2022-09-14 15:34:10 +00:00
|
|
|
const { from, pageId } = action.payload;
|
2021-09-08 17:32:22 +00:00
|
|
|
const pluginId: string = yield select(
|
|
|
|
|
getPluginIdOfPackageName,
|
2022-10-17 15:16:38 +00:00
|
|
|
PluginPackageName.JS,
|
2021-09-08 17:32:22 +00:00
|
|
|
);
|
|
|
|
|
if (pageId && pluginId) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const jsActions: JSCollectionDataState = yield select(getJSCollections);
|
2021-09-23 07:21:57 +00:00
|
|
|
const pageJSActions = jsActions.filter(
|
2021-09-08 17:32:22 +00:00
|
|
|
(a: JSCollectionData) => a.config.pageId === pageId,
|
|
|
|
|
);
|
|
|
|
|
const newJSCollectionName = createNewJSFunctionName(pageJSActions, pageId);
|
2021-10-26 12:53:58 +00:00
|
|
|
const { actions, body } = createDummyJSCollectionActions(
|
|
|
|
|
pageId,
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId,
|
2021-10-26 12:53:58 +00:00
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
yield put(
|
|
|
|
|
createJSCollectionRequest({
|
2022-09-14 15:34:10 +00:00
|
|
|
from: from,
|
|
|
|
|
request: {
|
|
|
|
|
name: newJSCollectionName,
|
|
|
|
|
pageId,
|
|
|
|
|
workspaceId,
|
|
|
|
|
pluginId,
|
|
|
|
|
body: body,
|
|
|
|
|
variables: [
|
|
|
|
|
{
|
|
|
|
|
name: "myVar1",
|
|
|
|
|
value: [],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "myVar2",
|
|
|
|
|
value: {},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
actions: actions,
|
|
|
|
|
applicationId,
|
|
|
|
|
pluginType: PluginType.JS,
|
|
|
|
|
},
|
2021-09-08 17:32:22 +00:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* handleJSCollectionCreatedSaga(
|
|
|
|
|
actionPayload: ReduxAction<JSCollection>,
|
|
|
|
|
) {
|
2022-07-11 04:06:29 +00:00
|
|
|
const { id, pageId } = actionPayload.payload;
|
2022-03-25 10:43:26 +00:00
|
|
|
history.push(
|
|
|
|
|
jsCollectionIdURL({
|
2022-07-11 04:06:29 +00:00
|
|
|
pageId,
|
2022-03-25 10:43:26 +00:00
|
|
|
collectionId: id,
|
2022-05-04 09:47:41 +00:00
|
|
|
params: {
|
|
|
|
|
editName: true,
|
|
|
|
|
},
|
2022-03-25 10:43:26 +00:00
|
|
|
}),
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-08 06:49:22 +00:00
|
|
|
function* handleEachUpdateJSCollection(update: JSUpdate) {
|
|
|
|
|
const jsActionId = update.id;
|
2022-06-15 15:37:41 +00:00
|
|
|
const workspaceId: string = yield select(getCurrentWorkspaceId);
|
2021-09-08 17:32:22 +00:00
|
|
|
if (jsActionId) {
|
|
|
|
|
const jsAction: JSCollection = yield select(getJSCollection, jsActionId);
|
2021-11-08 06:49:22 +00:00
|
|
|
const parsedBody = update.parsedBody;
|
2021-10-19 11:53:15 +00:00
|
|
|
const jsActionTobeUpdated = JSON.parse(JSON.stringify(jsAction));
|
2021-09-21 06:02:45 +00:00
|
|
|
if (parsedBody) {
|
2021-11-08 06:49:22 +00:00
|
|
|
// jsActionTobeUpdated.body = jsAction.body;
|
2021-09-21 06:02:45 +00:00
|
|
|
const data = getDifferenceInJSCollection(parsedBody, jsAction);
|
|
|
|
|
if (data.nameChangedActions.length) {
|
|
|
|
|
for (let i = 0; i < data.nameChangedActions.length; i++) {
|
|
|
|
|
yield put(
|
|
|
|
|
refactorJSCollectionAction({
|
2021-10-19 11:53:15 +00:00
|
|
|
refactorAction: {
|
|
|
|
|
actionId: data.nameChangedActions[i].id,
|
|
|
|
|
collectionName: jsAction.name,
|
|
|
|
|
pageId: data.nameChangedActions[i].pageId,
|
|
|
|
|
oldName: data.nameChangedActions[i].oldName,
|
|
|
|
|
newName: data.nameChangedActions[i].newName,
|
|
|
|
|
},
|
|
|
|
|
actionCollection: jsActionTobeUpdated,
|
2021-09-21 06:02:45 +00:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-10-19 11:53:15 +00:00
|
|
|
} else {
|
|
|
|
|
let newActions: Partial<JSAction>[] = [];
|
|
|
|
|
let updateActions: JSAction[] = [];
|
|
|
|
|
let deletedActions: JSAction[] = [];
|
2021-11-08 06:49:22 +00:00
|
|
|
let updateCollection = false;
|
|
|
|
|
const changedVariables = data.changedVariables;
|
|
|
|
|
if (changedVariables.length) {
|
2021-10-19 11:53:15 +00:00
|
|
|
jsActionTobeUpdated.variables = parsedBody.variables;
|
2021-11-08 06:49:22 +00:00
|
|
|
updateCollection = true;
|
2021-09-21 06:02:45 +00:00
|
|
|
}
|
2021-10-19 11:53:15 +00:00
|
|
|
if (data.newActions.length) {
|
|
|
|
|
newActions = data.newActions;
|
|
|
|
|
for (let i = 0; i < data.newActions.length; i++) {
|
|
|
|
|
jsActionTobeUpdated.actions.push({
|
|
|
|
|
...data.newActions[i],
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId: workspaceId,
|
2021-10-19 11:53:15 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-08 06:49:22 +00:00
|
|
|
updateCollection = true;
|
2021-10-19 11:53:15 +00:00
|
|
|
}
|
|
|
|
|
if (data.updateActions.length > 0) {
|
|
|
|
|
updateActions = data.updateActions;
|
|
|
|
|
let changedActions = [];
|
|
|
|
|
for (let i = 0; i < data.updateActions.length; i++) {
|
|
|
|
|
changedActions = jsActionTobeUpdated.actions.map(
|
|
|
|
|
(js: JSAction) =>
|
|
|
|
|
data.updateActions.find(
|
|
|
|
|
(update: JSAction) => update.id === js.id,
|
|
|
|
|
) || js,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-08 06:49:22 +00:00
|
|
|
updateCollection = true;
|
2021-10-19 11:53:15 +00:00
|
|
|
jsActionTobeUpdated.actions = changedActions;
|
|
|
|
|
}
|
|
|
|
|
if (data.deletedActions.length > 0) {
|
|
|
|
|
deletedActions = data.deletedActions;
|
|
|
|
|
const nonDeletedActions = jsActionTobeUpdated.actions.filter(
|
|
|
|
|
(js: JSAction) => {
|
|
|
|
|
return !data.deletedActions.find((deleted) => {
|
|
|
|
|
return deleted.id === js.id;
|
|
|
|
|
});
|
|
|
|
|
},
|
2021-09-21 06:02:45 +00:00
|
|
|
);
|
2021-11-08 06:49:22 +00:00
|
|
|
updateCollection = true;
|
2021-10-19 11:53:15 +00:00
|
|
|
jsActionTobeUpdated.actions = nonDeletedActions;
|
2021-09-21 06:02:45 +00:00
|
|
|
}
|
2021-11-08 06:49:22 +00:00
|
|
|
if (updateCollection) {
|
2022-09-14 15:34:10 +00:00
|
|
|
newActions.forEach((action) => {
|
|
|
|
|
AnalyticsUtil.logEvent("JS_OBJECT_FUNCTION_ADDED", {
|
|
|
|
|
name: action.name,
|
|
|
|
|
jsObjectName: jsAction.name,
|
|
|
|
|
});
|
|
|
|
|
});
|
2021-11-08 06:49:22 +00:00
|
|
|
yield call(updateJSCollection, {
|
|
|
|
|
jsCollection: jsActionTobeUpdated,
|
|
|
|
|
newActions: newActions,
|
|
|
|
|
updatedActions: updateActions,
|
|
|
|
|
deletedActions: deletedActions,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 06:49:22 +00:00
|
|
|
export function* makeUpdateJSCollection(jsUpdates: Record<string, JSUpdate>) {
|
|
|
|
|
yield all(
|
|
|
|
|
Object.keys(jsUpdates).map((key) =>
|
|
|
|
|
call(handleEachUpdateJSCollection, jsUpdates[key]),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-19 11:53:15 +00:00
|
|
|
function* updateJSCollection(data: {
|
|
|
|
|
jsCollection: JSCollection;
|
2021-11-08 06:49:22 +00:00
|
|
|
newActions?: Partial<JSAction>[];
|
|
|
|
|
updatedActions?: JSAction[];
|
|
|
|
|
deletedActions?: JSAction[];
|
2021-10-19 11:53:15 +00:00
|
|
|
}) {
|
2021-09-08 17:32:22 +00:00
|
|
|
let jsAction = {};
|
|
|
|
|
const jsActionId = getJSCollectionIdFromURL();
|
|
|
|
|
if (jsActionId) {
|
|
|
|
|
jsAction = yield select(getJSCollection, jsActionId);
|
|
|
|
|
}
|
|
|
|
|
try {
|
2021-10-19 11:53:15 +00:00
|
|
|
const { deletedActions, jsCollection, newActions, updatedActions } = data;
|
2021-09-28 07:31:46 +00:00
|
|
|
if (jsCollection) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const response: JSCollectionCreateUpdateResponse = yield JSActionAPI.updateJSCollection(
|
|
|
|
|
jsCollection,
|
|
|
|
|
);
|
|
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2021-09-08 17:32:22 +00:00
|
|
|
if (isValidResponse) {
|
2021-11-08 06:49:22 +00:00
|
|
|
if (newActions && newActions.length) {
|
2021-09-28 07:31:46 +00:00
|
|
|
pushLogsForObjectUpdate(
|
|
|
|
|
newActions,
|
|
|
|
|
jsCollection,
|
|
|
|
|
createMessage(JS_FUNCTION_CREATE_SUCCESS),
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-08 06:49:22 +00:00
|
|
|
if (updatedActions && updatedActions.length) {
|
2021-09-28 07:31:46 +00:00
|
|
|
pushLogsForObjectUpdate(
|
|
|
|
|
updatedActions,
|
|
|
|
|
jsCollection,
|
|
|
|
|
createMessage(JS_FUNCTION_UPDATE_SUCCESS),
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-11-08 06:49:22 +00:00
|
|
|
if (deletedActions && deletedActions.length) {
|
2021-09-28 07:31:46 +00:00
|
|
|
pushLogsForObjectUpdate(
|
|
|
|
|
deletedActions,
|
|
|
|
|
jsCollection,
|
|
|
|
|
createMessage(JS_FUNCTION_DELETE_SUCCESS),
|
|
|
|
|
);
|
2022-06-30 07:21:20 +00:00
|
|
|
// delete all execution error logs for deletedActions if present
|
|
|
|
|
deletedActions.forEach((action) =>
|
2022-12-07 10:28:29 +00:00
|
|
|
AppsmithConsole.deleteErrors([
|
|
|
|
|
{ id: `${jsCollection.id}-${action.id}` },
|
|
|
|
|
]),
|
2022-06-30 07:21:20 +00:00
|
|
|
);
|
2021-09-28 07:31:46 +00:00
|
|
|
}
|
2022-04-28 16:51:02 +00:00
|
|
|
|
|
|
|
|
yield put(
|
|
|
|
|
updateJSCollectionSuccess({
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: data is of type unknown
|
2022-04-28 16:51:02 +00:00
|
|
|
data: response?.data,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.UPDATE_JS_ACTION_ERROR,
|
|
|
|
|
payload: { error, data: jsAction },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* handleJSObjectNameChangeSuccessSaga(
|
|
|
|
|
action: ReduxAction<{ actionId: string }>,
|
|
|
|
|
) {
|
|
|
|
|
const { actionId } = action.payload;
|
2022-06-21 13:57:34 +00:00
|
|
|
const actionObj: JSCollection | undefined = yield select(
|
|
|
|
|
getJSCollection,
|
|
|
|
|
actionId,
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
yield take(ReduxActionTypes.FETCH_JS_ACTIONS_FOR_PAGE_SUCCESS);
|
|
|
|
|
if (!actionObj) {
|
|
|
|
|
// Error case, log to sentry
|
|
|
|
|
Toaster.show({
|
|
|
|
|
text: createMessage(ERROR_JS_COLLECTION_RENAME_FAIL, ""),
|
|
|
|
|
variant: Variant.danger,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-06-21 13:57:34 +00:00
|
|
|
|
|
|
|
|
if (actionObj.pluginType === PluginType.JS) {
|
2021-09-08 17:32:22 +00:00
|
|
|
const params = getQueryParams();
|
|
|
|
|
if (params.editName) {
|
|
|
|
|
params.editName = "false";
|
|
|
|
|
}
|
2022-03-25 10:43:26 +00:00
|
|
|
history.push(
|
|
|
|
|
jsCollectionIdURL({
|
2022-07-11 04:06:29 +00:00
|
|
|
pageId: actionObj.pageId,
|
2022-03-25 10:43:26 +00:00
|
|
|
collectionId: actionId,
|
|
|
|
|
params,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-06 07:22:18 +00:00
|
|
|
export function* handleExecuteJSFunctionSaga(data: {
|
|
|
|
|
collectionName: string;
|
|
|
|
|
action: JSAction;
|
|
|
|
|
collectionId: string;
|
|
|
|
|
}): any {
|
|
|
|
|
const { action, collectionId, collectionName } = data;
|
2021-09-08 17:32:22 +00:00
|
|
|
const actionId = action.id;
|
2022-05-07 16:03:03 +00:00
|
|
|
const appMode: APP_MODE = yield select(getAppMode);
|
2022-04-13 06:17:56 +00:00
|
|
|
yield put(
|
|
|
|
|
executeJSFunctionInit({
|
|
|
|
|
collectionName,
|
|
|
|
|
action,
|
|
|
|
|
collectionId,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2022-05-19 13:13:51 +00:00
|
|
|
|
|
|
|
|
const isEntitySaving = yield select(getIsSavingEntity);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Only start executing when no entity in the application is saving
|
|
|
|
|
* This ensures that execution doesn't get carried out on stale values
|
|
|
|
|
* This includes other entities which might be bound in the JS Function
|
|
|
|
|
*/
|
|
|
|
|
if (isEntitySaving) {
|
|
|
|
|
yield take(ReduxActionTypes.ENTITY_UPDATE_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 06:02:45 +00:00
|
|
|
try {
|
2022-05-11 10:20:33 +00:00
|
|
|
const { isDirty, result } = yield call(
|
|
|
|
|
executeFunction,
|
|
|
|
|
collectionName,
|
|
|
|
|
action,
|
2022-06-30 07:21:20 +00:00
|
|
|
collectionId,
|
2022-05-11 10:20:33 +00:00
|
|
|
);
|
2021-09-21 06:02:45 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.EXECUTE_JS_FUNCTION_SUCCESS,
|
|
|
|
|
payload: {
|
|
|
|
|
results: result,
|
|
|
|
|
collectionId,
|
|
|
|
|
actionId,
|
2022-05-11 10:20:33 +00:00
|
|
|
isDirty,
|
2021-09-21 06:02:45 +00:00
|
|
|
},
|
|
|
|
|
});
|
2021-09-28 07:31:46 +00:00
|
|
|
AppsmithConsole.info({
|
|
|
|
|
text: createMessage(JS_EXECUTION_SUCCESS),
|
|
|
|
|
source: {
|
|
|
|
|
type: ENTITY_TYPE.JSACTION,
|
|
|
|
|
name: collectionName + "." + action.name,
|
|
|
|
|
id: collectionId,
|
|
|
|
|
},
|
|
|
|
|
state: { response: result },
|
|
|
|
|
});
|
2022-05-07 16:03:03 +00:00
|
|
|
appMode === APP_MODE.EDIT &&
|
2022-05-11 10:20:33 +00:00
|
|
|
!isDirty &&
|
2022-05-07 16:03:03 +00:00
|
|
|
Toaster.show({
|
|
|
|
|
text: createMessage(JS_EXECUTION_SUCCESS_TOASTER, action.name),
|
|
|
|
|
variant: Variant.success,
|
|
|
|
|
});
|
2022-06-21 13:57:34 +00:00
|
|
|
} catch (error) {
|
2022-12-07 10:28:29 +00:00
|
|
|
AppsmithConsole.addErrors([
|
|
|
|
|
{
|
|
|
|
|
payload: {
|
|
|
|
|
id: actionId,
|
|
|
|
|
logType: LOG_TYPE.ACTION_EXECUTION_ERROR,
|
|
|
|
|
text: createMessage(JS_EXECUTION_FAILURE),
|
|
|
|
|
source: {
|
|
|
|
|
type: ENTITY_TYPE.JSACTION,
|
|
|
|
|
name: collectionName + "." + action.name,
|
|
|
|
|
id: collectionId,
|
|
|
|
|
},
|
|
|
|
|
messages: [
|
|
|
|
|
{
|
|
|
|
|
message: (error as Error).message,
|
|
|
|
|
type: PLATFORM_ERROR.PLUGIN_EXECUTION,
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-09-28 07:31:46 +00:00
|
|
|
},
|
2022-12-07 10:28:29 +00:00
|
|
|
},
|
|
|
|
|
]);
|
2021-09-21 06:02:45 +00:00
|
|
|
Toaster.show({
|
2022-06-21 13:57:34 +00:00
|
|
|
text:
|
|
|
|
|
(error as Error).message || createMessage(JS_EXECUTION_FAILURE_TOASTER),
|
2021-09-21 06:02:45 +00:00
|
|
|
variant: Variant.danger,
|
2022-10-13 20:13:44 +00:00
|
|
|
showDebugButton: {
|
|
|
|
|
component: DebugButton,
|
|
|
|
|
componentProps: {
|
|
|
|
|
className: "t--toast-debug-button",
|
|
|
|
|
source: "TOAST",
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-09-21 06:02:45 +00:00
|
|
|
});
|
|
|
|
|
}
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-06 07:22:18 +00:00
|
|
|
export function* handleStartExecuteJSFunctionSaga(
|
|
|
|
|
data: ReduxAction<{
|
|
|
|
|
collectionName: string;
|
|
|
|
|
action: JSAction;
|
|
|
|
|
collectionId: string;
|
2022-09-14 15:34:10 +00:00
|
|
|
from: EventLocation;
|
2022-04-06 07:22:18 +00:00
|
|
|
}>,
|
|
|
|
|
): any {
|
2022-09-14 15:34:10 +00:00
|
|
|
const { action, collectionId, collectionName, from } = data.payload;
|
2022-04-06 07:22:18 +00:00
|
|
|
const actionId = action.id;
|
|
|
|
|
if (action.confirmBeforeExecute) {
|
|
|
|
|
const modalPayload = {
|
|
|
|
|
name: collectionName + "." + action.name,
|
|
|
|
|
modalOpen: true,
|
|
|
|
|
modalType: ModalType.RUN_ACTION,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const confirmed = yield call(requestModalConfirmationSaga, modalPayload);
|
|
|
|
|
|
|
|
|
|
if (!confirmed) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.RUN_ACTION_CANCELLED,
|
|
|
|
|
payload: { id: actionId },
|
|
|
|
|
});
|
|
|
|
|
throw new UserCancelledActionExecutionError();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-14 15:34:10 +00:00
|
|
|
AnalyticsUtil.logEvent("JS_OBJECT_FUNCTION_RUN", {
|
|
|
|
|
name: action.name,
|
|
|
|
|
num_params: action.actionConfiguration?.jsArguments?.length,
|
|
|
|
|
from: from,
|
|
|
|
|
});
|
2022-04-06 07:22:18 +00:00
|
|
|
yield call(handleExecuteJSFunctionSaga, {
|
|
|
|
|
collectionName: collectionName,
|
|
|
|
|
action: action,
|
|
|
|
|
collectionId: collectionId,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-08 06:49:22 +00:00
|
|
|
function* handleUpdateJSCollectionBody(
|
2021-12-07 09:45:18 +00:00
|
|
|
actionPayload: ReduxAction<{ body: string; id: string; isReplay: boolean }>,
|
2021-11-08 06:49:22 +00:00
|
|
|
) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const jsCollection: JSCollection | undefined = yield select(
|
|
|
|
|
getJSCollection,
|
|
|
|
|
actionPayload.payload.id,
|
|
|
|
|
);
|
|
|
|
|
// @ts-expect-error: Object jsCollection is possibly undefined
|
2022-03-17 12:05:17 +00:00
|
|
|
jsCollection["body"] = actionPayload.payload.body;
|
2021-11-08 06:49:22 +00:00
|
|
|
try {
|
|
|
|
|
if (jsCollection) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const response: JSCollectionCreateUpdateResponse = yield JSActionAPI.updateJSCollection(
|
|
|
|
|
jsCollection,
|
|
|
|
|
);
|
|
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2021-11-08 06:49:22 +00:00
|
|
|
if (isValidResponse) {
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: response is of type unknown
|
2021-11-08 06:49:22 +00:00
|
|
|
yield put(updateJSCollectionBodySuccess({ data: response?.data }));
|
2022-09-24 10:01:52 +00:00
|
|
|
checkAndLogErrorsIfCyclicDependency(
|
|
|
|
|
(response.data as JSCollection).errorReports,
|
|
|
|
|
);
|
2021-11-08 06:49:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.UPDATE_JS_ACTION_BODY_ERROR,
|
|
|
|
|
payload: { error, data: jsCollection },
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-07 09:45:18 +00:00
|
|
|
if (!actionPayload.payload.isReplay)
|
|
|
|
|
yield put(
|
|
|
|
|
updateReplayEntity(
|
|
|
|
|
actionPayload.payload.id,
|
|
|
|
|
{
|
|
|
|
|
id: actionPayload.payload.id,
|
|
|
|
|
body: actionPayload.payload.body,
|
|
|
|
|
},
|
|
|
|
|
ENTITY_TYPE.JSACTION,
|
|
|
|
|
),
|
|
|
|
|
);
|
2021-11-08 06:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-08 17:32:22 +00:00
|
|
|
function* handleRefactorJSActionNameSaga(
|
|
|
|
|
data: ReduxAction<{
|
2021-10-19 11:53:15 +00:00
|
|
|
refactorAction: RefactorAction;
|
|
|
|
|
actionCollection: JSCollection;
|
2021-09-08 17:32:22 +00:00
|
|
|
}>,
|
|
|
|
|
) {
|
2022-06-21 13:57:34 +00:00
|
|
|
const pageResponse: FetchPageResponse = yield call(PageApi.fetchPage, {
|
2021-10-19 11:53:15 +00:00
|
|
|
id: data.payload.refactorAction.pageId,
|
2021-09-08 17:32:22 +00:00
|
|
|
});
|
2022-06-21 13:57:34 +00:00
|
|
|
const isPageRequestSuccessful: boolean = yield validateResponse(pageResponse);
|
2021-09-08 17:32:22 +00:00
|
|
|
if (isPageRequestSuccessful) {
|
|
|
|
|
// get the layoutId from the page response
|
|
|
|
|
const layoutId = pageResponse.data.layouts[0].id;
|
2021-10-19 11:53:15 +00:00
|
|
|
const requestData = {
|
|
|
|
|
refactorAction: {
|
|
|
|
|
...data.payload.refactorAction,
|
|
|
|
|
layoutId: layoutId,
|
|
|
|
|
},
|
|
|
|
|
actionCollection: data.payload.actionCollection,
|
|
|
|
|
};
|
2021-09-08 17:32:22 +00:00
|
|
|
// call to refactor action
|
|
|
|
|
try {
|
2022-06-21 13:57:34 +00:00
|
|
|
const refactorResponse: ApiResponse = yield JSActionAPI.updateJSCollectionActionRefactor(
|
2021-10-19 11:53:15 +00:00
|
|
|
requestData,
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
const isRefactorSuccessful: boolean = yield validateResponse(
|
|
|
|
|
refactorResponse,
|
|
|
|
|
);
|
2021-09-08 17:32:22 +00:00
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
const currentPageId: string | undefined = yield select(getCurrentPageId);
|
2021-09-08 17:32:22 +00:00
|
|
|
|
|
|
|
|
if (isRefactorSuccessful) {
|
2021-10-19 11:53:15 +00:00
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.REFACTOR_JS_ACTION_NAME_SUCCESS,
|
|
|
|
|
payload: { collectionId: data.payload.actionCollection.id },
|
|
|
|
|
});
|
|
|
|
|
if (currentPageId === data.payload.refactorAction.pageId) {
|
2021-09-08 17:32:22 +00:00
|
|
|
yield updateCanvasWithDSL(
|
2022-06-21 13:57:34 +00:00
|
|
|
// @ts-expect-error: response is of type unknown
|
2021-09-08 17:32:22 +00:00
|
|
|
refactorResponse.data,
|
2021-10-19 11:53:15 +00:00
|
|
|
data.payload.refactorAction.pageId,
|
2021-09-08 17:32:22 +00:00
|
|
|
layoutId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.REFACTOR_JS_ACTION_NAME_ERROR,
|
2021-10-19 11:53:15 +00:00
|
|
|
payload: { collectionId: data.payload.actionCollection.id },
|
2021-09-08 17:32:22 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 12:05:17 +00:00
|
|
|
function* setFunctionPropertySaga(
|
|
|
|
|
data: ReduxAction<SetFunctionPropertyPayload>,
|
|
|
|
|
) {
|
|
|
|
|
const { action, propertyName, value } = data.payload;
|
|
|
|
|
if (!action.id) return;
|
|
|
|
|
const actionId = action.id;
|
|
|
|
|
if (propertyName === "executeOnLoad") {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.TOGGLE_FUNCTION_EXECUTE_ON_LOAD_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
collectionId: action.collectionId,
|
|
|
|
|
actionId,
|
|
|
|
|
shouldExecute: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
yield put(updateJSFunction({ ...data.payload }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* handleUpdateJSFunctionPropertySaga(
|
|
|
|
|
data: ReduxAction<SetFunctionPropertyPayload>,
|
|
|
|
|
) {
|
|
|
|
|
const { action, propertyName, value } = data.payload;
|
|
|
|
|
if (!action.id) return;
|
|
|
|
|
const actionId = action.id;
|
|
|
|
|
let collection: JSCollection;
|
|
|
|
|
if (action.collectionId) {
|
|
|
|
|
collection = yield select(getJSCollection, action.collectionId);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const actions: JSAction[] = collection.actions;
|
|
|
|
|
const updatedActions = actions.map((jsAction: JSAction) => {
|
|
|
|
|
if (jsAction.id === actionId) {
|
|
|
|
|
set(jsAction, propertyName, value);
|
|
|
|
|
return jsAction;
|
|
|
|
|
}
|
|
|
|
|
return jsAction;
|
|
|
|
|
});
|
|
|
|
|
collection.actions = updatedActions;
|
2022-06-21 13:57:34 +00:00
|
|
|
const response: ApiResponse<JSCollectionCreateUpdateResponse> = yield JSActionAPI.updateJSCollection(
|
|
|
|
|
collection,
|
|
|
|
|
);
|
|
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2022-03-17 12:05:17 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
const fieldToBeUpdated = propertyName.replace(
|
|
|
|
|
"actionConfiguration",
|
|
|
|
|
"config",
|
|
|
|
|
);
|
|
|
|
|
AppsmithConsole.info({
|
|
|
|
|
logType: LOG_TYPE.ACTION_UPDATE,
|
|
|
|
|
text: "Configuration updated",
|
|
|
|
|
source: {
|
|
|
|
|
type: ENTITY_TYPE.JSACTION,
|
|
|
|
|
name: collection.name + "." + action.name,
|
|
|
|
|
id: actionId,
|
|
|
|
|
propertyPath: fieldToBeUpdated,
|
|
|
|
|
},
|
|
|
|
|
state: {
|
|
|
|
|
[fieldToBeUpdated]: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.UPDATE_JS_FUNCTION_PROPERTY_SUCCESS,
|
|
|
|
|
payload: {
|
|
|
|
|
collection,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.UPDATE_JS_FUNCTION_PROPERTY_ERROR,
|
|
|
|
|
payload: collection,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* toggleFunctionExecuteOnLoadSaga(
|
|
|
|
|
action: ReduxAction<{
|
|
|
|
|
collectionId: string;
|
|
|
|
|
actionId: string;
|
|
|
|
|
shouldExecute: boolean;
|
|
|
|
|
}>,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const { actionId, collectionId, shouldExecute } = action.payload;
|
2022-06-21 13:57:34 +00:00
|
|
|
const collection = shouldBeDefined<JSCollection>(
|
|
|
|
|
yield select(getJSCollection, collectionId),
|
|
|
|
|
`JS Collection not found for id - ${collectionId}`,
|
|
|
|
|
);
|
2022-03-17 12:05:17 +00:00
|
|
|
const jsAction = collection.actions.find(
|
|
|
|
|
(action: JSAction) => actionId === action.id,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const response: ApiResponse = yield call(
|
2022-03-17 12:05:17 +00:00
|
|
|
ActionAPI.toggleActionExecuteOnLoad,
|
|
|
|
|
actionId,
|
|
|
|
|
shouldExecute,
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const isValidResponse: boolean = yield validateResponse(response);
|
2022-03-17 12:05:17 +00:00
|
|
|
if (isValidResponse) {
|
|
|
|
|
AppsmithConsole.info({
|
|
|
|
|
logType: LOG_TYPE.ACTION_UPDATE,
|
|
|
|
|
text: "Configuration updated",
|
|
|
|
|
source: {
|
|
|
|
|
type: ENTITY_TYPE.JSACTION,
|
2022-06-21 13:57:34 +00:00
|
|
|
name: collection.name + "." + jsAction?.name,
|
2022-03-17 12:05:17 +00:00
|
|
|
id: actionId,
|
|
|
|
|
propertyPath: "executeOnLoad",
|
|
|
|
|
},
|
|
|
|
|
state: {
|
|
|
|
|
["executeOnLoad"]: shouldExecute,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.TOGGLE_FUNCTION_EXECUTE_ON_LOAD_SUCCESS,
|
|
|
|
|
payload: {
|
|
|
|
|
actionId: actionId,
|
|
|
|
|
collectionId: collectionId,
|
|
|
|
|
executeOnLoad: shouldExecute,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.TOGGLE_ACTION_EXECUTE_ON_LOAD_ERROR,
|
|
|
|
|
payload: error,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 17:32:22 +00:00
|
|
|
export default function* root() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.CREATE_NEW_JS_ACTION,
|
|
|
|
|
handleCreateNewJsActionSaga,
|
|
|
|
|
),
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.CREATE_JS_ACTION_SUCCESS,
|
|
|
|
|
handleJSCollectionCreatedSaga,
|
|
|
|
|
),
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.SAVE_JS_COLLECTION_NAME_SUCCESS,
|
|
|
|
|
handleJSObjectNameChangeSuccessSaga,
|
|
|
|
|
),
|
|
|
|
|
takeEvery(
|
2022-04-06 07:22:18 +00:00
|
|
|
ReduxActionTypes.START_EXECUTE_JS_FUNCTION,
|
|
|
|
|
handleStartExecuteJSFunctionSaga,
|
2021-09-08 17:32:22 +00:00
|
|
|
),
|
|
|
|
|
takeEvery(
|
|
|
|
|
ReduxActionTypes.REFACTOR_JS_ACTION_NAME,
|
|
|
|
|
handleRefactorJSActionNameSaga,
|
|
|
|
|
),
|
2021-11-08 06:49:22 +00:00
|
|
|
debounce(
|
|
|
|
|
100,
|
|
|
|
|
ReduxActionTypes.UPDATE_JS_ACTION_BODY_INIT,
|
|
|
|
|
handleUpdateJSCollectionBody,
|
|
|
|
|
),
|
2022-03-17 12:05:17 +00:00
|
|
|
takeEvery(ReduxActionTypes.SET_FUNCTION_PROPERTY, setFunctionPropertySaga),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.UPDATE_JS_FUNCTION_PROPERTY_INIT,
|
|
|
|
|
handleUpdateJSFunctionPropertySaga,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.TOGGLE_FUNCTION_EXECUTE_ON_LOAD_INIT,
|
|
|
|
|
toggleFunctionExecuteOnLoadSaga,
|
|
|
|
|
),
|
2021-09-08 17:32:22 +00:00
|
|
|
]);
|
|
|
|
|
}
|