[WEB-1397] chore: update project publish types (#4841)

* chore: update project publish types

* chore: added additional entity name

* chore: updated types
This commit is contained in:
Aaryan Khandelwal 2024-06-17 16:51:38 +05:30 committed by GitHub
parent c4f5093492
commit ae3dcc3dbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 59 additions and 68 deletions

View file

@ -1,6 +1,6 @@
import { IProject, IProjectLite, IWorkspaceLite } from "@plane/types"; import { IProject, IProjectLite, IWorkspaceLite } from "@plane/types";
export type TPublishEntityType = "project"; export type TPublishEntityType = "project" | "page";
export type TProjectPublishLayouts = export type TProjectPublishLayouts =
| "calendar" | "calendar"
@ -9,7 +9,7 @@ export type TProjectPublishLayouts =
| "list" | "list"
| "spreadsheet"; | "spreadsheet";
export type TPublishViewProps = { export type TProjectPublishViewProps = {
calendar?: boolean; calendar?: boolean;
gantt?: boolean; gantt?: boolean;
kanban?: boolean; kanban?: boolean;
@ -20,22 +20,25 @@ export type TPublishViewProps = {
export type TProjectDetails = IProjectLite & export type TProjectDetails = IProjectLite &
Pick<IProject, "cover_image" | "logo_props" | "description">; Pick<IProject, "cover_image" | "logo_props" | "description">;
export type TPublishSettings = { type TPublishSettings = {
anchor: string | undefined; anchor: string | undefined;
is_comments_enabled: boolean;
created_at: string | undefined; created_at: string | undefined;
created_by: string | undefined; created_by: string | undefined;
entity_identifier: string | undefined; entity_identifier: string | undefined;
entity_name: TPublishEntityType | undefined; entity_name: TPublishEntityType | undefined;
id: string | undefined; id: string | undefined;
inbox: unknown; inbox: unknown;
is_comments_enabled: boolean;
is_reactions_enabled: boolean;
is_votes_enabled: boolean;
project: string | undefined; project: string | undefined;
project_details: TProjectDetails | undefined; project_details: TProjectDetails | undefined;
is_reactions_enabled: boolean;
updated_at: string | undefined; updated_at: string | undefined;
updated_by: string | undefined; updated_by: string | undefined;
view_props: TViewProps | undefined;
is_votes_enabled: boolean;
workspace: string | undefined; workspace: string | undefined;
workspace_detail: IWorkspaceLite | undefined; workspace_detail: IWorkspaceLite | undefined;
}; };
export type TProjectPublishSettings = TPublishSettings & {
view_props: TProjectPublishViewProps | undefined;
};

View file

@ -1,6 +1,6 @@
import { notFound, redirect } from "next/navigation"; import { notFound, redirect } from "next/navigation";
// types // types
import { TPublishSettings } from "@plane/types"; import { TProjectPublishSettings } from "@plane/types";
// services // services
import PublishService from "@/services/publish.service"; import PublishService from "@/services/publish.service";
@ -20,7 +20,7 @@ export default async function IssuesPage(props: Props) {
const { workspaceSlug, projectId } = params; const { workspaceSlug, projectId } = params;
const { board, peekId } = searchParams; const { board, peekId } = searchParams;
let response: TPublishSettings | undefined = undefined; let response: TProjectPublishSettings | undefined = undefined;
try { try {
response = await publishService.fetchAnchorFromProjectDetails(workspaceSlug, projectId); response = await publishService.fetchAnchorFromProjectDetails(workspaceSlug, projectId);
} catch (error) { } catch (error) {

View file

@ -1,5 +1,5 @@
// types // types
import { TPublishSettings } from "@plane/types"; import { TProjectPublishSettings } from "@plane/types";
// helpers // helpers
import { API_BASE_URL } from "@/helpers/common.helper"; import { API_BASE_URL } from "@/helpers/common.helper";
// services // services
@ -10,7 +10,7 @@ class PublishService extends APIService {
super(API_BASE_URL); super(API_BASE_URL);
} }
async fetchPublishSettings(anchor: string): Promise<TPublishSettings> { async fetchPublishSettings(anchor: string): Promise<TProjectPublishSettings> {
return this.get(`/api/public/anchor/${anchor}/settings/`) return this.get(`/api/public/anchor/${anchor}/settings/`)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -18,7 +18,7 @@ class PublishService extends APIService {
}); });
} }
async fetchAnchorFromProjectDetails(workspaceSlug: string, projectID: string): Promise<TPublishSettings> { async fetchAnchorFromProjectDetails(workspaceSlug: string, projectID: string): Promise<TProjectPublishSettings> {
return this.get(`/api/public/workspaces/${workspaceSlug}/projects/${projectID}/anchor/`) return this.get(`/api/public/workspaces/${workspaceSlug}/projects/${projectID}/anchor/`)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {

View file

@ -1,10 +1,16 @@
import { observable, makeObservable, computed } from "mobx"; import { observable, makeObservable, computed } from "mobx";
// types // types
import { IWorkspaceLite, TProjectDetails, TPublishEntityType, TPublishSettings, TPublishViewProps } from "@plane/types"; import {
IWorkspaceLite,
TProjectDetails,
TPublishEntityType,
TProjectPublishSettings,
TProjectPublishViewProps,
} from "@plane/types";
// store types // store types
import { RootStore } from "@/store/root.store"; import { RootStore } from "@/store/root.store";
export interface IPublishStore extends TPublishSettings { export interface IPublishStore extends TProjectPublishSettings {
// computed // computed
workspaceSlug: string | undefined; workspaceSlug: string | undefined;
canComment: boolean; canComment: boolean;
@ -27,14 +33,14 @@ export class PublishStore implements IPublishStore {
is_reactions_enabled: boolean; is_reactions_enabled: boolean;
updated_at: string | undefined; updated_at: string | undefined;
updated_by: string | undefined; updated_by: string | undefined;
view_props: TPublishViewProps | undefined; view_props: TProjectPublishViewProps | undefined;
is_votes_enabled: boolean; is_votes_enabled: boolean;
workspace: string | undefined; workspace: string | undefined;
workspace_detail: IWorkspaceLite | undefined; workspace_detail: IWorkspaceLite | undefined;
constructor( constructor(
private store: RootStore, private store: RootStore,
publishSettings: TPublishSettings publishSettings: TProjectPublishSettings
) { ) {
this.anchor = publishSettings.anchor; this.anchor = publishSettings.anchor;
this.is_comments_enabled = publishSettings.is_comments_enabled; this.is_comments_enabled = publishSettings.is_comments_enabled;

View file

@ -1,7 +1,7 @@
import set from "lodash/set"; import set from "lodash/set";
import { makeObservable, observable, runInAction, action } from "mobx"; import { makeObservable, observable, runInAction, action } from "mobx";
// types // types
import { TPublishSettings } from "@plane/types"; import { TProjectPublishSettings } from "@plane/types";
// services // services
import PublishService from "@/services/publish.service"; import PublishService from "@/services/publish.service";
// store // store
@ -13,7 +13,7 @@ export interface IPublishListStore {
// observables // observables
publishMap: Record<string, PublishStore>; // anchor => PublishStore publishMap: Record<string, PublishStore>; // anchor => PublishStore
// actions // actions
fetchPublishSettings: (pageId: string) => Promise<TPublishSettings>; fetchPublishSettings: (pageId: string) => Promise<TProjectPublishSettings>;
} }
export class PublishListStore implements IPublishListStore { export class PublishListStore implements IPublishListStore {
@ -42,7 +42,13 @@ export class PublishListStore implements IPublishListStore {
const response = await this.publishService.fetchPublishSettings(anchor); const response = await this.publishService.fetchPublishSettings(anchor);
runInAction(() => { runInAction(() => {
if (response.anchor && response.view_props) { if (response.anchor && response.view_props) {
this.store.issueFilter.updateLayoutOptions(response?.view_props); this.store.issueFilter.updateLayoutOptions({
list: !!response.view_props.list,
kanban: !!response.view_props.kanban,
calendar: !!response.view_props.calendar,
gantt: !!response.view_props.gantt,
spreadsheet: !!response.view_props.spreadsheet,
});
set(this.publishMap, [response.anchor], new PublishStore(this.store, response)); set(this.publishMap, [response.anchor], new PublishStore(this.store, response));
} }
}); });

View file

@ -1,24 +0,0 @@
import { IWorkspaceLite } from "@plane/types";
import { TProjectDetails, TViewDetails } from "@/types/project";
export type TPublishEntityType = "project";
export type TPublishSettings = {
anchor: string | undefined;
is_comments_enabled: boolean;
created_at: string | undefined;
created_by: string | undefined;
entity_identifier: string | undefined;
entity_name: TPublishEntityType | undefined;
id: string | undefined;
inbox: unknown;
project: string | undefined;
project_details: TProjectDetails | undefined;
is_reactions_enabled: boolean;
updated_at: string | undefined;
updated_by: string | undefined;
view_props: TViewDetails | undefined;
is_votes_enabled: boolean;
workspace: string | undefined;
workspace_detail: IWorkspaceLite | undefined;
};

View file

@ -6,7 +6,7 @@ import { useParams } from "next/navigation";
import { Controller, useForm } from "react-hook-form"; import { Controller, useForm } from "react-hook-form";
import { Check, ExternalLink, Globe2 } from "lucide-react"; import { Check, ExternalLink, Globe2 } from "lucide-react";
// types // types
import { IProject, TProjectPublishLayouts, TPublishSettings } from "@plane/types"; import { IProject, TProjectPublishLayouts, TProjectPublishSettings } from "@plane/types";
// ui // ui
import { Button, Loader, ToggleSwitch, TOAST_TYPE, setToast, CustomSelect, ModalCore, EModalWidth } from "@plane/ui"; import { Button, Loader, ToggleSwitch, TOAST_TYPE, setToast, CustomSelect, ModalCore, EModalWidth } from "@plane/ui";
// helpers // helpers
@ -21,7 +21,7 @@ type Props = {
onClose: () => void; onClose: () => void;
}; };
const defaultValues: Partial<TPublishSettings> = { const defaultValues: Partial<TProjectPublishSettings> = {
is_comments_enabled: false, is_comments_enabled: false,
is_reactions_enabled: false, is_reactions_enabled: false,
is_votes_enabled: false, is_votes_enabled: false,
@ -81,12 +81,12 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
} }
}, [fetchPublishSettings, isOpen, project, projectPublishSettings, workspaceSlug]); }, [fetchPublishSettings, isOpen, project, projectPublishSettings, workspaceSlug]);
const handlePublishProject = async (payload: Partial<TPublishSettings>) => { const handlePublishProject = async (payload: Partial<TProjectPublishSettings>) => {
if (!workspaceSlug) return; if (!workspaceSlug) return;
await publishProject(workspaceSlug.toString(), project.id, payload); await publishProject(workspaceSlug.toString(), project.id, payload);
}; };
const handleUpdatePublishSettings = async (payload: Partial<TPublishSettings>) => { const handleUpdatePublishSettings = async (payload: Partial<TProjectPublishSettings>) => {
if (!workspaceSlug || !payload.id) return; if (!workspaceSlug || !payload.id) return;
await updatePublishSettings(workspaceSlug.toString(), project.id, payload.id, payload).then((res) => { await updatePublishSettings(workspaceSlug.toString(), project.id, payload.id, payload).then((res) => {
@ -124,7 +124,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
.map(([key, value]) => key) .map(([key, value]) => key)
.filter((l) => VIEW_OPTIONS.find((o) => o.key === l)); .filter((l) => VIEW_OPTIONS.find((o) => o.key === l));
const handleFormSubmit = async (formData: Partial<TPublishSettings>) => { const handleFormSubmit = async (formData: Partial<TProjectPublishSettings>) => {
if (!selectedLayouts || selectedLayouts.length === 0) { if (!selectedLayouts || selectedLayouts.length === 0) {
setToast({ setToast({
type: TOAST_TYPE.ERROR, type: TOAST_TYPE.ERROR,
@ -134,7 +134,7 @@ export const PublishProjectModal: React.FC<Props> = observer((props) => {
return; return;
} }
const payload: Partial<TPublishSettings> = { const payload: Partial<TProjectPublishSettings> = {
id: formData.id, id: formData.id,
is_comments_enabled: formData.is_comments_enabled, is_comments_enabled: formData.is_comments_enabled,
is_reactions_enabled: formData.is_reactions_enabled, is_reactions_enabled: formData.is_reactions_enabled,

View file

@ -1,5 +1,5 @@
// types // types
import { TPublishSettings } from "@plane/types"; import { TProjectPublishSettings } from "@plane/types";
// helpers // helpers
import { API_BASE_URL } from "@/helpers/common.helper"; import { API_BASE_URL } from "@/helpers/common.helper";
// services // services
@ -10,7 +10,7 @@ export class ProjectPublishService extends APIService {
super(API_BASE_URL); super(API_BASE_URL);
} }
async fetchPublishSettings(workspaceSlug: string, projectID: string): Promise<TPublishSettings> { async fetchPublishSettings(workspaceSlug: string, projectID: string): Promise<TProjectPublishSettings> {
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectID}/project-deploy-boards/`) return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectID}/project-deploy-boards/`)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -21,8 +21,8 @@ export class ProjectPublishService extends APIService {
async publishProject( async publishProject(
workspaceSlug: string, workspaceSlug: string,
projectID: string, projectID: string,
data: Partial<TPublishSettings> data: Partial<TProjectPublishSettings>
): Promise<TPublishSettings> { ): Promise<TProjectPublishSettings> {
return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectID}/project-deploy-boards/`, data) return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectID}/project-deploy-boards/`, data)
.then((response) => response?.data) .then((response) => response?.data)
.catch((error) => { .catch((error) => {
@ -34,8 +34,8 @@ export class ProjectPublishService extends APIService {
workspaceSlug: string, workspaceSlug: string,
projectID: string, projectID: string,
project_publish_id: string, project_publish_id: string,
data: Partial<TPublishSettings> data: Partial<TProjectPublishSettings>
): Promise<TPublishSettings> { ): Promise<TProjectPublishSettings> {
return this.patch( return this.patch(
`/api/workspaces/${workspaceSlug}/projects/${projectID}/project-deploy-boards/${project_publish_id}/`, `/api/workspaces/${workspaceSlug}/projects/${projectID}/project-deploy-boards/${project_publish_id}/`,
data data

View file

@ -2,7 +2,7 @@ import set from "lodash/set";
import unset from "lodash/unset"; import unset from "lodash/unset";
import { observable, action, makeObservable, runInAction } from "mobx"; import { observable, action, makeObservable, runInAction } from "mobx";
// types // types
import { TPublishSettings } from "@plane/types"; import { TProjectPublishSettings } from "@plane/types";
// services // services
import { ProjectPublishService } from "@/services/project"; import { ProjectPublishService } from "@/services/project";
// store // store
@ -13,22 +13,22 @@ export interface IProjectPublishStore {
generalLoader: boolean; generalLoader: boolean;
fetchSettingsLoader: boolean; fetchSettingsLoader: boolean;
// observables // observables
publishSettingsMap: Record<string, TPublishSettings>; // projectID => TPublishSettings publishSettingsMap: Record<string, TProjectPublishSettings>; // projectID => TProjectPublishSettings
// helpers // helpers
getPublishSettingsByProjectID: (projectID: string) => TPublishSettings | undefined; getPublishSettingsByProjectID: (projectID: string) => TProjectPublishSettings | undefined;
// actions // actions
fetchPublishSettings: (workspaceSlug: string, projectID: string) => Promise<TPublishSettings>; fetchPublishSettings: (workspaceSlug: string, projectID: string) => Promise<TProjectPublishSettings>;
updatePublishSettings: ( updatePublishSettings: (
workspaceSlug: string, workspaceSlug: string,
projectID: string, projectID: string,
projectPublishId: string, projectPublishId: string,
data: Partial<TPublishSettings> data: Partial<TProjectPublishSettings>
) => Promise<TPublishSettings>; ) => Promise<TProjectPublishSettings>;
publishProject: ( publishProject: (
workspaceSlug: string, workspaceSlug: string,
projectID: string, projectID: string,
data: Partial<TPublishSettings> data: Partial<TProjectPublishSettings>
) => Promise<TPublishSettings>; ) => Promise<TProjectPublishSettings>;
unPublishProject: (workspaceSlug: string, projectID: string, projectPublishId: string) => Promise<void>; unPublishProject: (workspaceSlug: string, projectID: string, projectPublishId: string) => Promise<void>;
} }
@ -37,7 +37,7 @@ export class ProjectPublishStore implements IProjectPublishStore {
generalLoader: boolean = false; generalLoader: boolean = false;
fetchSettingsLoader: boolean = false; fetchSettingsLoader: boolean = false;
// observables // observables
publishSettingsMap: Record<string, TPublishSettings> = {}; publishSettingsMap: Record<string, TProjectPublishSettings> = {};
// root store // root store
projectRootStore: ProjectRootStore; projectRootStore: ProjectRootStore;
// services // services
@ -65,9 +65,9 @@ export class ProjectPublishStore implements IProjectPublishStore {
/** /**
* @description returns the publish settings of a particular project * @description returns the publish settings of a particular project
* @param {string} projectID * @param {string} projectID
* @returns {TPublishSettings | undefined} * @returns {TProjectPublishSettings | undefined}
*/ */
getPublishSettingsByProjectID = (projectID: string): TPublishSettings | undefined => getPublishSettingsByProjectID = (projectID: string): TProjectPublishSettings | undefined =>
this.publishSettingsMap?.[projectID] ?? undefined; this.publishSettingsMap?.[projectID] ?? undefined;
/** /**
@ -103,7 +103,7 @@ export class ProjectPublishStore implements IProjectPublishStore {
* @param data * @param data
* @returns * @returns
*/ */
publishProject = async (workspaceSlug: string, projectID: string, data: Partial<TPublishSettings>) => { publishProject = async (workspaceSlug: string, projectID: string, data: Partial<TProjectPublishSettings>) => {
try { try {
runInAction(() => { runInAction(() => {
this.generalLoader = true; this.generalLoader = true;
@ -135,7 +135,7 @@ export class ProjectPublishStore implements IProjectPublishStore {
workspaceSlug: string, workspaceSlug: string,
projectID: string, projectID: string,
projectPublishId: string, projectPublishId: string,
data: Partial<TPublishSettings> data: Partial<TProjectPublishSettings>
) => { ) => {
try { try {
runInAction(() => { runInAction(() => {