PromucFlow_constructor/app/client/src/api/ActionAPI.tsx

198 lines
5.1 KiB
TypeScript
Raw Normal View History

import API, { HttpMethod } from "api/Api";
import { ApiResponse, GenericApiResponse, ResponseMeta } from "./ApiResponses";
import { DEFAULT_EXECUTE_ACTION_TIMEOUT_MS } from "@appsmith/constants/ApiConstants";
import axios, { AxiosPromise, CancelTokenSource } from "axios";
import { Action, ActionViewMode } from "entities/Action";
import { APIRequest } from "constants/AppsmithActionConstants/ActionConstants";
[Feature] new nav sniping mode (#5746) * added sniping mode toggle option to header * added cover to components on hover in sniping mode * fixed the transition time * using filled icon * Show dependencies in action pane * Added a wrapper to make a widget snipeable * removed older parts of sniping from Positioned Container * removed onclick action from snipeable wrapper * Showing widget name in different color * Added a mechanism to send user to sniping mode from successful API screen * created new property pane saga to bind the data * Fix datasource list width issue * Fix sidebar going out of view when the response is a table * Minor refactor * Show add widgets section on the sidebar * Stop showing autocomplete option after adding a widget * fetching pageId, appId from store * Get suggested widget from response * Fix table data not getting evaluated after adding binding * Fix property pane going below the entity explorer while navigating from query/api pane * Fix width of sidepane shifting for apis * Fix vertical margins of connections * Fix api pane suggested widget showing up for errors * Fix margins * can show select in canvas btn in sidebar * can get the action object at the end to bind the data * updated saga and action names * can bind data to table * Use themes * Use new image url for Table widget * Added conditional mapping for sniping mode binding. * updated the widget name tags and seq of calls to open property pane * pushed all sniping mode decoration to header * moved setting sniping mode logic to editor reducer * Added keyboard short cut to get out of sniping mode * updated reset sniping mechanism * removed a divider line * if there are no relationships, will not show the complete section * Connect Data will automatically show relevant tab in integrations * Update list and dropdown image urls * Remove create table button * no wrapping bind to text * minor review considerations * showing the widget name to left in sniping mode * can set data to datepicker * will not show snipe btn if there are no widgets in canvas * Changes for multiple suggested widgets * removed dependency of sniping from suggested widgets * Added analytics events for sniping mode * logic for binding data to a widget, moved to snipeable component * changed binding widget func from capture to onClick and took care of sniping from widget wrapper too. * added tests to check sniping mode for table * updated test spec * minor fix * Fix copy changes * Update test to use table widget from suggested widget list * if fails to bind will generate warning and keep user in sniping mode * in sniping mode will only show name plate if it is under focus * fixed the test case * added a comment * minor fix to capture on click event in sniping mode * updated text * Hide connections UI when there are no connections * Increase width to 90% * Show placeholder text and back button in sidepane * Show tooltip on hover * Add analyitcs events for suggested widgets and connections * Update label based on whether widgets are there or not * binding related changes * renamed the saga file containing sinping mode sagas * Changes for inspect entity * Revert "binding related changes" temporarily This reverts commit 54ae9667fecf24bc3cf9912a5356d06600b25c84. * Update suggested widgets url * Update table url * Fix chart data field not getting evaluated * a minor fix to show proper tool tip when user hovers on widget name * Show sidepane when there is output * Update locators * Use constants for messages * Update file name to ApiRightPane * Remove delay * Revert "Revert "binding related changes" temporarily" This reverts commit ee7f75e83218137250b4b9a28fcf63080c185150. * Fix width * Fix overlap Co-authored-by: Akash N <akash@codemonk.in>
2021-07-26 16:44:10 +00:00
import { WidgetType } from "constants/WidgetConstants";
2019-09-12 11:44:18 +00:00
export interface CreateActionRequest<T> extends APIRequest {
2019-11-07 09:32:38 +00:00
datasourceId: string;
2019-10-21 15:12:45 +00:00
pageId: string;
name: string;
2019-09-16 10:37:38 +00:00
actionConfiguration: T;
2019-09-12 11:44:18 +00:00
}
export interface UpdateActionRequest<T> extends CreateActionRequest<T> {
2019-09-16 10:37:38 +00:00
actionId: string;
2019-09-12 11:44:18 +00:00
}
export interface Property {
key: string;
2020-06-04 13:49:22 +00:00
value?: string;
}
export interface BodyFormData {
editable: boolean;
mandatory: boolean;
description: string;
key: string;
value?: string;
type: string;
}
2019-09-12 11:44:18 +00:00
export interface QueryConfig {
2019-09-16 10:37:38 +00:00
queryString: string;
2019-09-12 11:44:18 +00:00
}
2019-09-16 10:37:38 +00:00
export interface ActionCreateUpdateResponse extends ApiResponse {
2019-10-21 15:12:45 +00:00
id: string;
jsonPathKeys: Record<string, string>;
}
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;
}
2019-09-12 13:44:25 +00:00
export interface ExecuteActionResponse extends ApiResponse {
2019-09-16 10:37:38 +00:00
actionId: string;
data: any;
2019-09-12 13:44:25 +00:00
}
2020-06-19 16:27:12 +00:00
export interface ActionApiResponseReq {
headers: Record<string, string[]>;
body: Record<string, unknown> | null;
2020-06-19 16:27:12 +00:00
httpMethod: HttpMethod | "";
url: string;
}
export interface ActionExecutionResponse {
2019-11-12 09:43:13 +00:00
responseMeta: ResponseMeta;
data: {
body: Record<string, unknown> | string;
2019-11-12 09:43:13 +00:00
headers: Record<string, string[]>;
2020-03-12 20:27:39 +00:00
statusCode: string;
isExecutionSuccess: boolean;
2020-06-19 16:27:12 +00:00
request: ActionApiResponseReq;
errorType?: string;
dataTypes: any[];
2019-11-12 09:43:13 +00:00
};
clientMeta: {
duration: string;
size: string;
};
}
[Feature] new nav sniping mode (#5746) * added sniping mode toggle option to header * added cover to components on hover in sniping mode * fixed the transition time * using filled icon * Show dependencies in action pane * Added a wrapper to make a widget snipeable * removed older parts of sniping from Positioned Container * removed onclick action from snipeable wrapper * Showing widget name in different color * Added a mechanism to send user to sniping mode from successful API screen * created new property pane saga to bind the data * Fix datasource list width issue * Fix sidebar going out of view when the response is a table * Minor refactor * Show add widgets section on the sidebar * Stop showing autocomplete option after adding a widget * fetching pageId, appId from store * Get suggested widget from response * Fix table data not getting evaluated after adding binding * Fix property pane going below the entity explorer while navigating from query/api pane * Fix width of sidepane shifting for apis * Fix vertical margins of connections * Fix api pane suggested widget showing up for errors * Fix margins * can show select in canvas btn in sidebar * can get the action object at the end to bind the data * updated saga and action names * can bind data to table * Use themes * Use new image url for Table widget * Added conditional mapping for sniping mode binding. * updated the widget name tags and seq of calls to open property pane * pushed all sniping mode decoration to header * moved setting sniping mode logic to editor reducer * Added keyboard short cut to get out of sniping mode * updated reset sniping mechanism * removed a divider line * if there are no relationships, will not show the complete section * Connect Data will automatically show relevant tab in integrations * Update list and dropdown image urls * Remove create table button * no wrapping bind to text * minor review considerations * showing the widget name to left in sniping mode * can set data to datepicker * will not show snipe btn if there are no widgets in canvas * Changes for multiple suggested widgets * removed dependency of sniping from suggested widgets * Added analytics events for sniping mode * logic for binding data to a widget, moved to snipeable component * changed binding widget func from capture to onClick and took care of sniping from widget wrapper too. * added tests to check sniping mode for table * updated test spec * minor fix * Fix copy changes * Update test to use table widget from suggested widget list * if fails to bind will generate warning and keep user in sniping mode * in sniping mode will only show name plate if it is under focus * fixed the test case * added a comment * minor fix to capture on click event in sniping mode * updated text * Hide connections UI when there are no connections * Increase width to 90% * Show placeholder text and back button in sidepane * Show tooltip on hover * Add analyitcs events for suggested widgets and connections * Update label based on whether widgets are there or not * binding related changes * renamed the saga file containing sinping mode sagas * Changes for inspect entity * Revert "binding related changes" temporarily This reverts commit 54ae9667fecf24bc3cf9912a5356d06600b25c84. * Update suggested widgets url * Update table url * Fix chart data field not getting evaluated * a minor fix to show proper tool tip when user hovers on widget name * Show sidepane when there is output * Update locators * Use constants for messages * Update file name to ApiRightPane * Remove delay * Revert "Revert "binding related changes" temporarily" This reverts commit ee7f75e83218137250b4b9a28fcf63080c185150. * Fix width * Fix overlap Co-authored-by: Akash N <akash@codemonk.in>
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 {
body: unknown;
headers: Record<string, string[]>;
2020-06-19 17:33:02 +00:00
request?: ActionApiResponseReq;
2020-03-12 20:27:39 +00:00
statusCode: string;
dataTypes: Record<string, string>[];
duration: string;
size: string;
isExecutionSuccess?: boolean;
[Feature] new nav sniping mode (#5746) * added sniping mode toggle option to header * added cover to components on hover in sniping mode * fixed the transition time * using filled icon * Show dependencies in action pane * Added a wrapper to make a widget snipeable * removed older parts of sniping from Positioned Container * removed onclick action from snipeable wrapper * Showing widget name in different color * Added a mechanism to send user to sniping mode from successful API screen * created new property pane saga to bind the data * Fix datasource list width issue * Fix sidebar going out of view when the response is a table * Minor refactor * Show add widgets section on the sidebar * Stop showing autocomplete option after adding a widget * fetching pageId, appId from store * Get suggested widget from response * Fix table data not getting evaluated after adding binding * Fix property pane going below the entity explorer while navigating from query/api pane * Fix width of sidepane shifting for apis * Fix vertical margins of connections * Fix api pane suggested widget showing up for errors * Fix margins * can show select in canvas btn in sidebar * can get the action object at the end to bind the data * updated saga and action names * can bind data to table * Use themes * Use new image url for Table widget * Added conditional mapping for sniping mode binding. * updated the widget name tags and seq of calls to open property pane * pushed all sniping mode decoration to header * moved setting sniping mode logic to editor reducer * Added keyboard short cut to get out of sniping mode * updated reset sniping mechanism * removed a divider line * if there are no relationships, will not show the complete section * Connect Data will automatically show relevant tab in integrations * Update list and dropdown image urls * Remove create table button * no wrapping bind to text * minor review considerations * showing the widget name to left in sniping mode * can set data to datepicker * will not show snipe btn if there are no widgets in canvas * Changes for multiple suggested widgets * removed dependency of sniping from suggested widgets * Added analytics events for sniping mode * logic for binding data to a widget, moved to snipeable component * changed binding widget func from capture to onClick and took care of sniping from widget wrapper too. * added tests to check sniping mode for table * updated test spec * minor fix * Fix copy changes * Update test to use table widget from suggested widget list * if fails to bind will generate warning and keep user in sniping mode * in sniping mode will only show name plate if it is under focus * fixed the test case * added a comment * minor fix to capture on click event in sniping mode * updated text * Hide connections UI when there are no connections * Increase width to 90% * Show placeholder text and back button in sidepane * Show tooltip on hover * Add analyitcs events for suggested widgets and connections * Update label based on whether widgets are there or not * binding related changes * renamed the saga file containing sinping mode sagas * Changes for inspect entity * Revert "binding related changes" temporarily This reverts commit 54ae9667fecf24bc3cf9912a5356d06600b25c84. * Update suggested widgets url * Update table url * Fix chart data field not getting evaluated * a minor fix to show proper tool tip when user hovers on widget name * Show sidepane when there is output * Update locators * Use constants for messages * Update file name to ApiRightPane * Remove delay * Revert "Revert "binding related changes" temporarily" This reverts commit ee7f75e83218137250b4b9a28fcf63080c185150. * Fix width * Fix overlap Co-authored-by: Akash N <akash@codemonk.in>
2021-07-26 16:44:10 +00:00
suggestedWidgets?: SuggestedWidget[];
messages?: Array<string>;
errorType?: string;
readableError?: string;
responseDisplayFormat?: string;
}
2020-01-24 09:54:40 +00:00
export interface MoveActionRequest {
action: Action;
2020-01-24 09:54:40 +00:00
destinationPageId: string;
}
export interface CopyActionRequest {
action: Action;
2020-01-24 09:54:40 +00:00
pageId: string;
}
2020-06-16 10:23:19 +00:00
export interface UpdateActionNameRequest {
pageId: string;
actionId: string;
2020-06-16 10:23:19 +00:00
layoutId: string;
newName: string;
oldName: string;
}
class ActionAPI extends API {
static url = "v1/actions";
static apiUpdateCancelTokenSource: CancelTokenSource;
static queryUpdateCancelTokenSource: CancelTokenSource;
2019-09-12 11:44:18 +00:00
static createAction(
2020-12-30 07:31:20 +00:00
apiConfig: Partial<Action>,
): AxiosPromise<ActionCreateUpdateResponse> {
2019-10-21 15:12:45 +00:00
return API.post(ActionAPI.url, apiConfig);
}
static fetchActions(
2020-01-24 09:54:40 +00:00
applicationId: string,
): AxiosPromise<GenericApiResponse<Action[]>> {
2020-01-24 09:54:40 +00:00
return API.get(ActionAPI.url, { applicationId });
2019-10-21 15:12:45 +00:00
}
static fetchActionsForViewMode(
applicationId: string,
): AxiosPromise<GenericApiResponse<ActionViewMode[]>> {
return API.get(`${ActionAPI.url}/view`, { applicationId });
}
2020-02-21 12:16:49 +00:00
static fetchActionsByPageId(
pageId: string,
): AxiosPromise<GenericApiResponse<Action[]>> {
2020-02-21 12:16:49 +00:00
return API.get(ActionAPI.url, { pageId });
}
static updateAction(
apiConfig: Partial<Action>,
): AxiosPromise<ActionCreateUpdateResponse> {
if (ActionAPI.apiUpdateCancelTokenSource) {
ActionAPI.apiUpdateCancelTokenSource.cancel();
}
ActionAPI.apiUpdateCancelTokenSource = axios.CancelToken.source();
const action = Object.assign({}, apiConfig);
// While this line is not required, name can not be changed from this endpoint
delete action.name;
return API.put(`${ActionAPI.url}/${action.id}`, action, undefined, {
cancelToken: ActionAPI.apiUpdateCancelTokenSource.token,
});
2019-09-12 11:44:18 +00:00
}
2020-06-16 10:23:19 +00:00
static updateActionName(updateActionNameRequest: UpdateActionNameRequest) {
return API.put(ActionAPI.url + "/refactor", updateActionNameRequest);
}
2019-10-21 15:12:45 +00:00
static deleteAction(id: string) {
return API.delete(`${ActionAPI.url}/${id}`);
2019-09-12 11:44:18 +00:00
}
2019-09-16 10:37:38 +00:00
static executeAction(
executeAction: FormData,
2020-05-07 08:07:29 +00:00
timeout?: number,
): 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,
headers: {
accept: "application/json",
"Content-Type": "multipart/form-data",
},
2020-05-05 08:13:39 +00:00
});
2019-09-16 10:37:38 +00:00
}
2020-01-24 09:54:40 +00:00
static moveAction(moveRequest: MoveActionRequest) {
return API.put(ActionAPI.url + "/move", moveRequest, undefined, {
timeout: DEFAULT_EXECUTE_ACTION_TIMEOUT_MS,
});
2020-01-24 09:54:40 +00:00
}
static toggleActionExecuteOnLoad(actionId: string, shouldExecute: boolean) {
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;