[WEB-4852] chore: views refactor (#7729)

* chore: refactored view store and services

* chore: removed unused import

* chore: refactored update view component

* fix: lint errors
This commit is contained in:
Vamsi Krishna 2025-09-11 17:09:56 +05:30 committed by GitHub
parent 8bf059535a
commit 85f23b450d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 156 additions and 473 deletions

View File

@ -191,7 +191,7 @@ export const GlobalIssuesHeader = observer(() => {
</Breadcrumbs> </Breadcrumbs>
</Header.LeftItem> </Header.LeftItem>
<Header.RightItem> <Header.RightItem className="items-center">
{!isLocked ? ( {!isLocked ? (
<> <>
<GlobalViewLayoutSelection <GlobalViewLayoutSelection

View File

@ -1,4 +1,7 @@
import { EIssueLayoutTypes } from "@plane/types"; import { ExternalLink, Link, Pencil, Trash2 } from "lucide-react";
import { useTranslation } from "@plane/i18n";
import { EIssueLayoutTypes, IProjectView } from "@plane/types";
import { TContextMenuItem } from "@plane/ui";
import { TWorkspaceLayoutProps } from "@/components/views/helper"; import { TWorkspaceLayoutProps } from "@/components/views/helper";
export type TLayoutSelectionProps = { export type TLayoutSelectionProps = {
@ -10,3 +13,68 @@ export type TLayoutSelectionProps = {
export const GlobalViewLayoutSelection = (props: TLayoutSelectionProps) => <></>; export const GlobalViewLayoutSelection = (props: TLayoutSelectionProps) => <></>;
export const WorkspaceAdditionalLayouts = (props: TWorkspaceLayoutProps) => <></>; export const WorkspaceAdditionalLayouts = (props: TWorkspaceLayoutProps) => <></>;
export type TMenuItemsFactoryProps = {
isOwner: boolean;
isAdmin: boolean;
setDeleteViewModal: (open: boolean) => void;
setCreateUpdateViewModal: (open: boolean) => void;
handleOpenInNewTab: () => void;
handleCopyText: () => void;
isLocked: boolean;
workspaceSlug: string;
projectId?: string;
viewId: string;
};
export const useMenuItemsFactory = (props: TMenuItemsFactoryProps) => {
const { isOwner, isAdmin, setDeleteViewModal, setCreateUpdateViewModal, handleOpenInNewTab, handleCopyText } = props;
const { t } = useTranslation();
const editMenuItem = () => ({
key: "edit",
action: () => setCreateUpdateViewModal(true),
title: t("edit"),
icon: Pencil,
shouldRender: isOwner,
});
const openInNewTabMenuItem = () => ({
key: "open-new-tab",
action: handleOpenInNewTab,
title: t("open_in_new_tab"),
icon: ExternalLink,
});
const copyLinkMenuItem = () => ({
key: "copy-link",
action: handleCopyText,
title: t("copy_link"),
icon: Link,
});
const deleteMenuItem = () => ({
key: "delete",
action: () => setDeleteViewModal(true),
title: t("delete"),
icon: Trash2,
shouldRender: isOwner || isAdmin,
});
return {
editMenuItem,
openInNewTabMenuItem,
copyLinkMenuItem,
deleteMenuItem,
};
};
export const useViewMenuItems = (props: TMenuItemsFactoryProps): TContextMenuItem[] => {
const factory = useMenuItemsFactory(props);
return [factory.editMenuItem(), factory.openInNewTabMenuItem(), factory.copyLinkMenuItem(), factory.deleteMenuItem()];
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const AdditionalHeaderItems = (view: IProjectView) => <></>;

View File

@ -1,2 +1,2 @@
export * from "./project"; export * from "./project";
export * from "./workspace.service"; export * from "@/services/workspace.service";

View File

@ -1,2 +1,2 @@
export * from "./estimate.service"; export * from "./estimate.service";
export * from "./view.service"; export * from "@/services/view.service";

View File

@ -1,60 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { EViewAccess, TPublishViewSettings } from "@plane/types";
import { ViewService as CoreViewService } from "@/services/view.service";
export class ViewService extends CoreViewService {
constructor() {
super(API_BASE_URL);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async updateViewAccess(workspaceSlug: string, projectId: string, viewId: string, access: EViewAccess) {
return Promise.resolve();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async lockView(workspaceSlug: string, projectId: string, viewId: string) {
return Promise.resolve();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async unLockView(workspaceSlug: string, projectId: string, viewId: string) {
return Promise.resolve();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async getPublishDetails(workspaceSlug: string, projectId: string, viewId: string): Promise<any> {
return Promise.resolve({});
}
async publishView(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
workspaceSlug: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
projectId: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
viewId: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
data: TPublishViewSettings
): Promise<any> {
return Promise.resolve();
}
async updatePublishedView(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
workspaceSlug: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
projectId: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
viewId: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
data: Partial<TPublishViewSettings>
): Promise<void> {
return Promise.resolve();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async unPublishView(workspaceSlug: string, projectId: string, viewId: string): Promise<void> {
return Promise.resolve();
}
}

View File

@ -1,24 +0,0 @@
import { API_BASE_URL } from "@plane/constants";
import { EViewAccess } from "@plane/types";
import { WorkspaceService as CoreWorkspaceService } from "@/services/workspace.service";
export class WorkspaceService extends CoreWorkspaceService {
constructor() {
super(API_BASE_URL);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async updateViewAccess(workspaceSlug: string, viewId: string, access: EViewAccess) {
return Promise.resolve();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async lockView(workspaceSlug: string, viewId: string) {
return Promise.resolve();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async unLockView(workspaceSlug: string, viewId: string) {
return Promise.resolve();
}
}

View File

@ -0,0 +1 @@
export * from "@/store/global-view.store";

View File

@ -0,0 +1 @@
export * from "@/store/project-view.store";

View File

@ -2,7 +2,6 @@
import { useState } from "react"; import { useState } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { ExternalLink, Link, Pencil, Trash2 } from "lucide-react";
// types // types
import { EUserPermissions, EUserPermissionsLevel, PROJECT_VIEW_TRACKER_ELEMENTS } from "@plane/constants"; import { EUserPermissions, EUserPermissionsLevel, PROJECT_VIEW_TRACKER_ELEMENTS } from "@plane/constants";
import { IProjectView } from "@plane/types"; import { IProjectView } from "@plane/types";
@ -13,6 +12,7 @@ import { copyUrlToClipboard, cn } from "@plane/utils";
import { captureClick } from "@/helpers/event-tracker.helper"; import { captureClick } from "@/helpers/event-tracker.helper";
// hooks // hooks
import { useUser, useUserPermissions } from "@/hooks/store/user"; import { useUser, useUserPermissions } from "@/hooks/store/user";
import { useViewMenuItems } from "@/plane-web/components/views/helper";
import { PublishViewModal, useViewPublish } from "@/plane-web/components/views/publish"; import { PublishViewModal, useViewPublish } from "@/plane-web/components/views/publish";
// local imports // local imports
import { DeleteProjectViewModal } from "./delete-view-modal"; import { DeleteProjectViewModal } from "./delete-view-modal";
@ -54,34 +54,18 @@ export const ViewQuickActions: React.FC<Props> = observer((props) => {
}); });
const handleOpenInNewTab = () => window.open(`/${viewLink}`, "_blank"); const handleOpenInNewTab = () => window.open(`/${viewLink}`, "_blank");
const MENU_ITEMS: TContextMenuItem[] = [ const MENU_ITEMS: TContextMenuItem[] = useViewMenuItems({
{ isOwner,
key: "edit", isAdmin,
action: () => setCreateUpdateViewModal(true), setDeleteViewModal,
title: "Edit", setCreateUpdateViewModal,
icon: Pencil, handleOpenInNewTab,
shouldRender: isOwner, handleCopyText,
}, isLocked: view.is_locked,
{ workspaceSlug,
key: "open-new-tab", projectId,
action: handleOpenInNewTab, viewId: view.id,
title: "Open in new tab", });
icon: ExternalLink,
},
{
key: "copy-link",
action: handleCopyText,
title: "Copy link",
icon: Link,
},
{
key: "delete",
action: () => setDeleteViewModal(true),
title: "Delete",
icon: Trash2,
shouldRender: isOwner || isAdmin,
},
];
if (publishContextMenu) MENU_ITEMS.splice(2, 0, publishContextMenu); if (publishContextMenu) MENU_ITEMS.splice(2, 0, publishContextMenu);

View File

@ -1,6 +1,5 @@
import { SetStateAction, useEffect, useState } from "react"; import { SetStateAction, useEffect, useState } from "react";
import { Button } from "@plane/ui"; import { Button } from "@plane/ui";
import { LockedComponent } from "../icons/locked-component";
type Props = { type Props = {
isLocked: boolean; isLocked: boolean;
@ -14,16 +13,8 @@ type Props = {
}; };
export const UpdateViewComponent = (props: Props) => { export const UpdateViewComponent = (props: Props) => {
const { const { isLocked, areFiltersEqual, isOwner, isAuthorizedUser, setIsModalOpen, handleUpdateView, trackerElement } =
isLocked, props;
areFiltersEqual,
isOwner,
isAuthorizedUser,
setIsModalOpen,
handleUpdateView,
lockedTooltipContent,
trackerElement,
} = props;
const [isUpdating, setIsUpdating] = useState(false); const [isUpdating, setIsUpdating] = useState(false);
@ -54,24 +45,19 @@ export const UpdateViewComponent = (props: Props) => {
return ( return (
<div className="flex gap-2 h-fit"> <div className="flex gap-2 h-fit">
{isLocked ? ( {!isLocked && !areFiltersEqual && isAuthorizedUser && (
<LockedComponent toolTipContent={lockedTooltipContent} /> <>
) : ( <Button
!areFiltersEqual && variant="outline-primary"
isAuthorizedUser && ( size="md"
<> className="flex-shrink-0"
<Button data-ph-element={trackerElement}
variant="outline-primary" onClick={() => setIsModalOpen(true)}
size="md" >
className="flex-shrink-0" Save as
data-ph-element={trackerElement} </Button>
onClick={() => setIsModalOpen(true)} {isOwner && <>{updateButton}</>}
> </>
Save as
</Button>
{isOwner && <>{updateButton}</>}
</>
)
)} )}
</div> </div>
); );

View File

@ -2,10 +2,8 @@
import { useState } from "react"; import { useState } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { ExternalLink, LinkIcon, Pencil, Trash2 } from "lucide-react";
// plane imports // plane imports
import { EUserPermissions, EUserPermissionsLevel, GLOBAL_VIEW_TRACKER_ELEMENTS } from "@plane/constants"; import { EUserPermissions, EUserPermissionsLevel, GLOBAL_VIEW_TRACKER_ELEMENTS } from "@plane/constants";
import { useTranslation } from "@plane/i18n";
import { IWorkspaceView } from "@plane/types"; import { IWorkspaceView } from "@plane/types";
import { CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui"; import { CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui";
import { copyUrlToClipboard, cn } from "@plane/utils"; import { copyUrlToClipboard, cn } from "@plane/utils";
@ -14,6 +12,7 @@ import { captureClick } from "@/helpers/event-tracker.helper";
// hooks // hooks
import { useUser, useUserPermissions } from "@/hooks/store/user"; import { useUser, useUserPermissions } from "@/hooks/store/user";
// local imports // local imports
import { useViewMenuItems } from "@/plane-web/components/views/helper";
import { DeleteGlobalViewModal } from "./delete-view-modal"; import { DeleteGlobalViewModal } from "./delete-view-modal";
import { CreateUpdateWorkspaceViewModal } from "./modal"; import { CreateUpdateWorkspaceViewModal } from "./modal";
@ -30,7 +29,6 @@ export const WorkspaceViewQuickActions: React.FC<Props> = observer((props) => {
// store hooks // store hooks
const { data } = useUser(); const { data } = useUser();
const { allowPermissions } = useUserPermissions(); const { allowPermissions } = useUserPermissions();
const { t } = useTranslation();
// auth // auth
const isOwner = view?.owned_by === data?.id; const isOwner = view?.owned_by === data?.id;
const isAdmin = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.WORKSPACE); const isAdmin = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.WORKSPACE);
@ -46,34 +44,17 @@ export const WorkspaceViewQuickActions: React.FC<Props> = observer((props) => {
}); });
const handleOpenInNewTab = () => window.open(`/${viewLink}`, "_blank"); const handleOpenInNewTab = () => window.open(`/${viewLink}`, "_blank");
const MENU_ITEMS: TContextMenuItem[] = [ const MENU_ITEMS: TContextMenuItem[] = useViewMenuItems({
{ isOwner,
key: "edit", isAdmin,
action: () => setUpdateViewModal(true), setDeleteViewModal,
title: t("edit"), setCreateUpdateViewModal: setUpdateViewModal,
icon: Pencil, handleOpenInNewTab,
shouldRender: isOwner, handleCopyText,
}, isLocked: view.is_locked,
{ workspaceSlug,
key: "open-new-tab", viewId: view.id,
action: handleOpenInNewTab, });
title: t("open_in_new_tab"),
icon: ExternalLink,
},
{
key: "copy-link",
action: handleCopyText,
title: t("copy_link"),
icon: LinkIcon,
},
{
key: "delete",
action: () => setDeleteViewModal(true),
title: t("delete"),
icon: Trash2,
shouldRender: isOwner || isAdmin,
},
];
return ( return (
<> <>

View File

@ -2,7 +2,7 @@ import { useContext } from "react";
// mobx store // mobx store
import { StoreContext } from "@/lib/store-context"; import { StoreContext } from "@/lib/store-context";
// types // types
import type { IGlobalViewStore } from "@/store/global-view.store"; import type { IGlobalViewStore } from "@/plane-web/store/global-view.store";
export const useGlobalView = (): IGlobalViewStore => { export const useGlobalView = (): IGlobalViewStore => {
const context = useContext(StoreContext); const context = useContext(StoreContext);

View File

@ -2,7 +2,7 @@ import { useContext } from "react";
// mobx store // mobx store
import { StoreContext } from "@/lib/store-context"; import { StoreContext } from "@/lib/store-context";
// types // types
import type { IProjectViewStore } from "@/store/project-view.store"; import type { IProjectViewStore } from "@/plane-web/store/project-view.store";
export const useProjectView = (): IProjectViewStore => { export const useProjectView = (): IProjectViewStore => {
const context = useContext(StoreContext); const context = useContext(StoreContext);

View File

@ -99,7 +99,7 @@ export const getEstimatePoints = async (workspaceSlug: string) => {
}; };
export const getMembers = async (workspaceSlug: string) => { export const getMembers = async (workspaceSlug: string) => {
const workspaceService = new WorkspaceService(API_BASE_URL); const workspaceService = new WorkspaceService();
const members = await workspaceService.fetchWorkspaceMembers(workspaceSlug); const members = await workspaceService.fetchWorkspaceMembers(workspaceSlug);
const objects = members.map((member: IWorkspaceMember) => member.member); const objects = members.map((member: IWorkspaceMember) => member.member);
return objects; return objects;

View File

@ -1,11 +1,12 @@
import { API_BASE_URL } from "@plane/constants";
import { IProjectView } from "@plane/types"; import { IProjectView } from "@plane/types";
import { APIService } from "@/services/api.service"; import { APIService } from "@/services/api.service";
// types // types
// helpers // helpers
export class ViewService extends APIService { export class ViewService extends APIService {
constructor(baseUrl: string) { constructor() {
super(baseUrl); super(API_BASE_URL);
} }
async createView(workspaceSlug: string, projectId: string, data: Partial<IProjectView>): Promise<any> { async createView(workspaceSlug: string, projectId: string, data: Partial<IProjectView>): Promise<any> {

View File

@ -1,3 +1,4 @@
import { API_BASE_URL } from "@plane/constants";
import { import {
IWorkspace, IWorkspace,
IWorkspaceMemberMe, IWorkspaceMemberMe,
@ -23,8 +24,8 @@ import {
import { APIService } from "@/services/api.service"; import { APIService } from "@/services/api.service";
export class WorkspaceService extends APIService { export class WorkspaceService extends APIService {
constructor(baseUrl: string) { constructor() {
super(baseUrl); super(API_BASE_URL);
} }
async userWorkspaces(): Promise<IWorkspace[]> { async userWorkspaces(): Promise<IWorkspace[]> {

View File

@ -5,7 +5,7 @@ import set from "lodash/set";
import { observable, action, makeObservable, runInAction, computed } from "mobx"; import { observable, action, makeObservable, runInAction, computed } from "mobx";
import { computedFn } from "mobx-utils"; import { computedFn } from "mobx-utils";
import { EIssueFilterType } from "@plane/constants"; import { EIssueFilterType } from "@plane/constants";
import { EViewAccess, IIssueFilterOptions, IWorkspaceView } from "@plane/types"; import { IIssueFilterOptions, IWorkspaceView } from "@plane/types";
// constants // constants
// services // services
import { WorkspaceService } from "@/plane-web/services"; import { WorkspaceService } from "@/plane-web/services";
@ -50,15 +50,18 @@ export class GlobalViewStore implements IGlobalViewStore {
// actions // actions
fetchAllGlobalViews: action, fetchAllGlobalViews: action,
fetchGlobalViewDetails: action, fetchGlobalViewDetails: action,
createGlobalView: action,
updateGlobalView: action,
deleteGlobalView: action, deleteGlobalView: action,
updateGlobalView: action,
createGlobalView: action,
}); });
// root store // root store
this.rootStore = _rootStore; this.rootStore = _rootStore;
// services // services
this.workspaceService = new WorkspaceService(); this.workspaceService = new WorkspaceService();
this.createGlobalView = this.createGlobalView.bind(this);
this.updateGlobalView = this.updateGlobalView.bind(this);
} }
/** /**
@ -130,18 +133,19 @@ export class GlobalViewStore implements IGlobalViewStore {
* @param workspaceSlug * @param workspaceSlug
* @param data * @param data
*/ */
createGlobalView = async (workspaceSlug: string, data: Partial<IWorkspaceView>): Promise<IWorkspaceView> => { async createGlobalView(workspaceSlug: string, data: Partial<IWorkspaceView>) {
const response = await this.workspaceService.createView(workspaceSlug, data); try {
runInAction(() => { const response = await this.workspaceService.createView(workspaceSlug, data);
set(this.globalViewMap, response.id, response); runInAction(() => {
}); set(this.globalViewMap, response.id, response);
});
if (data.access === EViewAccess.PRIVATE) { return response;
await this.updateViewAccess(workspaceSlug, response.id, EViewAccess.PRIVATE); } catch (error) {
console.error(error);
throw error;
} }
}
return response;
};
/** /**
* @description update global view * @description update global view
@ -149,11 +153,11 @@ export class GlobalViewStore implements IGlobalViewStore {
* @param viewId * @param viewId
* @param data * @param data
*/ */
updateGlobalView = async ( async updateGlobalView(
workspaceSlug: string, workspaceSlug: string,
viewId: string, viewId: string,
data: Partial<IWorkspaceView> data: Partial<IWorkspaceView>
): Promise<IWorkspaceView | undefined> => { ): Promise<IWorkspaceView | undefined> {
const currentViewData = this.getViewDetailsById(viewId) ? cloneDeep(this.getViewDetailsById(viewId)) : undefined; const currentViewData = this.getViewDetailsById(viewId) ? cloneDeep(this.getViewDetailsById(viewId)) : undefined;
try { try {
Object.keys(data).forEach((key) => { Object.keys(data).forEach((key) => {
@ -161,14 +165,7 @@ export class GlobalViewStore implements IGlobalViewStore {
set(this.globalViewMap, [viewId, currentKey], data[currentKey]); set(this.globalViewMap, [viewId, currentKey], data[currentKey]);
}); });
const promiseRequests = []; const currentView = await this.workspaceService.updateView(workspaceSlug, viewId, data);
promiseRequests.push(this.workspaceService.updateView(workspaceSlug, viewId, data));
if (data.access !== undefined && data.access !== currentViewData?.access) {
promiseRequests.push(this.updateViewAccess(workspaceSlug, viewId, data.access));
}
const [currentView] = await Promise.all(promiseRequests);
// applying the filters in the global view // applying the filters in the global view
if (!isEqual(currentViewData?.filters || {}, currentView?.filters || {})) { if (!isEqual(currentViewData?.filters || {}, currentView?.filters || {})) {
@ -205,7 +202,7 @@ export class GlobalViewStore implements IGlobalViewStore {
if (currentViewData) set(this.globalViewMap, [viewId, currentKey], currentViewData[currentKey]); if (currentViewData) set(this.globalViewMap, [viewId, currentKey], currentViewData[currentKey]);
}); });
} }
}; }
/** /**
* @description delete global view * @description delete global view
@ -218,73 +215,4 @@ export class GlobalViewStore implements IGlobalViewStore {
delete this.globalViewMap[viewId]; delete this.globalViewMap[viewId];
}); });
}); });
/** Locks view
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
lockView = async (workspaceSlug: string, viewId: string) => {
try {
const currentView = this.getViewDetailsById(viewId);
if (currentView?.is_locked) return;
runInAction(() => {
set(this.globalViewMap, [viewId, "is_locked"], true);
});
await this.workspaceService.lockView(workspaceSlug, viewId);
} catch (error) {
console.error("Failed to lock the view in view store", error);
runInAction(() => {
set(this.globalViewMap, [viewId, "is_locked"], false);
});
}
};
/**
* unlocks View
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
unLockView = async (workspaceSlug: string, viewId: string) => {
try {
const currentView = this.getViewDetailsById(viewId);
if (!currentView?.is_locked) return;
runInAction(() => {
set(this.globalViewMap, [viewId, "is_locked"], false);
});
await this.workspaceService.unLockView(workspaceSlug, viewId);
} catch (error) {
console.error("Failed to unlock view in view store", error);
runInAction(() => {
set(this.globalViewMap, [viewId, "is_locked"], true);
});
}
};
/**
* Updates View access
* @param workspaceSlug
* @param projectId
* @param viewId
* @param access
* @returns
*/
updateViewAccess = async (workspaceSlug: string, viewId: string, access: EViewAccess) => {
const currentView = this.getViewDetailsById(viewId);
const currentAccess = currentView?.access;
try {
runInAction(() => {
set(this.globalViewMap, [viewId, "access"], access);
});
await this.workspaceService.updateViewAccess(workspaceSlug, viewId, access);
} catch (error) {
console.error("Failed to update Access for view", error);
runInAction(() => {
set(this.globalViewMap, [viewId, "access"], currentAccess);
});
}
};
} }

View File

@ -2,7 +2,7 @@ import { set } from "lodash";
import { observable, action, makeObservable, runInAction, computed } from "mobx"; import { observable, action, makeObservable, runInAction, computed } from "mobx";
import { computedFn } from "mobx-utils"; import { computedFn } from "mobx-utils";
// types // types
import { EViewAccess, IProjectView, TPublishViewDetails, TPublishViewSettings, TViewFilters } from "@plane/types"; import { IProjectView, TViewFilters } from "@plane/types";
// constants // constants
// helpers // helpers
import { getValidatedViewFilters, getViewName, orderViews, shouldFilterView } from "@plane/utils"; import { getValidatedViewFilters, getViewName, orderViews, shouldFilterView } from "@plane/utils";
@ -41,25 +41,6 @@ export interface IProjectViewStore {
// favorites actions // favorites actions
addViewToFavorites: (workspaceSlug: string, projectId: string, viewId: string) => Promise<any>; addViewToFavorites: (workspaceSlug: string, projectId: string, viewId: string) => Promise<any>;
removeViewFromFavorites: (workspaceSlug: string, projectId: string, viewId: string) => Promise<any>; removeViewFromFavorites: (workspaceSlug: string, projectId: string, viewId: string) => Promise<any>;
// publish
publishView: (
workspaceSlug: string,
projectId: string,
viewId: string,
data: TPublishViewSettings
) => Promise<TPublishViewDetails | undefined>;
fetchPublishDetails: (
workspaceSlug: string,
projectId: string,
viewId: string
) => Promise<TPublishViewDetails | undefined>;
updatePublishedView: (
workspaceSlug: string,
projectId: string,
viewId: string,
data: Partial<TPublishViewSettings>
) => Promise<void>;
unPublishView: (workspaceSlug: string, projectId: string, viewId: string) => Promise<void>;
} }
export class ProjectViewStore implements IProjectViewStore { export class ProjectViewStore implements IProjectViewStore {
@ -101,6 +82,9 @@ export class ProjectViewStore implements IProjectViewStore {
this.rootStore = _rootStore; this.rootStore = _rootStore;
// services // services
this.viewService = new ViewService(); this.viewService = new ViewService();
this.createView = this.createView.bind(this);
this.updateView = this.updateView.bind(this);
} }
/** /**
@ -213,19 +197,15 @@ export class ProjectViewStore implements IProjectViewStore {
* @param data * @param data
* @returns Promise<IProjectView> * @returns Promise<IProjectView>
*/ */
createView = async (workspaceSlug: string, projectId: string, data: Partial<IProjectView>): Promise<IProjectView> => { async createView(workspaceSlug: string, projectId: string, data: Partial<IProjectView>): Promise<IProjectView> {
const response = await this.viewService.createView(workspaceSlug, projectId, getValidatedViewFilters(data)); const response = await this.viewService.createView(workspaceSlug, projectId, getValidatedViewFilters(data));
runInAction(() => { runInAction(() => {
set(this.viewMap, [response.id], response); set(this.viewMap, [response.id], response);
}); });
if (data.access === EViewAccess.PRIVATE) {
await this.updateViewAccess(workspaceSlug, projectId, response.id, EViewAccess.PRIVATE);
}
return response; return response;
}; }
/** /**
* Updates a view details of specific view and updates it in the store * Updates a view details of specific view and updates it in the store
@ -235,29 +215,22 @@ export class ProjectViewStore implements IProjectViewStore {
* @param data * @param data
* @returns Promise<IProjectView> * @returns Promise<IProjectView>
*/ */
updateView = async ( async updateView(
workspaceSlug: string, workspaceSlug: string,
projectId: string, projectId: string,
viewId: string, viewId: string,
data: Partial<IProjectView> data: Partial<IProjectView>
): Promise<IProjectView> => { ): Promise<IProjectView> {
const currentView = this.getViewById(viewId); const currentView = this.getViewById(viewId);
const promiseRequests = [];
promiseRequests.push(this.viewService.patchView(workspaceSlug, projectId, viewId, data));
runInAction(() => { runInAction(() => {
set(this.viewMap, [viewId], { ...currentView, ...data }); set(this.viewMap, [viewId], { ...currentView, ...data });
}); });
if (data.access !== undefined && data.access !== currentView.access) { const response = await this.viewService.patchView(workspaceSlug, projectId, viewId, data);
promiseRequests.push(this.updateViewAccess(workspaceSlug, projectId, viewId, data.access));
}
const [response] = await Promise.all(promiseRequests);
return response; return response;
}; }
/** /**
* Deletes a view and removes it from the viewMap object * Deletes a view and removes it from the viewMap object
@ -275,75 +248,6 @@ export class ProjectViewStore implements IProjectViewStore {
}); });
}; };
/** Locks view
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
lockView = async (workspaceSlug: string, projectId: string, viewId: string) => {
try {
const currentView = this.getViewById(viewId);
if (currentView?.is_locked) return;
runInAction(() => {
set(this.viewMap, [viewId, "is_locked"], true);
});
await this.viewService.lockView(workspaceSlug, projectId, viewId);
} catch (error) {
console.error("Failed to lock the view in view store", error);
runInAction(() => {
set(this.viewMap, [viewId, "is_locked"], false);
});
}
};
/**
* unlocks View
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
unLockView = async (workspaceSlug: string, projectId: string, viewId: string) => {
try {
const currentView = this.getViewById(viewId);
if (!currentView?.is_locked) return;
runInAction(() => {
set(this.viewMap, [viewId, "is_locked"], false);
});
await this.viewService.unLockView(workspaceSlug, projectId, viewId);
} catch (error) {
console.error("Failed to unlock view in view store", error);
runInAction(() => {
set(this.viewMap, [viewId, "is_locked"], true);
});
}
};
/**
* Updates View access
* @param workspaceSlug
* @param projectId
* @param viewId
* @param access
* @returns
*/
updateViewAccess = async (workspaceSlug: string, projectId: string, viewId: string, access: EViewAccess) => {
const currentView = this.getViewById(viewId);
const currentAccess = currentView?.access;
try {
runInAction(() => {
set(this.viewMap, [viewId, "access"], access);
});
await this.viewService.updateViewAccess(workspaceSlug, projectId, viewId, access);
} catch (error) {
console.error("Failed to update Access for view", error);
runInAction(() => {
set(this.viewMap, [viewId, "access"], currentAccess);
});
}
};
/** /**
* Adds a view to favorites * Adds a view to favorites
* @param workspaceSlug * @param workspaceSlug
@ -394,91 +298,4 @@ export class ProjectViewStore implements IProjectViewStore {
}); });
} }
}; };
/**
* Publishes View to the Public
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
publishView = async (workspaceSlug: string, projectId: string, viewId: string, data: TPublishViewSettings) => {
try {
const response = (await this.viewService.publishView(
workspaceSlug,
projectId,
viewId,
data
)) as TPublishViewDetails;
runInAction(() => {
set(this.viewMap, [viewId, "anchor"], response?.anchor);
});
return response;
} catch (error) {
console.error("Failed to publish view", error);
}
};
/**
* fetches Published Details
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
fetchPublishDetails = async (workspaceSlug: string, projectId: string, viewId: string) => {
try {
const response = (await this.viewService.getPublishDetails(
workspaceSlug,
projectId,
viewId
)) as TPublishViewDetails;
runInAction(() => {
set(this.viewMap, [viewId, "anchor"], response?.anchor);
});
return response;
} catch (error) {
console.error("Failed to fetch published view details", error);
}
};
/**
* updates already published view
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
updatePublishedView = async (
workspaceSlug: string,
projectId: string,
viewId: string,
data: Partial<TPublishViewSettings>
) => {
try {
return await this.viewService.updatePublishedView(workspaceSlug, projectId, viewId, data);
} catch (error) {
console.error("Failed to update published view details", error);
}
};
/**
* un publishes the view
* @param workspaceSlug
* @param projectId
* @param viewId
* @returns
*/
unPublishView = async (workspaceSlug: string, projectId: string, viewId: string) => {
try {
const response = await this.viewService.unPublishView(workspaceSlug, projectId, viewId);
runInAction(() => {
set(this.viewMap, [viewId, "anchor"], null);
});
return response;
} catch (error) {
console.error("Failed to unPublish view", error);
}
};
} }

View File

@ -18,7 +18,7 @@ import {
TProjectMembership, TProjectMembership,
} from "@plane/types"; } from "@plane/types";
// plane web imports // plane web imports
import { WorkspaceService } from "@/plane-web/services/workspace.service"; import { WorkspaceService } from "@/plane-web/services";
import type { RootStore } from "@/plane-web/store/root.store"; import type { RootStore } from "@/plane-web/store/root.store";
// services // services
import projectMemberService from "@/services/project/project-member.service"; import projectMemberService from "@/services/project/project-member.service";

View File

@ -1,2 +1,2 @@
export * from "./project"; export * from "./project";
export * from "ce/services/workspace.service"; export * from "@/services/workspace.service";

View File

@ -1,2 +1 @@
export * from "./estimate.service"; export * from "./estimate.service";
export * from "ce/services/project/view.service";