PromucFlow_constructor/app/client/src/ce/api/JSActionAPI.tsx
Ankita Kinger cc61ca4c47
chore: Refactoring queries/JS section on entity explorer to support private entities on packages (#29703)
## Description

Refactoring queries/JS section on entity explorer to support private
entities on packages

#### PR fixes following issue(s)
Fixes [#28495](https://github.com/appsmithorg/appsmith/issues/28495)

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## 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
- [x] 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
- [x] 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

## Summary by CodeRabbit

- **New Features**
  - Introduced new search filtering capabilities in the global search.
- Enhanced the `EntityExplorer` component to selectively display files
based on new criteria.

- **Enhancements**
- Expanded `JSCollection` interface to support workflow associations and
contextual actions.

- **Refactor**
- Streamlined naming functions with the introduction of
`CreateNewActionKey` enum to ensure consistency in action creation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2023-12-18 22:37:32 +05:30

126 lines
3.4 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 { ActionContextType } from "@appsmith/entities/DataTree/types";
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;
}
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?: ActionContextType;
}
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;