## Description Refactor for updating js object function name change refactor logic to include modules #### PR fixes following issue(s) PR for https://github.com/appsmithorg/appsmith-ee/pull/3242 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### 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 - [ ] 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 - [ ] 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 - **Refactor** - Improved action interface to enhance flexibility in action management. - **New Features** - Introduced module support within the action framework. - **Tests** - Updated tests to accommodate new module-related changes. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
131 lines
3.6 KiB
TypeScript
131 lines
3.6 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;
|
|
moduleId?: string;
|
|
contextType?: ActionParentEntityTypeInterface;
|
|
}
|
|
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;
|