2021-09-08 17:32:22 +00:00
|
|
|
import API from "api/Api";
|
|
|
|
|
import { AxiosPromise } from "axios";
|
|
|
|
|
import { JSCollection } from "entities/JSCollection";
|
|
|
|
|
import { ApiResponse, GenericApiResponse } from "./ApiResponses";
|
2021-09-15 06:28:25 +00:00
|
|
|
import { Variable, JSAction } from "entities/JSCollection";
|
|
|
|
|
import { PluginType } from "entities/Action";
|
2021-09-08 17:32:22 +00:00
|
|
|
export interface JSCollectionCreateUpdateResponse extends ApiResponse {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
export interface MoveJSCollectionRequest {
|
|
|
|
|
collectionId: string;
|
|
|
|
|
destinationPageId: string;
|
2022-01-20 16:32:11 +00:00
|
|
|
name: string;
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
export interface UpdateJSObjectNameRequest {
|
|
|
|
|
pageId: string;
|
|
|
|
|
actionCollectionId: string;
|
|
|
|
|
layoutId: string;
|
|
|
|
|
newName: string;
|
|
|
|
|
oldName: string;
|
|
|
|
|
}
|
2021-09-15 06:28:25 +00:00
|
|
|
|
|
|
|
|
export interface CreateJSCollectionRequest {
|
|
|
|
|
name: string;
|
|
|
|
|
pageId: string;
|
|
|
|
|
organizationId: string;
|
|
|
|
|
pluginId: string;
|
|
|
|
|
body: string;
|
|
|
|
|
variables: Array<Variable>;
|
|
|
|
|
actions: Array<Partial<JSAction>>;
|
|
|
|
|
applicationId: string;
|
|
|
|
|
pluginType: PluginType;
|
|
|
|
|
}
|
2021-10-19 11:53:15 +00:00
|
|
|
|
|
|
|
|
export interface RefactorAction {
|
|
|
|
|
pageId: string;
|
|
|
|
|
actionId: string;
|
|
|
|
|
newName: string;
|
|
|
|
|
oldName: string;
|
|
|
|
|
collectionName: string;
|
|
|
|
|
}
|
|
|
|
|
export interface RefactorActionRequest extends RefactorAction {
|
|
|
|
|
layoutId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UpdateCollectionActionNameRequest {
|
|
|
|
|
refactorAction: RefactorActionRequest;
|
|
|
|
|
actionCollection: JSCollection;
|
|
|
|
|
}
|
2021-09-08 17:32:22 +00:00
|
|
|
class JSActionAPI extends API {
|
|
|
|
|
static url = "v1/collections/actions";
|
|
|
|
|
|
|
|
|
|
static fetchJSCollections(
|
|
|
|
|
applicationId: string,
|
|
|
|
|
): AxiosPromise<GenericApiResponse<JSCollection[]>> {
|
|
|
|
|
return API.get(JSActionAPI.url, { applicationId });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static createJSCollection(
|
2021-09-15 06:28:25 +00:00
|
|
|
jsConfig: CreateJSCollectionRequest,
|
|
|
|
|
): AxiosPromise<JSCollectionCreateUpdateResponse> {
|
|
|
|
|
return API.post(JSActionAPI.url, jsConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static copyJSCollection(
|
|
|
|
|
jsConfig: Partial<JSCollection>,
|
2021-09-08 17:32:22 +00:00
|
|
|
): AxiosPromise<JSCollectionCreateUpdateResponse> {
|
2021-09-15 06:28:25 +00:00
|
|
|
return API.post(JSActionAPI.url, jsConfig);
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static updateJSCollection(
|
2021-09-15 06:28:25 +00:00
|
|
|
jsConfig: JSCollection,
|
2021-09-08 17:32:22 +00:00
|
|
|
): AxiosPromise<JSCollectionCreateUpdateResponse> {
|
2021-09-15 06:28:25 +00:00
|
|
|
const jsAction = Object.assign({}, jsConfig);
|
2021-09-08 17:32:22 +00:00
|
|
|
return API.put(`${JSActionAPI.url}/${jsAction.id}`, jsAction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static deleteJSCollection(id: string) {
|
|
|
|
|
return API.delete(`${JSActionAPI.url}/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static moveJSCollection(moveRequest: MoveJSCollectionRequest) {
|
|
|
|
|
return API.put(JSActionAPI.url + "/move", moveRequest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fetchJSCollectionsByPageId(
|
|
|
|
|
pageId: string,
|
|
|
|
|
): AxiosPromise<GenericApiResponse<JSCollection[]>> {
|
|
|
|
|
return API.get(JSActionAPI.url, { pageId });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static fetchJSCollectionsForViewMode(
|
|
|
|
|
applicationId: string,
|
|
|
|
|
): AxiosPromise<GenericApiResponse<JSCollection[]>> {
|
|
|
|
|
return API.get(`${JSActionAPI.url}/view`, { applicationId });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static updateJSCollectionOrActionName(
|
|
|
|
|
updateJSObjectNameRequest: UpdateJSObjectNameRequest,
|
|
|
|
|
) {
|
|
|
|
|
return API.put(JSActionAPI.url + "/refactor", updateJSObjectNameRequest);
|
|
|
|
|
}
|
2021-10-19 11:53:15 +00:00
|
|
|
|
|
|
|
|
static updateJSCollectionActionRefactor(
|
|
|
|
|
updateJSCollectionActionName: UpdateCollectionActionNameRequest,
|
|
|
|
|
) {
|
|
|
|
|
return API.put(
|
|
|
|
|
JSActionAPI.url + "/refactorAction",
|
|
|
|
|
updateJSCollectionActionName,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-09-08 17:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default JSActionAPI;
|