PromucFlow_constructor/app/client/src/api/PageApi.tsx

161 lines
3.7 KiB
TypeScript
Raw Normal View History

2019-09-09 09:08:54 +00:00
import Api from "./Api";
2019-11-25 05:07:27 +00:00
import { ContainerWidgetProps } from "widgets/ContainerWidget";
2019-09-09 09:08:54 +00:00
import { ApiResponse } from "./ApiResponses";
2019-11-25 05:07:27 +00:00
import { WidgetProps } from "widgets/BaseWidget";
import { AxiosPromise } from "axios";
import { PageAction } from "constants/ActionConstants";
export interface FetchPageRequest {
2019-08-29 11:22:09 +00:00
pageId: string;
}
export interface FetchPublishedPageRequest {
pageId: string;
2020-05-05 12:16:51 +00:00
bustCache?: boolean;
}
export interface SavePageRequest {
dsl: ContainerWidgetProps<WidgetProps>;
layoutId: string;
pageId: string;
}
2019-09-13 09:56:11 +00:00
export interface PageLayout {
id: string;
dsl: Partial<ContainerWidgetProps<any>>;
2020-02-21 12:16:49 +00:00
layoutOnLoadActions: PageAction[][];
layoutActions: PageAction[];
2019-09-13 09:56:11 +00:00
}
export type FetchPageResponse = ApiResponse & {
data: {
id: string;
name: string;
applicationId: string;
layouts: Array<PageLayout>;
};
};
export type FetchPublishedPageResponse = ApiResponse & {
2019-10-24 09:23:50 +00:00
data: {
id: string;
dsl: Partial<ContainerWidgetProps<any>>;
pageId: string;
2019-10-24 09:23:50 +00:00
};
};
2019-09-27 16:05:33 +00:00
export interface SavePageResponse extends ApiResponse {
2019-08-29 11:22:09 +00:00
pageId: string;
}
export interface CreatePageRequest {
applicationId: string;
name: string;
}
2020-01-27 08:24:58 +00:00
export interface UpdatePageRequest {
id: string;
name: string;
}
export interface CreatePageResponse extends ApiResponse {
data: {};
}
export interface FetchPageListResponse extends ApiResponse {
data: {
pages: Array<{
id: string;
name: string;
isDefault: boolean;
layouts: Array<PageLayout>;
}>;
organizationId: string;
};
}
2020-01-27 08:24:58 +00:00
export interface DeletePageRequest {
pageId: string;
}
2020-02-21 12:16:49 +00:00
export interface UpdateWidgetNameRequest {
pageId: string;
layoutId: string;
newName: string;
oldName: string;
}
export interface UpdateWidgetNameResponse extends ApiResponse {
data: PageLayout;
}
class PageApi extends Api {
2019-09-24 12:36:03 +00:00
static url = "v1/pages";
2020-02-21 12:16:49 +00:00
static refactorLayoutURL = "v1/layouts/refactor";
static getLayoutUpdateURL = (pageId: string, layoutId: string) => {
2019-09-24 12:36:03 +00:00
return `v1/layouts/${layoutId}/pages/${pageId}`;
};
2019-09-09 09:08:54 +00:00
2020-05-05 12:16:51 +00:00
static getPublishedPageURL = (pageId: string, bustCache?: boolean) => {
const url = `v1/pages/${pageId}/view`;
return !!bustCache ? url + "?v=" + +new Date() : url;
};
2020-01-27 08:24:58 +00:00
static updatePageUrl = (pageId: string) => `${PageApi.url}/${pageId}`;
static fetchPage(
pageRequest: FetchPageRequest,
): AxiosPromise<FetchPageResponse> {
return Api.get(PageApi.url + "/" + pageRequest.pageId);
}
static savePage(
savePageRequest: SavePageRequest,
): AxiosPromise<SavePageResponse> {
const body = { dsl: savePageRequest.dsl };
return Api.put(
PageApi.getLayoutUpdateURL(
savePageRequest.pageId,
savePageRequest.layoutId,
),
body,
);
}
static fetchPublishedPage(
pageRequest: FetchPublishedPageRequest,
): AxiosPromise<FetchPublishedPageResponse> {
2020-05-05 12:16:51 +00:00
return Api.get(
PageApi.getPublishedPageURL(pageRequest.pageId, pageRequest.bustCache),
);
}
static createPage(
createPageRequest: CreatePageRequest,
): AxiosPromise<FetchPageResponse> {
return Api.post(PageApi.url, createPageRequest);
}
2020-01-27 08:24:58 +00:00
static updatePage(request: UpdatePageRequest): AxiosPromise<ApiResponse> {
return Api.put(PageApi.updatePageUrl(request.id), request);
}
static fetchPageList(
applicationId: string,
): AxiosPromise<FetchPageListResponse> {
return Api.get(PageApi.url + "/application/" + applicationId);
}
2020-01-27 08:24:58 +00:00
static deletePage(request: DeletePageRequest): AxiosPromise<ApiResponse> {
return Api.delete(PageApi.url + "/" + request.pageId);
}
2020-02-21 12:16:49 +00:00
static updateWidgetName(
request: UpdateWidgetNameRequest,
): AxiosPromise<UpdateWidgetNameResponse> {
return Api.put(PageApi.refactorLayoutURL, request);
}
}
2019-09-09 09:08:54 +00:00
export default PageApi;