forked from github/plane
f7e140bf68
* feat: added heading 3 in the editor summary markings * feat: fixed editor and summary bar sizing * feat: added `issue-embed` extension * feat: exposed issue embed extension * feat: added main embed config configuration to document editor body * feat: added peek overview and issue embed fetch function * feat: enabled slash commands to take additonal suggestions from editors * chore: replaced `IssueEmbedWidget` into widget extension * chore: removed issue embed from previous places * feat: added issue embed suggestion extension * feat: added issue embed suggestion renderer * feat: added issue embed suggestions into extensions module * feat: added issues in issueEmbedConfiguration in document editor * chore: package fixes * chore: removed log statements * feat: added title updation logic into document editor * fix: issue suggestion items, not rendering issue widget on enter * feat: added error card for issue widget * feat: improved focus logic for issue search and navigate * feat: appended transactionid for issueWidgetTransaction * chore: packages update * feat: disabled editing of title in readonly mode * feat: added issueEmbedConfig in readonly editor * fix: issue suggestions not loading after structure changed to object * feat: added toast messages for success/error messages from doc editor * fix: issue suggestions sorting issue * fix: formatting errors resolved * fix: infinite reloading of the readonly document editor * fix: css in avatar of issue widget card * feat: added show alert on pages reload * feat: added saving state for the pages editor * fix: issue with heading 3 in side bar view * style: updated issue suggestions dropdown ui * fix: Pages intiliazation and mutation with updated MobX store * fixed image uploads being cancelled on refocus due to swr * fix: issue with same description rerendering empty content fixed * fix: scroll in issue suggestion view * fix: added submission prop * fix: Updated the comment update to take issue id in inbox issues * feat:changed date representation in IssueEmbedCard * fix: page details mutation with optimistic updates using swr * fix: menu options in read only editor with auth fixed * fix: add error handling for title and page desc * fixed yarn.lock * fix: read-only editor title wrapping * fix: build error with rich text editor --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com> Co-authored-by: Palanikannan1437 <73993394+Palanikannan1437@users.noreply.github.com>
208 lines
6.9 KiB
TypeScript
208 lines
6.9 KiB
TypeScript
import { API_BASE_URL } from "helpers/common.helper";
|
|
// services
|
|
import { APIService } from "services/api.service";
|
|
// types
|
|
import { IPage, IPageBlock, RecentPagesResponse, IIssue } from "types";
|
|
|
|
export class PageService extends APIService {
|
|
constructor() {
|
|
super(API_BASE_URL);
|
|
}
|
|
|
|
async createPage(workspaceSlug: string, projectId: string, data: Partial<IPage>): Promise<IPage> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/`, data)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async patchPage(workspaceSlug: string, projectId: string, pageId: string, data: Partial<IPage>): Promise<IPage> {
|
|
return this.patch(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/`, data)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
console.log("error", error?.response?.data);
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deletePage(workspaceSlug: string, projectId: string, pageId: string): Promise<any> {
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async addPageToFavorites(workspaceSlug: string, projectId: string, pageId: string): Promise<any> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-pages/`, { page: pageId })
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async removePageFromFavorites(workspaceSlug: string, projectId: string, pageId: string) {
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/user-favorite-pages/${pageId}`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getPagesWithParams(
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
pageType: "all" | "favorite" | "private" | "shared"
|
|
): Promise<IPage[]> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/`, {
|
|
params: {
|
|
page_view: pageType,
|
|
},
|
|
})
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getRecentPages(workspaceSlug: string, projectId: string): Promise<RecentPagesResponse> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/`, {
|
|
params: {
|
|
page_view: "recent",
|
|
},
|
|
})
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getPageDetails(workspaceSlug: string, projectId: string, pageId: string): Promise<IPage> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async createPageBlock(
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
pageId: string,
|
|
data: Partial<IPageBlock>
|
|
): Promise<IPageBlock> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/`, data)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getPageBlock(
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
pageId: string,
|
|
pageBlockId: string
|
|
): Promise<IPageBlock[]> {
|
|
return this.get(
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${pageBlockId}/`
|
|
)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async patchPageBlock(
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
pageId: string,
|
|
pageBlockId: string,
|
|
data: Partial<IPageBlock>
|
|
): Promise<IPage> {
|
|
return this.patch(
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${pageBlockId}/`,
|
|
data
|
|
)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async deletePageBlock(workspaceSlug: string, projectId: string, pageId: string, pageBlockId: string): Promise<any> {
|
|
return this.delete(
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${pageBlockId}/`
|
|
)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async listPageBlocks(workspaceSlug: string, projectId: string, pageId: string): Promise<IPageBlock[]> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async convertPageBlockToIssue(
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
pageId: string,
|
|
blockId: string
|
|
): Promise<IIssue> {
|
|
return this.post(
|
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/page-blocks/${blockId}/issues/`
|
|
)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
// =============== Archiving & Unarchiving Pages =================
|
|
async archivePage(workspaceSlug: string, projectId: string, pageId: string): Promise<void> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/archive/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async restorePage(workspaceSlug: string, projectId: string, pageId: string): Promise<void> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/unarchive/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async getArchivedPages(workspaceSlug: string, projectId: string): Promise<IPage[]> {
|
|
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/archived-pages/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error;
|
|
});
|
|
}
|
|
// ==================== Pages Locking Services ==========================
|
|
async lockPage(workspaceSlug: string, projectId: string, pageId: string): Promise<any> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/lock/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
|
|
async unlockPage(workspaceSlug: string, projectId: string, pageId: string): Promise<any> {
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/pages/${pageId}/unlock/`)
|
|
.then((response) => response?.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|
|
}
|