PromucFlow_constructor/app/client/src/api/TemplatesApi.ts
Anagh Hegde 681ad2e6d1
chore: template upload process revamping (#29626)
## Description
Move from all the manual process of exporting app and filling so many
details, make template upload process a 1 click action.
Current, the step is manual. One has to export the app manually, and
then upload to s3, get the APP URL and page name correct and there is a
lot of room for error. All of this can be automated.

#### PR fixes following issue(s)
Fixes https://github.com/appsmithorg/cloud-services/issues/1454


#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing
#### How Has This Been Tested?
- [ ] Manual


#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new feature for publishing templates under a "use-case"
category.
- Implemented a simplified endpoint for publishing community templates.

- **Bug Fixes**
- Streamlined the template publishing process to enhance user
experience.

- **Refactor**
- Consolidated template-related data transfer objects to a more generic
naming convention.
- Refactored the publishing methods to align with the new template
categorization.

- **Documentation**
- Updated API documentation to reflect new endpoints and usage patterns.

- **Tests**
- Modified existing tests to accommodate changes in template DTO naming
and publishing logic.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2023-12-15 17:31:25 +05:30

120 lines
3.2 KiB
TypeScript

import type { AxiosPromise } from "axios";
import Api from "api/Api";
import type { ApiResponse } from "./ApiResponses";
import type { WidgetType } from "constants/WidgetConstants";
import type {
ApplicationResponsePayload,
ApplicationPagePayload,
} from "@appsmith/api/ApplicationApi";
import type { Datasource } from "entities/Datasource";
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[];
pages: ApplicationPagePayload[];
allowPageImport: boolean;
}
export type FetchTemplatesResponse = ApiResponse<Template[]>;
export type FilterKeys = "widgets" | "datasources";
export type FetchTemplateResponse = ApiResponse<Template>;
export type ImportTemplateResponse = ApiResponse<{
isPartialImport: boolean;
unConfiguredDatasourceList: Datasource[];
application: ApplicationResponsePayload;
}>;
export interface TemplateFiltersResponse extends ApiResponse {
data: {
functions: string[];
useCases?: string[];
};
}
export interface PublishCommunityTemplateRequest {
applicationId: string;
workspaceId: string;
branchName: string;
title: string;
headline: string;
description: string;
useCases: string[];
authorEmail: string;
}
export type PublishCommunityTemplateResponse = ApiResponse<{
isPublic: boolean;
forkingEnabled: boolean;
isCommunityTemplate: boolean;
modifiedAt: string;
}>;
class TemplatesAPI extends Api {
static baseUrl = "v1";
static async getAllTemplates(): Promise<
AxiosPromise<FetchTemplatesResponse>
> {
return Api.get(TemplatesAPI.baseUrl + `/app-templates`);
}
static async getTemplateInformation(
templateId: string,
): Promise<AxiosPromise<FetchTemplatesResponse>> {
return Api.get(TemplatesAPI.baseUrl + `/app-templates/${templateId}`);
}
static async getSimilarTemplates(
templateId: string,
): Promise<AxiosPromise<FetchTemplatesResponse>> {
return Api.get(
TemplatesAPI.baseUrl + `/app-templates/${templateId}/similar`,
);
}
static async importTemplate(
templateId: string,
workspaceId: string,
): Promise<AxiosPromise<ImportTemplateResponse>> {
return Api.post(
TemplatesAPI.baseUrl +
`/app-templates/${templateId}/import/${workspaceId}`,
);
}
static async importTemplateToApplication(
templateId: string,
applicationId: string,
organizationId: string,
body?: string[],
): Promise<AxiosPromise<ImportTemplateResponse>> {
return Api.post(
TemplatesAPI.baseUrl +
`/app-templates/${templateId}/merge/${applicationId}/${organizationId}`,
body,
);
}
static async getTemplateFilters(): Promise<
AxiosPromise<TemplateFiltersResponse>
> {
return Api.get(TemplatesAPI.baseUrl + `/app-templates/filters`);
}
static async publishCommunityTemplate(
body: PublishCommunityTemplateRequest,
): Promise<AxiosPromise<PublishCommunityTemplateResponse>> {
return Api.post(
TemplatesAPI.baseUrl + `/app-templates/publish/community-template`,
body,
);
}
}
export default TemplatesAPI;