## Description Refactoring code to fix a couple of issues related to modules on EE #### PR fixes following issue(s) Fixes [#29842](https://github.com/appsmithorg/appsmith/issues/29842) [#29445](https://github.com/appsmithorg/appsmith/issues/29445) #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [x] Manual - [ ] JUnit - [ ] Jest - [x] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [x] 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: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new interface for improved action context handling. - Added functionality to create API actions based on the editor type. - Implemented a new hook for retrieving parent entity information in the datasource editor. - **Refactor** - Updated various components to utilize the new `ActionParentEntityTypeInterface`. - Enhanced reducer logic for better handling of action configurations. - Streamlined entity exports and imports for consistency. - **Bug Fixes** - Fixed redirection logic in the Datasource Blank State component for a smoother user experience. - **Chores** - Removed unused event listeners from sagas to optimize performance. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
129 lines
3.5 KiB
TypeScript
129 lines
3.5 KiB
TypeScript
import API from "api/Api";
|
|
import type { AxiosPromise } from "axios";
|
|
import type { JSCollection } from "entities/JSCollection";
|
|
import type { ApiResponse } from "api/ApiResponses";
|
|
import type { Variable, JSAction } from "entities/JSCollection";
|
|
import type { PluginType } from "entities/Action";
|
|
import type { FetchActionsPayload } from "api/ActionAPI";
|
|
import type { ActionParentEntityTypeInterface } from "@appsmith/entities/Engine/actionHelpers";
|
|
|
|
export type JSCollectionCreateUpdateResponse = ApiResponse & {
|
|
id: string;
|
|
};
|
|
|
|
export interface MoveJSCollectionRequest {
|
|
collectionId: string;
|
|
destinationPageId: string;
|
|
name: string;
|
|
}
|
|
export interface UpdateJSObjectNameRequest {
|
|
pageId?: string;
|
|
actionCollectionId: string;
|
|
layoutId?: string;
|
|
newName: string;
|
|
oldName: string;
|
|
moduleId?: string;
|
|
contextType?: ActionParentEntityTypeInterface;
|
|
}
|
|
|
|
export interface CreateJSCollectionRequest {
|
|
name: string;
|
|
pageId: string;
|
|
workspaceId: string;
|
|
pluginId: string;
|
|
body: string;
|
|
variables: Array<Variable>;
|
|
actions: Array<Partial<JSAction>>;
|
|
applicationId: string;
|
|
pluginType: PluginType;
|
|
workflowId?: string;
|
|
contextType?: ActionParentEntityTypeInterface;
|
|
moduleId?: string;
|
|
}
|
|
|
|
export interface SetFunctionPropertyPayload {
|
|
action: JSAction;
|
|
propertyName: string;
|
|
value: any;
|
|
}
|
|
export interface RefactorAction {
|
|
pageId: string;
|
|
actionId: string;
|
|
newName: string;
|
|
oldName: string;
|
|
collectionName: string;
|
|
}
|
|
export interface RefactorActionRequest extends RefactorAction {
|
|
layoutId: string;
|
|
}
|
|
|
|
export interface UpdateCollectionActionNameRequest
|
|
extends RefactorActionRequest {
|
|
actionCollection: JSCollection;
|
|
}
|
|
class JSActionAPI extends API {
|
|
static url = "v1/collections/actions";
|
|
|
|
static async fetchJSCollections(
|
|
payload: FetchActionsPayload,
|
|
): Promise<AxiosPromise<ApiResponse<JSCollection[]>>> {
|
|
return API.get(JSActionAPI.url, payload);
|
|
}
|
|
|
|
static async createJSCollection(
|
|
jsConfig: CreateJSCollectionRequest,
|
|
): Promise<AxiosPromise<JSCollectionCreateUpdateResponse>> {
|
|
return API.post(JSActionAPI.url, jsConfig);
|
|
}
|
|
|
|
static async copyJSCollection(
|
|
jsConfig: Partial<JSCollection>,
|
|
): Promise<AxiosPromise<JSCollectionCreateUpdateResponse>> {
|
|
return API.post(JSActionAPI.url, jsConfig);
|
|
}
|
|
|
|
static async updateJSCollection(
|
|
jsConfig: JSCollection,
|
|
): Promise<AxiosPromise<JSCollectionCreateUpdateResponse>> {
|
|
const jsAction = Object.assign({}, jsConfig);
|
|
return API.put(`${JSActionAPI.url}/${jsAction.id}`, jsAction);
|
|
}
|
|
|
|
static async deleteJSCollection(id: string) {
|
|
return API.delete(`${JSActionAPI.url}/${id}`);
|
|
}
|
|
|
|
static async moveJSCollection(moveRequest: MoveJSCollectionRequest) {
|
|
return API.put(JSActionAPI.url + "/move", moveRequest);
|
|
}
|
|
|
|
static async fetchJSCollectionsByPageId(
|
|
pageId: string,
|
|
): Promise<AxiosPromise<ApiResponse<JSCollection[]>>> {
|
|
return API.get(JSActionAPI.url, { pageId });
|
|
}
|
|
|
|
static async fetchJSCollectionsForViewMode(
|
|
applicationId: string,
|
|
): Promise<AxiosPromise<ApiResponse<JSCollection[]>>> {
|
|
return API.get(`${JSActionAPI.url}/view`, { applicationId });
|
|
}
|
|
|
|
static async updateJSCollectionOrActionName(
|
|
updateJSObjectNameRequest: UpdateJSObjectNameRequest,
|
|
) {
|
|
return API.put(JSActionAPI.url + "/refactor", updateJSObjectNameRequest);
|
|
}
|
|
|
|
static async updateJSCollectionActionRefactor(
|
|
updateJSCollectionActionName: UpdateCollectionActionNameRequest,
|
|
) {
|
|
return API.put(
|
|
JSActionAPI.url + "/refactorAction",
|
|
updateJSCollectionActionName,
|
|
);
|
|
}
|
|
}
|
|
|
|
export default JSActionAPI;
|