PromucFlow_constructor/app/client/src/ce/api/JSActionAPI.tsx
Trisha Anand 72504222e7
chore: Splitting JS Object body dump vs parsed JS Object update to remove race condition originated bad state (#33124)
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9029211697>
> Commit: 190f7682cad3117e776d94f1502609026633369c
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9029211697&attempt=1"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->










## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No

---------

Co-authored-by: Nidhi Nair <nidhi@appsmith.com>
Co-authored-by: Diljit VJ <diljit@appsmith.com>
2024-05-13 09:38:30 +05:30

139 lines
3.9 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<JSCollection>;
export interface MoveJSCollectionRequest {
collectionId: string;
destinationPageId: string;
name: string;
}
export interface UpdateJSObjectNameRequest {
pageId?: string;
actionCollectionId: string;
layoutId?: string;
newName: string;
oldName: string;
moduleId?: string;
workflowId?: 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 updateJSCollectionBody(
jsCollectionId: string,
jsCollectionBody: string,
): Promise<AxiosPromise<JSCollectionCreateUpdateResponse>> {
return API.put(`${JSActionAPI.url}/${jsCollectionId}/body`, {
body: jsCollectionBody,
});
}
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;