2024-05-27 07:07:18 +00:00
|
|
|
import type React from "react";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] 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
- [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
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { HttpMethod } from "api/Api";
|
|
|
|
|
import API from "api/Api";
|
|
|
|
|
import type { ApiResponse } from "./ApiResponses";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { DEFAULT_EXECUTE_ACTION_TIMEOUT_MS } from "ee/constants/ApiConstants";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] 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
- [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
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { AxiosPromise, CancelTokenSource } from "axios";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import type { Action, ActionViewMode } from "entities/Action";
|
|
|
|
|
import type { APIRequest } from "constants/AppsmithActionConstants/ActionConstants";
|
|
|
|
|
import type { WidgetType } from "constants/WidgetConstants";
|
2024-08-06 14:52:22 +00:00
|
|
|
import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers";
|
2025-02-24 09:18:34 +00:00
|
|
|
import type { PostActionRunConfig } from "./types";
|
2019-09-12 11:44:18 +00:00
|
|
|
|
2019-09-17 10:11:50 +00:00
|
|
|
export interface Property {
|
|
|
|
|
key: string;
|
2020-06-04 13:49:22 +00:00
|
|
|
value?: string;
|
2019-09-17 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type ActionCreateUpdateResponse = ApiResponse & {
|
2019-10-21 15:12:45 +00:00
|
|
|
id: string;
|
2024-07-31 02:54:51 +00:00
|
|
|
baseId: string;
|
2019-10-21 15:12:45 +00:00
|
|
|
jsonPathKeys: Record<string, string>;
|
2023-06-13 11:00:37 +00:00
|
|
|
datasource: {
|
|
|
|
|
id?: string;
|
|
|
|
|
};
|
2022-06-21 13:57:34 +00:00
|
|
|
};
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2020-03-12 20:27:39 +00:00
|
|
|
export type PaginationField = "PREV" | "NEXT";
|
2020-02-07 02:32:52 +00:00
|
|
|
|
2019-09-12 13:44:25 +00:00
|
|
|
export interface ExecuteActionRequest extends APIRequest {
|
[API breaking change : Automated Tests Will Fail] Page And Action Refactor (#549)
* Introduced new page which stores the published and unpublished pages as separate.
* Mid level commit to save the state.
* Parity of new page repository with old page repository (custom functions)
* WIP : Delete a page. This requires changes across application structure as well.
* Added publishedPages construct inside application to store the pages in the deployed view as well as isDefault so that the same changes (delete or isDefault) in unpublished view doesn't alter these fields for the published application
* Parity reached with PageService.
* Minor ActionService refactor to remove unnecessary code.
ApplicationPageService, LayoutActionService, LayoutService use the new page service to fetch the pages
Minor corrections in fetching the page from new page service in tests
* New save function which sets the PageDTO for unpublished page and then saves the new page into repository.
* Migration of page service functions to new page service functions across other services/tests/controller
* Finished migrating all the page service functions to the new page service functions
* Application Service Tests have been fixed.
* All the existing test cases are working now.
* Publish application implemented to store published pages as well. Added a basic test case to check that published pages is being set and that page's publishedPageDTO is being set accordingly.
* Minor TODOs added to add test cases for published application.
* A few tests to ascertain that published application page fields (deleted, isDefault) does not get changed when these statuses are changed for a page in edit mode.
* Added a new controller end point to fetch application in view mode.
* Added new endpoint for fetching an application in view mode on the client.
* Bug fix where get application in view mode API was not getting called.
* Fixed the get page names by application & archive pages which have been deleted in edit mode during publishing of application.
* During delete page, if a page was never published and it was deleted during edit, delete the entire page instead of just deleting the unpublished PageDTO
* Minor formatting.
* Non working client side code to fetch page list using view mode.
* revert unnecassary changes and streamlined view and edit actions
* Fix missed import
* Fixed a bug where if a page is not published, it should not be returned in view mode in list of page names api.
* Fixed update for a page which was not working in integration test.
* ActionDTO added.
* Solidified the new action structure.
* Migration added for NewAction index creation and NewAction per Action insertion in the database.
* Basic file structure added the new repository, custom repository, service, etc.
* Delete OldPage.java
* Repo functions added - TODO : Haven;t handled the published/edited views
* Helper functions added to convert Action to NewAction and vice-versa. Removed unused currentUserMono usage.
* Create & update action functionality added.
* Execute Action refactored. Removed dry run specific code.
* Repository migrated to handle new data structure. Execute action refactored to no longer support dry runs of actions.
* TODO added for special handling of change view of application to handle edge cases of pages/actions which either exist in published mode but don't exist in unpublished mode or vice versa.
* Migrated finding on load actions from spring repository to custom repository.
* In view mode, now actions are being fetched by application id directly instead of first fetching application and then using the page ids, fetching the actions. This reduces the db calls from 2 to 1 per fetch actions in view mode api call.
* Delete action and get all actions (used in edit mode on the client side) implemented.
* Updated CollectionService and ActionCollectionService to use the new action service instead of the old one.
* LayoutActionService refactored to now use the new service functions.
* ActionController now no longer used ActionService. The remaining service functions have been migrated to the new action service.
* Refactor across ACL code for addition/removal of policies during addition/removal of users to organization, making app public, refactor for services like policy utils, item service, etc.
* Removed the last of action repository and action service and replaced with new action repo and new action service.
* Compile and run time issues fixed. The server is coming up without any spring dependency errors.
* WIP in fixing fetching actions by page id.
* Finally!!! Fixed the fetch actions (both published and unpublished actions) by page id repository function.
* Fixed create action bug where null datasource in published actiondto (inside newly created action) leads to error.
* Fixed the execute action issues :
1. Removed the dry runs from the tests
2. Fixed the null pointer error in variable substituted action and datasource configurations.
* 1. Fixed the custom action repository field names.
2. Fixed the data structures used in ExamplesOrganizationClonerTests
* Fixed countByDatasourceId repository function which was querying the actions incorrectly.
* Fixed the clone example organization error where the id of the action was not getting updated in the page correctly. Yay!
* Fixed post merge compilation failure.
* Fixed more compilation time failures in ActionServiceTest
* Fixed failing test case for fetching actions in view mode.
* Minor changes to resolve merge changes and incorporate in the new refactored code.
* 1. Fixed compile time errors on Client code.
2. Fixed fetching of actions in view mode by application id. The repository function did not need name parameter. Removed the same.
* [Integration Testing Error Fix] : Added a new test case for refactor action name.
* Instead of fetching actions in the page, mistakenly used the base service which was fetching all the actions in the repository, barring none which led to the name refactor being blocked even though no action in the current page exists with the new proposed name,
* Added delete functionality to action service.
* Minor code cleanup
* Adding viewMode to action execution
* Replacing action with actionId.
* 1. Bug fix for deletion of unpublished action. In case of never published action, the entire action should be deleted. In case an action was published, only the unpublished action should be deleted.
2. In case of DB actions (external datasources), only the bare minimum fields should be stored inside the action (datasource id and datasource plugin id). The other fields should not be duplicated across code.
* Fixed yarn build compilation issues.
* Update app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
* Changed the API path for GET applications in view mode. Some minor code formatting.
* Incorporated review comments.
* Some more unnecessary code removed.
* Instead of returning Page, now the interface object between client and server for Pages is PageDTO
* Migrated Page and Action to PageDTO and ActionDTO
Fixed the compilation issues.
TODO : Fix the test compilation issues.
* Fixed compilation time issues with all the tests by migrating Page and Action to PageDTO and ActionDTO respectively
* Action Controller and Page Controller no longer extend Base Controller. All the required functions have now been implemented and no base line API end points are being re-used from the base.
* Test case fixes.
* Bug Fix : Updating an action was not updating execute on load. Fixed the data flow leading to the error.
* Deprecating Page and Action domain objects. This is to ensure no new code is written with these till we remove this old code.
* Cloned example applications are now published before returning. This is to ensure that the applications are in ready to view mode when the new user signs up.
* Added a function comment to expand on the usage of new param introduced.
* When cloning a page, new actions were not being stored. Added that. Also updated the clonePage test to assert that the actions are also cloned when the pages are cloned.
* Updated a Api call
* removed extra slash
Co-authored-by: Hetu Nandu <hetunandu@gmail.com>
Co-authored-by: Satbir Singh <satbir121@gmail.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: nandan.anantharamu <nandan@thinkify.io>
2020-10-26 12:34:23 +00:00
|
|
|
actionId: string;
|
2019-11-01 07:11:32 +00:00
|
|
|
params?: Property[];
|
2020-03-12 20:27:39 +00:00
|
|
|
paginationField?: PaginationField;
|
[API breaking change : Automated Tests Will Fail] Page And Action Refactor (#549)
* Introduced new page which stores the published and unpublished pages as separate.
* Mid level commit to save the state.
* Parity of new page repository with old page repository (custom functions)
* WIP : Delete a page. This requires changes across application structure as well.
* Added publishedPages construct inside application to store the pages in the deployed view as well as isDefault so that the same changes (delete or isDefault) in unpublished view doesn't alter these fields for the published application
* Parity reached with PageService.
* Minor ActionService refactor to remove unnecessary code.
ApplicationPageService, LayoutActionService, LayoutService use the new page service to fetch the pages
Minor corrections in fetching the page from new page service in tests
* New save function which sets the PageDTO for unpublished page and then saves the new page into repository.
* Migration of page service functions to new page service functions across other services/tests/controller
* Finished migrating all the page service functions to the new page service functions
* Application Service Tests have been fixed.
* All the existing test cases are working now.
* Publish application implemented to store published pages as well. Added a basic test case to check that published pages is being set and that page's publishedPageDTO is being set accordingly.
* Minor TODOs added to add test cases for published application.
* A few tests to ascertain that published application page fields (deleted, isDefault) does not get changed when these statuses are changed for a page in edit mode.
* Added a new controller end point to fetch application in view mode.
* Added new endpoint for fetching an application in view mode on the client.
* Bug fix where get application in view mode API was not getting called.
* Fixed the get page names by application & archive pages which have been deleted in edit mode during publishing of application.
* During delete page, if a page was never published and it was deleted during edit, delete the entire page instead of just deleting the unpublished PageDTO
* Minor formatting.
* Non working client side code to fetch page list using view mode.
* revert unnecassary changes and streamlined view and edit actions
* Fix missed import
* Fixed a bug where if a page is not published, it should not be returned in view mode in list of page names api.
* Fixed update for a page which was not working in integration test.
* ActionDTO added.
* Solidified the new action structure.
* Migration added for NewAction index creation and NewAction per Action insertion in the database.
* Basic file structure added the new repository, custom repository, service, etc.
* Delete OldPage.java
* Repo functions added - TODO : Haven;t handled the published/edited views
* Helper functions added to convert Action to NewAction and vice-versa. Removed unused currentUserMono usage.
* Create & update action functionality added.
* Execute Action refactored. Removed dry run specific code.
* Repository migrated to handle new data structure. Execute action refactored to no longer support dry runs of actions.
* TODO added for special handling of change view of application to handle edge cases of pages/actions which either exist in published mode but don't exist in unpublished mode or vice versa.
* Migrated finding on load actions from spring repository to custom repository.
* In view mode, now actions are being fetched by application id directly instead of first fetching application and then using the page ids, fetching the actions. This reduces the db calls from 2 to 1 per fetch actions in view mode api call.
* Delete action and get all actions (used in edit mode on the client side) implemented.
* Updated CollectionService and ActionCollectionService to use the new action service instead of the old one.
* LayoutActionService refactored to now use the new service functions.
* ActionController now no longer used ActionService. The remaining service functions have been migrated to the new action service.
* Refactor across ACL code for addition/removal of policies during addition/removal of users to organization, making app public, refactor for services like policy utils, item service, etc.
* Removed the last of action repository and action service and replaced with new action repo and new action service.
* Compile and run time issues fixed. The server is coming up without any spring dependency errors.
* WIP in fixing fetching actions by page id.
* Finally!!! Fixed the fetch actions (both published and unpublished actions) by page id repository function.
* Fixed create action bug where null datasource in published actiondto (inside newly created action) leads to error.
* Fixed the execute action issues :
1. Removed the dry runs from the tests
2. Fixed the null pointer error in variable substituted action and datasource configurations.
* 1. Fixed the custom action repository field names.
2. Fixed the data structures used in ExamplesOrganizationClonerTests
* Fixed countByDatasourceId repository function which was querying the actions incorrectly.
* Fixed the clone example organization error where the id of the action was not getting updated in the page correctly. Yay!
* Fixed post merge compilation failure.
* Fixed more compilation time failures in ActionServiceTest
* Fixed failing test case for fetching actions in view mode.
* Minor changes to resolve merge changes and incorporate in the new refactored code.
* 1. Fixed compile time errors on Client code.
2. Fixed fetching of actions in view mode by application id. The repository function did not need name parameter. Removed the same.
* [Integration Testing Error Fix] : Added a new test case for refactor action name.
* Instead of fetching actions in the page, mistakenly used the base service which was fetching all the actions in the repository, barring none which led to the name refactor being blocked even though no action in the current page exists with the new proposed name,
* Added delete functionality to action service.
* Minor code cleanup
* Adding viewMode to action execution
* Replacing action with actionId.
* 1. Bug fix for deletion of unpublished action. In case of never published action, the entire action should be deleted. In case an action was published, only the unpublished action should be deleted.
2. In case of DB actions (external datasources), only the bare minimum fields should be stored inside the action (datasource id and datasource plugin id). The other fields should not be duplicated across code.
* Fixed yarn build compilation issues.
* Update app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
* Changed the API path for GET applications in view mode. Some minor code formatting.
* Incorporated review comments.
* Some more unnecessary code removed.
* Instead of returning Page, now the interface object between client and server for Pages is PageDTO
* Migrated Page and Action to PageDTO and ActionDTO
Fixed the compilation issues.
TODO : Fix the test compilation issues.
* Fixed compilation time issues with all the tests by migrating Page and Action to PageDTO and ActionDTO respectively
* Action Controller and Page Controller no longer extend Base Controller. All the required functions have now been implemented and no base line API end points are being re-used from the base.
* Test case fixes.
* Bug Fix : Updating an action was not updating execute on load. Fixed the data flow leading to the error.
* Deprecating Page and Action domain objects. This is to ensure no new code is written with these till we remove this old code.
* Cloned example applications are now published before returning. This is to ensure that the applications are in ready to view mode when the new user signs up.
* Added a function comment to expand on the usage of new param introduced.
* When cloning a page, new actions were not being stored. Added that. Also updated the clonePage test to assert that the actions are also cloned when the pages are cloned.
* Updated a Api call
* removed extra slash
Co-authored-by: Hetu Nandu <hetunandu@gmail.com>
Co-authored-by: Satbir Singh <satbir121@gmail.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: nandan.anantharamu <nandan@thinkify.io>
2020-10-26 12:34:23 +00:00
|
|
|
viewMode: boolean;
|
2023-04-27 03:33:32 +00:00
|
|
|
paramProperties: Record<
|
|
|
|
|
string,
|
|
|
|
|
| string
|
|
|
|
|
| Record<string, Array<string>>
|
|
|
|
|
| Record<string, string>
|
|
|
|
|
| Record<string, Record<string, Array<string>>>
|
|
|
|
|
>;
|
2023-05-16 13:10:52 +00:00
|
|
|
analyticsProperties?: Record<string, boolean>;
|
2020-05-05 07:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-19 16:27:12 +00:00
|
|
|
export interface ActionApiResponseReq {
|
|
|
|
|
headers: Record<string, string[]>;
|
2020-11-03 13:05:40 +00:00
|
|
|
body: Record<string, unknown> | null;
|
2020-06-19 16:27:12 +00:00
|
|
|
httpMethod: HttpMethod | "";
|
|
|
|
|
url: string;
|
2023-06-29 13:53:25 +00:00
|
|
|
requestedAt?: number;
|
2020-06-19 16:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type ActionExecutionResponse = ApiResponse<{
|
|
|
|
|
body: Record<string, unknown> | string;
|
|
|
|
|
headers: Record<string, string[]>;
|
|
|
|
|
statusCode: string;
|
|
|
|
|
isExecutionSuccess: boolean;
|
|
|
|
|
request: ActionApiResponseReq;
|
|
|
|
|
errorType?: string;
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2022-06-21 13:57:34 +00:00
|
|
|
dataTypes: any[];
|
|
|
|
|
}> & {
|
2019-11-12 09:43:13 +00:00
|
|
|
clientMeta: {
|
|
|
|
|
duration: string;
|
|
|
|
|
size: string;
|
|
|
|
|
};
|
2022-06-21 13:57:34 +00:00
|
|
|
};
|
2019-11-12 09:43:13 +00:00
|
|
|
|
2021-07-26 16:44:10 +00:00
|
|
|
export interface SuggestedWidget {
|
|
|
|
|
type: WidgetType;
|
|
|
|
|
bindingQuery: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 09:43:13 +00:00
|
|
|
export interface ActionResponse {
|
2024-01-31 05:07:40 +00:00
|
|
|
body: React.ReactNode;
|
2019-10-29 12:02:58 +00:00
|
|
|
headers: Record<string, string[]>;
|
2020-06-19 17:33:02 +00:00
|
|
|
request?: ActionApiResponseReq;
|
2020-03-12 20:27:39 +00:00
|
|
|
statusCode: string;
|
2022-04-08 16:32:34 +00:00
|
|
|
dataTypes: Record<string, string>[];
|
2019-10-29 12:02:58 +00:00
|
|
|
duration: string;
|
|
|
|
|
size: string;
|
2020-08-05 10:23:07 +00:00
|
|
|
isExecutionSuccess?: boolean;
|
2021-07-26 16:44:10 +00:00
|
|
|
suggestedWidgets?: SuggestedWidget[];
|
2021-07-09 17:01:50 +00:00
|
|
|
messages?: Array<string>;
|
2021-09-01 10:15:45 +00:00
|
|
|
errorType?: string;
|
2021-10-14 11:04:43 +00:00
|
|
|
readableError?: string;
|
2022-04-08 16:32:34 +00:00
|
|
|
responseDisplayFormat?: string;
|
2023-02-18 12:55:46 +00:00
|
|
|
pluginErrorDetails?: PluginErrorDetails;
|
2025-02-24 09:18:34 +00:00
|
|
|
postRunAction?: PostActionRunConfig;
|
2023-02-18 12:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This contains the error details from the plugin that is sent to the client in the response
|
|
|
|
|
//title: The title of the error
|
|
|
|
|
//errorType: The type of error that occurred
|
|
|
|
|
//appsmithErrorCode: The error code that is used to identify the error in the appsmith
|
|
|
|
|
//appsmithErrorMessage: The appsmith error message that is shown to the user
|
|
|
|
|
//downstreamErrorCode: The error code that is sent by the plugin
|
|
|
|
|
//downstreamErrorMessage: The error message that is sent by the plugin
|
|
|
|
|
export interface PluginErrorDetails {
|
|
|
|
|
title: string;
|
|
|
|
|
errorType: string;
|
|
|
|
|
appsmithErrorCode: string;
|
|
|
|
|
appsmithErrorMessage: string;
|
|
|
|
|
downstreamErrorCode?: string;
|
|
|
|
|
downstreamErrorMessage?: string;
|
2019-10-29 12:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 09:54:40 +00:00
|
|
|
export interface MoveActionRequest {
|
2021-01-12 04:17:28 +00:00
|
|
|
action: Action;
|
2020-01-24 09:54:40 +00:00
|
|
|
destinationPageId: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 10:23:19 +00:00
|
|
|
export interface UpdateActionNameRequest {
|
2023-12-21 04:52:54 +00:00
|
|
|
pageId?: string;
|
2021-04-19 07:05:10 +00:00
|
|
|
actionId: string;
|
2023-12-21 04:52:54 +00:00
|
|
|
layoutId?: string;
|
2020-06-16 10:23:19 +00:00
|
|
|
newName: string;
|
|
|
|
|
oldName: string;
|
2023-12-21 04:52:54 +00:00
|
|
|
moduleId?: string;
|
2024-03-05 04:58:34 +00:00
|
|
|
workflowId?: string;
|
2023-12-26 06:08:00 +00:00
|
|
|
contextType?: ActionParentEntityTypeInterface;
|
2020-06-16 10:23:19 +00:00
|
|
|
}
|
2023-12-13 17:43:43 +00:00
|
|
|
|
|
|
|
|
export interface FetchActionsPayload {
|
|
|
|
|
applicationId?: string;
|
|
|
|
|
workflowId?: string;
|
|
|
|
|
}
|
2019-09-17 10:11:50 +00:00
|
|
|
class ActionAPI extends API {
|
|
|
|
|
static url = "v1/actions";
|
2020-10-15 15:28:54 +00:00
|
|
|
static apiUpdateCancelTokenSource: CancelTokenSource;
|
|
|
|
|
static queryUpdateCancelTokenSource: CancelTokenSource;
|
2022-08-12 07:19:17 +00:00
|
|
|
static abortActionExecutionTokenSource: CancelTokenSource;
|
2019-09-12 11:44:18 +00:00
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async createAction(
|
2020-12-30 07:31:20 +00:00
|
|
|
apiConfig: Partial<Action>,
|
2023-10-09 13:54:06 +00:00
|
|
|
): Promise<AxiosPromise<ActionCreateUpdateResponse>> {
|
2024-06-24 11:47:23 +00:00
|
|
|
const payload = {
|
|
|
|
|
...apiConfig,
|
|
|
|
|
eventData: undefined,
|
|
|
|
|
isValid: undefined,
|
|
|
|
|
entityReferenceType: undefined,
|
|
|
|
|
datasource: {
|
|
|
|
|
...apiConfig.datasource,
|
|
|
|
|
isValid: undefined,
|
|
|
|
|
new: undefined,
|
|
|
|
|
},
|
|
|
|
|
};
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-06-24 11:47:23 +00:00
|
|
|
return API.post(ActionAPI.url, payload);
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async fetchActions(
|
2023-12-13 17:43:43 +00:00
|
|
|
payload: FetchActionsPayload,
|
2023-10-09 13:54:06 +00:00
|
|
|
): Promise<AxiosPromise<ApiResponse<Action[]>>> {
|
2023-12-13 17:43:43 +00:00
|
|
|
return API.get(ActionAPI.url, payload);
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async fetchActionsForViewMode(
|
2020-07-15 13:01:35 +00:00
|
|
|
applicationId: string,
|
2023-10-09 13:54:06 +00:00
|
|
|
): Promise<AxiosPromise<ApiResponse<ActionViewMode[]>>> {
|
2020-07-15 13:01:35 +00:00
|
|
|
return API.get(`${ActionAPI.url}/view`, { applicationId });
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async fetchActionsByPageId(
|
2020-02-21 12:16:49 +00:00
|
|
|
pageId: string,
|
2023-10-09 13:54:06 +00:00
|
|
|
): Promise<AxiosPromise<ApiResponse<Action[]>>> {
|
2020-02-21 12:16:49 +00:00
|
|
|
return API.get(ActionAPI.url, { pageId });
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async updateAction(
|
2021-01-12 04:17:28 +00:00
|
|
|
apiConfig: Partial<Action>,
|
2023-10-09 13:54:06 +00:00
|
|
|
): Promise<AxiosPromise<ActionCreateUpdateResponse>> {
|
2020-10-15 15:28:54 +00:00
|
|
|
if (ActionAPI.apiUpdateCancelTokenSource) {
|
|
|
|
|
ActionAPI.apiUpdateCancelTokenSource.cancel();
|
|
|
|
|
}
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2020-10-15 15:28:54 +00:00
|
|
|
ActionAPI.apiUpdateCancelTokenSource = axios.CancelToken.source();
|
2024-06-25 07:33:36 +00:00
|
|
|
const payload: Partial<Action & { entityReferenceType: unknown }> = {
|
2024-05-27 07:07:18 +00:00
|
|
|
...apiConfig,
|
|
|
|
|
name: undefined,
|
|
|
|
|
entityReferenceType: undefined,
|
2024-06-25 07:33:36 +00:00
|
|
|
actionConfiguration: apiConfig.actionConfiguration && {
|
|
|
|
|
...apiConfig.actionConfiguration,
|
|
|
|
|
autoGeneratedHeaders:
|
|
|
|
|
apiConfig.actionConfiguration.autoGeneratedHeaders?.map(
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-06-25 07:33:36 +00:00
|
|
|
(header: any) => ({
|
|
|
|
|
...header,
|
|
|
|
|
isInvalid: undefined,
|
|
|
|
|
}),
|
|
|
|
|
) ?? undefined,
|
|
|
|
|
},
|
|
|
|
|
datasource: apiConfig.datasource && {
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2024-06-25 07:33:36 +00:00
|
|
|
...(apiConfig as any).datasource,
|
2024-05-27 07:07:18 +00:00
|
|
|
datasourceStorages: undefined,
|
|
|
|
|
isValid: undefined,
|
2024-06-24 11:47:23 +00:00
|
|
|
new: undefined,
|
2024-06-25 07:33:36 +00:00
|
|
|
},
|
|
|
|
|
};
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-06-25 07:33:36 +00:00
|
|
|
return API.put(`${ActionAPI.url}/${apiConfig.id}`, payload, undefined, {
|
2020-10-15 15:28:54 +00:00
|
|
|
cancelToken: ActionAPI.apiUpdateCancelTokenSource.token,
|
|
|
|
|
});
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async updateActionName(
|
|
|
|
|
updateActionNameRequest: UpdateActionNameRequest,
|
|
|
|
|
) {
|
2020-06-16 10:23:19 +00:00
|
|
|
return API.put(ActionAPI.url + "/refactor", updateActionNameRequest);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async deleteAction(id: string) {
|
2019-10-21 15:12:45 +00:00
|
|
|
return API.delete(`${ActionAPI.url}/${id}`);
|
2019-09-12 11:44:18 +00:00
|
|
|
}
|
2023-11-24 07:39:02 +00:00
|
|
|
private static async executeApiCall(
|
2022-03-02 16:01:50 +00:00
|
|
|
executeAction: FormData,
|
2020-05-07 08:07:29 +00:00
|
|
|
timeout?: number,
|
2023-10-09 13:54:06 +00:00
|
|
|
): Promise<AxiosPromise<ActionExecutionResponse>> {
|
2020-05-05 08:13:39 +00:00
|
|
|
return API.post(ActionAPI.url + "/execute", executeAction, undefined, {
|
2020-05-07 08:07:29 +00:00
|
|
|
timeout: timeout || DEFAULT_EXECUTE_ACTION_TIMEOUT_MS,
|
2022-03-02 16:01:50 +00:00
|
|
|
headers: {
|
|
|
|
|
accept: "application/json",
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
},
|
2022-08-12 07:19:17 +00:00
|
|
|
cancelToken: ActionAPI.abortActionExecutionTokenSource.token,
|
2020-05-05 08:13:39 +00:00
|
|
|
});
|
2019-09-16 10:37:38 +00:00
|
|
|
}
|
2020-01-24 09:54:40 +00:00
|
|
|
|
2023-11-24 07:39:02 +00:00
|
|
|
static async executeAction(
|
|
|
|
|
executeAction: FormData,
|
|
|
|
|
timeout?: number,
|
|
|
|
|
): Promise<AxiosPromise<ActionExecutionResponse>> {
|
|
|
|
|
ActionAPI.abortActionExecutionTokenSource = axios.CancelToken.source();
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-10-29 05:55:43 +00:00
|
|
|
return await this.executeApiCall(executeAction, timeout);
|
2023-11-24 07:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async moveAction(moveRequest: MoveActionRequest) {
|
2024-06-25 07:33:36 +00:00
|
|
|
const payload = {
|
|
|
|
|
...moveRequest,
|
|
|
|
|
action: moveRequest.action && {
|
|
|
|
|
...moveRequest.action,
|
|
|
|
|
entityReferenceType: undefined,
|
|
|
|
|
datasource: moveRequest.action.datasource && {
|
|
|
|
|
...moveRequest.action.datasource,
|
|
|
|
|
isValid: undefined,
|
|
|
|
|
new: undefined,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-06-25 07:33:36 +00:00
|
|
|
return API.put(ActionAPI.url + "/move", payload, undefined, {
|
2020-07-06 13:35:31 +00:00
|
|
|
timeout: DEFAULT_EXECUTE_ACTION_TIMEOUT_MS,
|
|
|
|
|
});
|
2020-01-24 09:54:40 +00:00
|
|
|
}
|
2020-05-05 07:50:30 +00:00
|
|
|
|
2023-10-09 13:54:06 +00:00
|
|
|
static async toggleActionExecuteOnLoad(
|
|
|
|
|
actionId: string,
|
|
|
|
|
shouldExecute: boolean,
|
|
|
|
|
) {
|
2020-08-27 15:39:16 +00:00
|
|
|
return API.put(ActionAPI.url + `/executeOnLoad/${actionId}`, undefined, {
|
|
|
|
|
flag: shouldExecute.toString(),
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-09-12 12:19:46 +00:00
|
|
|
}
|
2019-09-12 11:44:18 +00:00
|
|
|
|
2019-09-16 10:37:38 +00:00
|
|
|
export default ActionAPI;
|