diff --git a/apps/web/app/(all)/[workspaceSlug]/(projects)/workspace-views/header.tsx b/apps/web/app/(all)/[workspaceSlug]/(projects)/workspace-views/header.tsx index 1c50844c8..b4fa1bbd9 100644 --- a/apps/web/app/(all)/[workspaceSlug]/(projects)/workspace-views/header.tsx +++ b/apps/web/app/(all)/[workspaceSlug]/(projects)/workspace-views/header.tsx @@ -191,7 +191,7 @@ export const GlobalIssuesHeader = observer(() => { - + {!isLocked ? ( <> <>; 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) => <>; diff --git a/apps/web/ce/services/index.ts b/apps/web/ce/services/index.ts index d0c059461..7e406b1b4 100644 --- a/apps/web/ce/services/index.ts +++ b/apps/web/ce/services/index.ts @@ -1,2 +1,2 @@ export * from "./project"; -export * from "./workspace.service"; +export * from "@/services/workspace.service"; diff --git a/apps/web/ce/services/project/index.ts b/apps/web/ce/services/project/index.ts index 15e12c5fd..8b75f6bf5 100644 --- a/apps/web/ce/services/project/index.ts +++ b/apps/web/ce/services/project/index.ts @@ -1,2 +1,2 @@ export * from "./estimate.service"; -export * from "./view.service"; +export * from "@/services/view.service"; diff --git a/apps/web/ce/services/project/view.service.ts b/apps/web/ce/services/project/view.service.ts deleted file mode 100644 index 5ab65a1b6..000000000 --- a/apps/web/ce/services/project/view.service.ts +++ /dev/null @@ -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 { - 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 { - 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 - ): Promise { - return Promise.resolve(); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async unPublishView(workspaceSlug: string, projectId: string, viewId: string): Promise { - return Promise.resolve(); - } -} diff --git a/apps/web/ce/services/workspace.service.ts b/apps/web/ce/services/workspace.service.ts deleted file mode 100644 index d1e175c81..000000000 --- a/apps/web/ce/services/workspace.service.ts +++ /dev/null @@ -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(); - } -} diff --git a/apps/web/ce/store/global-view.store.ts b/apps/web/ce/store/global-view.store.ts new file mode 100644 index 000000000..f0d5cdfb4 --- /dev/null +++ b/apps/web/ce/store/global-view.store.ts @@ -0,0 +1 @@ +export * from "@/store/global-view.store"; diff --git a/apps/web/ce/store/project-view.store.ts b/apps/web/ce/store/project-view.store.ts new file mode 100644 index 000000000..41d7ba1ca --- /dev/null +++ b/apps/web/ce/store/project-view.store.ts @@ -0,0 +1 @@ +export * from "@/store/project-view.store"; diff --git a/apps/web/core/components/views/quick-actions.tsx b/apps/web/core/components/views/quick-actions.tsx index d46191a4f..9c5fbefcb 100644 --- a/apps/web/core/components/views/quick-actions.tsx +++ b/apps/web/core/components/views/quick-actions.tsx @@ -2,7 +2,6 @@ import { useState } from "react"; import { observer } from "mobx-react"; -import { ExternalLink, Link, Pencil, Trash2 } from "lucide-react"; // types import { EUserPermissions, EUserPermissionsLevel, PROJECT_VIEW_TRACKER_ELEMENTS } from "@plane/constants"; import { IProjectView } from "@plane/types"; @@ -13,6 +12,7 @@ import { copyUrlToClipboard, cn } from "@plane/utils"; import { captureClick } from "@/helpers/event-tracker.helper"; // hooks import { useUser, useUserPermissions } from "@/hooks/store/user"; +import { useViewMenuItems } from "@/plane-web/components/views/helper"; import { PublishViewModal, useViewPublish } from "@/plane-web/components/views/publish"; // local imports import { DeleteProjectViewModal } from "./delete-view-modal"; @@ -54,34 +54,18 @@ export const ViewQuickActions: React.FC = observer((props) => { }); const handleOpenInNewTab = () => window.open(`/${viewLink}`, "_blank"); - const MENU_ITEMS: TContextMenuItem[] = [ - { - key: "edit", - action: () => setCreateUpdateViewModal(true), - title: "Edit", - icon: Pencil, - shouldRender: isOwner, - }, - { - key: "open-new-tab", - action: handleOpenInNewTab, - 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, - }, - ]; + const MENU_ITEMS: TContextMenuItem[] = useViewMenuItems({ + isOwner, + isAdmin, + setDeleteViewModal, + setCreateUpdateViewModal, + handleOpenInNewTab, + handleCopyText, + isLocked: view.is_locked, + workspaceSlug, + projectId, + viewId: view.id, + }); if (publishContextMenu) MENU_ITEMS.splice(2, 0, publishContextMenu); diff --git a/apps/web/core/components/views/update-view-component.tsx b/apps/web/core/components/views/update-view-component.tsx index 9b199e0f5..54b6ae47d 100644 --- a/apps/web/core/components/views/update-view-component.tsx +++ b/apps/web/core/components/views/update-view-component.tsx @@ -1,6 +1,5 @@ import { SetStateAction, useEffect, useState } from "react"; import { Button } from "@plane/ui"; -import { LockedComponent } from "../icons/locked-component"; type Props = { isLocked: boolean; @@ -14,16 +13,8 @@ type Props = { }; export const UpdateViewComponent = (props: Props) => { - const { - isLocked, - areFiltersEqual, - isOwner, - isAuthorizedUser, - setIsModalOpen, - handleUpdateView, - lockedTooltipContent, - trackerElement, - } = props; + const { isLocked, areFiltersEqual, isOwner, isAuthorizedUser, setIsModalOpen, handleUpdateView, trackerElement } = + props; const [isUpdating, setIsUpdating] = useState(false); @@ -54,24 +45,19 @@ export const UpdateViewComponent = (props: Props) => { return (
- {isLocked ? ( - - ) : ( - !areFiltersEqual && - isAuthorizedUser && ( - <> - - {isOwner && <>{updateButton}} - - ) + {!isLocked && !areFiltersEqual && isAuthorizedUser && ( + <> + + {isOwner && <>{updateButton}} + )}
); diff --git a/apps/web/core/components/workspace/views/quick-action.tsx b/apps/web/core/components/workspace/views/quick-action.tsx index cbb67cb91..adb6b5e4b 100644 --- a/apps/web/core/components/workspace/views/quick-action.tsx +++ b/apps/web/core/components/workspace/views/quick-action.tsx @@ -2,10 +2,8 @@ import { useState } from "react"; import { observer } from "mobx-react"; -import { ExternalLink, LinkIcon, Pencil, Trash2 } from "lucide-react"; // plane imports import { EUserPermissions, EUserPermissionsLevel, GLOBAL_VIEW_TRACKER_ELEMENTS } from "@plane/constants"; -import { useTranslation } from "@plane/i18n"; import { IWorkspaceView } from "@plane/types"; import { CustomMenu, TContextMenuItem, TOAST_TYPE, setToast } from "@plane/ui"; import { copyUrlToClipboard, cn } from "@plane/utils"; @@ -14,6 +12,7 @@ import { captureClick } from "@/helpers/event-tracker.helper"; // hooks import { useUser, useUserPermissions } from "@/hooks/store/user"; // local imports +import { useViewMenuItems } from "@/plane-web/components/views/helper"; import { DeleteGlobalViewModal } from "./delete-view-modal"; import { CreateUpdateWorkspaceViewModal } from "./modal"; @@ -30,7 +29,6 @@ export const WorkspaceViewQuickActions: React.FC = observer((props) => { // store hooks const { data } = useUser(); const { allowPermissions } = useUserPermissions(); - const { t } = useTranslation(); // auth const isOwner = view?.owned_by === data?.id; const isAdmin = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.WORKSPACE); @@ -46,34 +44,17 @@ export const WorkspaceViewQuickActions: React.FC = observer((props) => { }); const handleOpenInNewTab = () => window.open(`/${viewLink}`, "_blank"); - const MENU_ITEMS: TContextMenuItem[] = [ - { - key: "edit", - action: () => setUpdateViewModal(true), - title: t("edit"), - icon: Pencil, - shouldRender: isOwner, - }, - { - key: "open-new-tab", - 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, - }, - ]; + const MENU_ITEMS: TContextMenuItem[] = useViewMenuItems({ + isOwner, + isAdmin, + setDeleteViewModal, + setCreateUpdateViewModal: setUpdateViewModal, + handleOpenInNewTab, + handleCopyText, + isLocked: view.is_locked, + workspaceSlug, + viewId: view.id, + }); return ( <> diff --git a/apps/web/core/hooks/store/use-global-view.ts b/apps/web/core/hooks/store/use-global-view.ts index 04e279cbb..92691be25 100644 --- a/apps/web/core/hooks/store/use-global-view.ts +++ b/apps/web/core/hooks/store/use-global-view.ts @@ -2,7 +2,7 @@ import { useContext } from "react"; // mobx store import { StoreContext } from "@/lib/store-context"; // types -import type { IGlobalViewStore } from "@/store/global-view.store"; +import type { IGlobalViewStore } from "@/plane-web/store/global-view.store"; export const useGlobalView = (): IGlobalViewStore => { const context = useContext(StoreContext); diff --git a/apps/web/core/hooks/store/use-project-view.ts b/apps/web/core/hooks/store/use-project-view.ts index 493c81641..43e43d56d 100644 --- a/apps/web/core/hooks/store/use-project-view.ts +++ b/apps/web/core/hooks/store/use-project-view.ts @@ -2,7 +2,7 @@ import { useContext } from "react"; // mobx store import { StoreContext } from "@/lib/store-context"; // types -import type { IProjectViewStore } from "@/store/project-view.store"; +import type { IProjectViewStore } from "@/plane-web/store/project-view.store"; export const useProjectView = (): IProjectViewStore => { const context = useContext(StoreContext); diff --git a/apps/web/core/local-db/utils/load-workspace.ts b/apps/web/core/local-db/utils/load-workspace.ts index 509e093a9..92037d15d 100644 --- a/apps/web/core/local-db/utils/load-workspace.ts +++ b/apps/web/core/local-db/utils/load-workspace.ts @@ -99,7 +99,7 @@ export const getEstimatePoints = 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 objects = members.map((member: IWorkspaceMember) => member.member); return objects; diff --git a/apps/web/core/services/view.service.ts b/apps/web/core/services/view.service.ts index b05331775..57db5f82f 100644 --- a/apps/web/core/services/view.service.ts +++ b/apps/web/core/services/view.service.ts @@ -1,11 +1,12 @@ +import { API_BASE_URL } from "@plane/constants"; import { IProjectView } from "@plane/types"; import { APIService } from "@/services/api.service"; // types // helpers export class ViewService extends APIService { - constructor(baseUrl: string) { - super(baseUrl); + constructor() { + super(API_BASE_URL); } async createView(workspaceSlug: string, projectId: string, data: Partial): Promise { diff --git a/apps/web/core/services/workspace.service.ts b/apps/web/core/services/workspace.service.ts index 4bc042e1c..1c1dfeea6 100644 --- a/apps/web/core/services/workspace.service.ts +++ b/apps/web/core/services/workspace.service.ts @@ -1,3 +1,4 @@ +import { API_BASE_URL } from "@plane/constants"; import { IWorkspace, IWorkspaceMemberMe, @@ -23,8 +24,8 @@ import { import { APIService } from "@/services/api.service"; export class WorkspaceService extends APIService { - constructor(baseUrl: string) { - super(baseUrl); + constructor() { + super(API_BASE_URL); } async userWorkspaces(): Promise { diff --git a/apps/web/core/store/global-view.store.ts b/apps/web/core/store/global-view.store.ts index aa0503623..7ed35b307 100644 --- a/apps/web/core/store/global-view.store.ts +++ b/apps/web/core/store/global-view.store.ts @@ -5,7 +5,7 @@ import set from "lodash/set"; import { observable, action, makeObservable, runInAction, computed } from "mobx"; import { computedFn } from "mobx-utils"; import { EIssueFilterType } from "@plane/constants"; -import { EViewAccess, IIssueFilterOptions, IWorkspaceView } from "@plane/types"; +import { IIssueFilterOptions, IWorkspaceView } from "@plane/types"; // constants // services import { WorkspaceService } from "@/plane-web/services"; @@ -50,15 +50,18 @@ export class GlobalViewStore implements IGlobalViewStore { // actions fetchAllGlobalViews: action, fetchGlobalViewDetails: action, - createGlobalView: action, - updateGlobalView: action, deleteGlobalView: action, + updateGlobalView: action, + createGlobalView: action, }); // root store this.rootStore = _rootStore; // services 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 data */ - createGlobalView = async (workspaceSlug: string, data: Partial): Promise => { - const response = await this.workspaceService.createView(workspaceSlug, data); - runInAction(() => { - set(this.globalViewMap, response.id, response); - }); + async createGlobalView(workspaceSlug: string, data: Partial) { + try { + const response = await this.workspaceService.createView(workspaceSlug, data); + runInAction(() => { + set(this.globalViewMap, response.id, response); + }); - if (data.access === EViewAccess.PRIVATE) { - await this.updateViewAccess(workspaceSlug, response.id, EViewAccess.PRIVATE); + return response; + } catch (error) { + console.error(error); + throw error; } - - return response; - }; + } /** * @description update global view @@ -149,11 +153,11 @@ export class GlobalViewStore implements IGlobalViewStore { * @param viewId * @param data */ - updateGlobalView = async ( + async updateGlobalView( workspaceSlug: string, viewId: string, data: Partial - ): Promise => { + ): Promise { const currentViewData = this.getViewDetailsById(viewId) ? cloneDeep(this.getViewDetailsById(viewId)) : undefined; try { Object.keys(data).forEach((key) => { @@ -161,14 +165,7 @@ export class GlobalViewStore implements IGlobalViewStore { set(this.globalViewMap, [viewId, currentKey], data[currentKey]); }); - const promiseRequests = []; - 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); + const currentView = await this.workspaceService.updateView(workspaceSlug, viewId, data); // applying the filters in the global view if (!isEqual(currentViewData?.filters || {}, currentView?.filters || {})) { @@ -205,7 +202,7 @@ export class GlobalViewStore implements IGlobalViewStore { if (currentViewData) set(this.globalViewMap, [viewId, currentKey], currentViewData[currentKey]); }); } - }; + } /** * @description delete global view @@ -218,73 +215,4 @@ export class GlobalViewStore implements IGlobalViewStore { 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); - }); - } - }; } diff --git a/apps/web/core/store/project-view.store.ts b/apps/web/core/store/project-view.store.ts index 49c7a1122..732122471 100644 --- a/apps/web/core/store/project-view.store.ts +++ b/apps/web/core/store/project-view.store.ts @@ -2,7 +2,7 @@ import { set } from "lodash"; import { observable, action, makeObservable, runInAction, computed } from "mobx"; import { computedFn } from "mobx-utils"; // types -import { EViewAccess, IProjectView, TPublishViewDetails, TPublishViewSettings, TViewFilters } from "@plane/types"; +import { IProjectView, TViewFilters } from "@plane/types"; // constants // helpers import { getValidatedViewFilters, getViewName, orderViews, shouldFilterView } from "@plane/utils"; @@ -41,25 +41,6 @@ export interface IProjectViewStore { // favorites actions addViewToFavorites: (workspaceSlug: string, projectId: string, viewId: string) => Promise; removeViewFromFavorites: (workspaceSlug: string, projectId: string, viewId: string) => Promise; - // publish - publishView: ( - workspaceSlug: string, - projectId: string, - viewId: string, - data: TPublishViewSettings - ) => Promise; - fetchPublishDetails: ( - workspaceSlug: string, - projectId: string, - viewId: string - ) => Promise; - updatePublishedView: ( - workspaceSlug: string, - projectId: string, - viewId: string, - data: Partial - ) => Promise; - unPublishView: (workspaceSlug: string, projectId: string, viewId: string) => Promise; } export class ProjectViewStore implements IProjectViewStore { @@ -101,6 +82,9 @@ export class ProjectViewStore implements IProjectViewStore { this.rootStore = _rootStore; // services 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 * @returns Promise */ - createView = async (workspaceSlug: string, projectId: string, data: Partial): Promise => { + async createView(workspaceSlug: string, projectId: string, data: Partial): Promise { const response = await this.viewService.createView(workspaceSlug, projectId, getValidatedViewFilters(data)); runInAction(() => { set(this.viewMap, [response.id], response); }); - if (data.access === EViewAccess.PRIVATE) { - await this.updateViewAccess(workspaceSlug, projectId, response.id, EViewAccess.PRIVATE); - } - return response; - }; + } /** * Updates a view details of specific view and updates it in the store @@ -235,29 +215,22 @@ export class ProjectViewStore implements IProjectViewStore { * @param data * @returns Promise */ - updateView = async ( + async updateView( workspaceSlug: string, projectId: string, viewId: string, data: Partial - ): Promise => { + ): Promise { const currentView = this.getViewById(viewId); - const promiseRequests = []; - promiseRequests.push(this.viewService.patchView(workspaceSlug, projectId, viewId, data)); - runInAction(() => { set(this.viewMap, [viewId], { ...currentView, ...data }); }); - if (data.access !== undefined && data.access !== currentView.access) { - promiseRequests.push(this.updateViewAccess(workspaceSlug, projectId, viewId, data.access)); - } - - const [response] = await Promise.all(promiseRequests); + const response = await this.viewService.patchView(workspaceSlug, projectId, viewId, data); return response; - }; + } /** * 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 * @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 - ) => { - 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); - } - }; } diff --git a/apps/web/core/store/user/base-permissions.store.ts b/apps/web/core/store/user/base-permissions.store.ts index 4d6f13d26..019c46219 100644 --- a/apps/web/core/store/user/base-permissions.store.ts +++ b/apps/web/core/store/user/base-permissions.store.ts @@ -18,7 +18,7 @@ import { TProjectMembership, } from "@plane/types"; // 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"; // services import projectMemberService from "@/services/project/project-member.service"; diff --git a/apps/web/ee/services/index.ts b/apps/web/ee/services/index.ts index 6f175ecf7..7e406b1b4 100644 --- a/apps/web/ee/services/index.ts +++ b/apps/web/ee/services/index.ts @@ -1,2 +1,2 @@ export * from "./project"; -export * from "ce/services/workspace.service"; +export * from "@/services/workspace.service"; diff --git a/apps/web/ee/services/project/index.ts b/apps/web/ee/services/project/index.ts index b2cec5064..29b17e55d 100644 --- a/apps/web/ee/services/project/index.ts +++ b/apps/web/ee/services/project/index.ts @@ -1,2 +1 @@ export * from "./estimate.service"; -export * from "ce/services/project/view.service";