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";
|
2019-10-29 12:02:58 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
2019-12-11 15:24:27 +00:00
|
|
|
import { PageAction } from "constants/ActionConstants";
|
2019-03-26 15:28:24 +00:00
|
|
|
|
2019-09-17 15:09:55 +00:00
|
|
|
export interface FetchPageRequest {
|
2019-08-29 11:22:09 +00:00
|
|
|
pageId: string;
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-24 07:03:59 +00:00
|
|
|
export interface FetchPublishedPageRequest {
|
|
|
|
|
pageId: string;
|
2020-05-05 12:16:51 +00:00
|
|
|
bustCache?: boolean;
|
2019-10-24 07:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-30 12:30:42 +00:00
|
|
|
export interface SavePageRequest {
|
2019-09-18 10:48:56 +00:00
|
|
|
dsl: ContainerWidgetProps<WidgetProps>;
|
|
|
|
|
layoutId: string;
|
|
|
|
|
pageId: string;
|
2019-03-26 15:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 09:56:11 +00:00
|
|
|
export interface PageLayout {
|
2019-09-18 10:48:56 +00:00
|
|
|
id: string;
|
2019-09-18 14:10:57 +00:00
|
|
|
dsl: Partial<ContainerWidgetProps<any>>;
|
2020-02-21 12:16:49 +00:00
|
|
|
layoutOnLoadActions: PageAction[][];
|
2019-12-11 15:24:27 +00:00
|
|
|
layoutActions: PageAction[];
|
2019-09-13 09:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-18 10:48:56 +00:00
|
|
|
export type FetchPageResponse = ApiResponse & {
|
|
|
|
|
data: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
applicationId: string;
|
|
|
|
|
layouts: Array<PageLayout>;
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-03-26 15:28:24 +00:00
|
|
|
|
2019-10-24 07:03:59 +00:00
|
|
|
export type FetchPublishedPageResponse = ApiResponse & {
|
2019-10-24 09:23:50 +00:00
|
|
|
data: {
|
|
|
|
|
id: string;
|
|
|
|
|
dsl: Partial<ContainerWidgetProps<any>>;
|
2019-10-31 08:36:04 +00:00
|
|
|
pageId: string;
|
2019-10-24 09:23:50 +00:00
|
|
|
};
|
2019-10-24 07:03:59 +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;
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-31 08:36:04 +00:00
|
|
|
export interface CreatePageRequest {
|
|
|
|
|
applicationId: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
export interface UpdatePageRequest {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 08:36:04 +00:00
|
|
|
export interface CreatePageResponse extends ApiResponse {
|
|
|
|
|
data: {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FetchPageListResponse extends ApiResponse {
|
2020-06-17 10:19:56 +00:00
|
|
|
data: {
|
|
|
|
|
pages: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
isDefault: boolean;
|
|
|
|
|
layouts: Array<PageLayout>;
|
|
|
|
|
}>;
|
|
|
|
|
organizationId: string;
|
|
|
|
|
};
|
2019-10-31 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 15:28:24 +00:00
|
|
|
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";
|
2019-09-18 10:48:56 +00:00
|
|
|
static getLayoutUpdateURL = (pageId: string, layoutId: string) => {
|
2019-09-24 12:36:03 +00:00
|
|
|
return `v1/layouts/${layoutId}/pages/${pageId}`;
|
2019-09-18 10:48:56 +00:00
|
|
|
};
|
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;
|
2019-10-24 07:03:59 +00:00
|
|
|
};
|
|
|
|
|
|
2020-01-27 08:24:58 +00:00
|
|
|
static updatePageUrl = (pageId: string) => `${PageApi.url}/${pageId}`;
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
static fetchPage(
|
|
|
|
|
pageRequest: FetchPageRequest,
|
|
|
|
|
): AxiosPromise<FetchPageResponse> {
|
2019-09-18 10:48:56 +00:00
|
|
|
return Api.get(PageApi.url + "/" + pageRequest.pageId);
|
2019-03-26 15:28:24 +00:00
|
|
|
}
|
2019-03-30 12:30:42 +00:00
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
static savePage(
|
|
|
|
|
savePageRequest: SavePageRequest,
|
|
|
|
|
): AxiosPromise<SavePageResponse> {
|
2019-09-18 10:48:56 +00:00
|
|
|
const body = { dsl: savePageRequest.dsl };
|
|
|
|
|
return Api.put(
|
|
|
|
|
PageApi.getLayoutUpdateURL(
|
|
|
|
|
savePageRequest.pageId,
|
|
|
|
|
savePageRequest.layoutId,
|
|
|
|
|
),
|
|
|
|
|
body,
|
|
|
|
|
);
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
2019-10-24 07:03:59 +00:00
|
|
|
|
|
|
|
|
static fetchPublishedPage(
|
|
|
|
|
pageRequest: FetchPublishedPageRequest,
|
2019-10-29 12:02:58 +00:00
|
|
|
): AxiosPromise<FetchPublishedPageResponse> {
|
2020-05-05 12:16:51 +00:00
|
|
|
return Api.get(
|
|
|
|
|
PageApi.getPublishedPageURL(pageRequest.pageId, pageRequest.bustCache),
|
|
|
|
|
);
|
2019-10-24 07:03:59 +00:00
|
|
|
}
|
2019-10-31 08:36:04 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
static fetchPageList(
|
|
|
|
|
applicationId: string,
|
|
|
|
|
): AxiosPromise<FetchPageListResponse> {
|
|
|
|
|
return Api.get(PageApi.url + "/application/" + applicationId);
|
2019-10-31 08:36:04 +00:00
|
|
|
}
|
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-03-26 15:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default PageApi;
|