2019-09-09 09:08:54 +00:00
|
|
|
import Api from "./Api";
|
|
|
|
|
import { ContainerWidgetProps } from "../widgets/ContainerWidget";
|
|
|
|
|
import { ApiResponse } from "./ApiResponses";
|
2019-09-17 15:09:55 +00:00
|
|
|
import { WidgetProps } from "../widgets/BaseWidget";
|
2019-03-30 12:30:42 +00:00
|
|
|
import { RenderMode } from "../constants/WidgetConstants";
|
2019-09-13 11:59:45 +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;
|
|
|
|
|
renderMode: RenderMode;
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-24 07:03:59 +00:00
|
|
|
export interface FetchPublishedPageRequest {
|
|
|
|
|
pageId: string;
|
|
|
|
|
layoutId: string;
|
|
|
|
|
}
|
|
|
|
|
|
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>>;
|
2019-09-13 11:59:45 +00:00
|
|
|
actions: 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-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-03-26 15:28:24 +00:00
|
|
|
class PageApi extends Api {
|
2019-09-24 12:36:03 +00:00
|
|
|
static url = "v1/pages";
|
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
|
|
|
|
2019-10-24 07:03:59 +00:00
|
|
|
static getPublishedPageURL = (pageId: string, layoutId: string) => {
|
|
|
|
|
return `v1/layouts/${layoutId}/pages/${pageId}/view`;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-17 15:09:55 +00:00
|
|
|
static fetchPage(pageRequest: FetchPageRequest): Promise<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-09-17 15:09:55 +00:00
|
|
|
static savePage(savePageRequest: SavePageRequest): Promise<SavePageResponse> {
|
2019-09-18 10:48:56 +00:00
|
|
|
const body = { dsl: savePageRequest.dsl };
|
|
|
|
|
return Api.put(
|
|
|
|
|
PageApi.getLayoutUpdateURL(
|
|
|
|
|
savePageRequest.pageId,
|
|
|
|
|
savePageRequest.layoutId,
|
|
|
|
|
),
|
|
|
|
|
undefined,
|
|
|
|
|
body,
|
|
|
|
|
);
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
2019-10-24 07:03:59 +00:00
|
|
|
|
|
|
|
|
static fetchPublishedPage(
|
|
|
|
|
pageRequest: FetchPublishedPageRequest,
|
|
|
|
|
): Promise<FetchPublishedPageResponse> {
|
|
|
|
|
return Api.get(
|
|
|
|
|
PageApi.getPublishedPageURL(pageRequest.pageId, pageRequest.layoutId),
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-03-26 15:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export default PageApi;
|