2022-03-03 10:56:53 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
|
|
|
|
import Api from "api/Api";
|
|
|
|
|
import { ApiResponse } from "./ApiResponses";
|
|
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
2022-09-30 13:41:04 +00:00
|
|
|
import {
|
|
|
|
|
ApplicationResponsePayload,
|
|
|
|
|
ApplicationPagePayload,
|
|
|
|
|
} from "./ApplicationApi";
|
2022-08-04 04:20:54 +00:00
|
|
|
import { Datasource } from "entities/Datasource";
|
2022-03-03 10:56:53 +00:00
|
|
|
|
|
|
|
|
export interface Template {
|
|
|
|
|
id: string;
|
|
|
|
|
userPermissions: string[];
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
appUrl: string;
|
|
|
|
|
gifUrl: string;
|
|
|
|
|
screenshotUrls: string[];
|
|
|
|
|
widgets: WidgetType[];
|
|
|
|
|
functions: string[];
|
|
|
|
|
useCases: string[];
|
|
|
|
|
datasources: string[];
|
2022-09-30 13:41:04 +00:00
|
|
|
pages: ApplicationPagePayload[];
|
2022-03-03 10:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type FetchTemplatesResponse = ApiResponse<Template[]>;
|
2022-03-31 05:16:04 +00:00
|
|
|
export type FilterKeys = "widgets" | "datasources";
|
|
|
|
|
|
2022-06-21 13:57:34 +00:00
|
|
|
export type FetchTemplateResponse = ApiResponse<Template>;
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2022-08-04 04:20:54 +00:00
|
|
|
export type ImportTemplateResponse = ApiResponse<{
|
|
|
|
|
isPartialImport: boolean;
|
|
|
|
|
unConfiguredDatasourceList: Datasource[];
|
|
|
|
|
application: ApplicationResponsePayload;
|
|
|
|
|
}>;
|
2022-03-03 10:56:53 +00:00
|
|
|
|
2022-09-30 13:41:04 +00:00
|
|
|
export interface TemplateFiltersResponse extends ApiResponse {
|
|
|
|
|
data: {
|
|
|
|
|
functions: string[];
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-03 10:56:53 +00:00
|
|
|
class TemplatesAPI extends Api {
|
|
|
|
|
static baseUrl = "v1";
|
|
|
|
|
|
|
|
|
|
static getAllTemplates(): AxiosPromise<FetchTemplatesResponse> {
|
|
|
|
|
return Api.get(TemplatesAPI.baseUrl + `/app-templates`);
|
|
|
|
|
}
|
|
|
|
|
static getTemplateInformation(
|
|
|
|
|
templateId: string,
|
|
|
|
|
): AxiosPromise<FetchTemplatesResponse> {
|
|
|
|
|
return Api.get(TemplatesAPI.baseUrl + `/app-templates/${templateId}`);
|
|
|
|
|
}
|
|
|
|
|
static getSimilarTemplates(
|
|
|
|
|
templateId: string,
|
|
|
|
|
): AxiosPromise<FetchTemplatesResponse> {
|
|
|
|
|
return Api.get(
|
|
|
|
|
TemplatesAPI.baseUrl + `/app-templates/${templateId}/similar`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
static importTemplate(
|
|
|
|
|
templateId: string,
|
2022-06-15 15:37:41 +00:00
|
|
|
workspaceId: string,
|
2022-03-18 12:08:10 +00:00
|
|
|
): AxiosPromise<ImportTemplateResponse> {
|
2022-03-03 10:56:53 +00:00
|
|
|
return Api.post(
|
|
|
|
|
TemplatesAPI.baseUrl +
|
2022-06-15 15:37:41 +00:00
|
|
|
`/app-templates/${templateId}/import/${workspaceId}`,
|
2022-03-03 10:56:53 +00:00
|
|
|
);
|
|
|
|
|
}
|
2022-09-30 13:41:04 +00:00
|
|
|
static importTemplateToApplication(
|
|
|
|
|
templateId: string,
|
|
|
|
|
applicationId: string,
|
|
|
|
|
organizationId: string,
|
|
|
|
|
body?: string[],
|
|
|
|
|
): AxiosPromise<ImportTemplateResponse> {
|
|
|
|
|
return Api.post(
|
|
|
|
|
TemplatesAPI.baseUrl +
|
|
|
|
|
`/app-templates/${templateId}/merge/${applicationId}/${organizationId}`,
|
|
|
|
|
body,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
static getTemplateFilters(): AxiosPromise<TemplateFiltersResponse> {
|
|
|
|
|
return Api.get(TemplatesAPI.baseUrl + `/app-templates/filters`);
|
|
|
|
|
}
|
2022-03-03 10:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TemplatesAPI;
|