[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>
</Header.LeftItem>
<Header.RightItem>
<Header.RightItem className="items-center">
{!isLocked ? (
<>
<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";
export type TLayoutSelectionProps = {
@ -10,3 +13,68 @@ export type TLayoutSelectionProps = {
export const GlobalViewLayoutSelection = (props: TLayoutSelectionProps) => <></>;
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 "./workspace.service";
export * from "@/services/workspace.service";

View File

@ -1,2 +1,2 @@
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 { 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<Props> = 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);

View File

@ -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 (
<div className="flex gap-2 h-fit">
{isLocked ? (
<LockedComponent toolTipContent={lockedTooltipContent} />
) : (
!areFiltersEqual &&
isAuthorizedUser && (
<>
<Button
variant="outline-primary"
size="md"
className="flex-shrink-0"
data-ph-element={trackerElement}
onClick={() => setIsModalOpen(true)}
>
Save as
</Button>
{isOwner && <>{updateButton}</>}
</>
)
{!isLocked && !areFiltersEqual && isAuthorizedUser && (
<>
<Button
variant="outline-primary"
size="md"
className="flex-shrink-0"
data-ph-element={trackerElement}
onClick={() => setIsModalOpen(true)}
>
Save as
</Button>
{isOwner && <>{updateButton}</>}
</>
)}
</div>
);

View File

@ -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<Props> = 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<Props> = 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 (
<>

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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<IProjectView>): Promise<any> {

View File

@ -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<IWorkspace[]> {

View File

@ -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<IWorkspaceView>): Promise<IWorkspaceView> => {
const response = await this.workspaceService.createView(workspaceSlug, data);
runInAction(() => {
set(this.globalViewMap, response.id, response);
});
async createGlobalView(workspaceSlug: string, data: Partial<IWorkspaceView>) {
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<IWorkspaceView>
): Promise<IWorkspaceView | undefined> => {
): Promise<IWorkspaceView | undefined> {
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);
});
}
};
}

View File

@ -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<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 {
@ -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<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));
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<IProjectView>
*/
updateView = async (
async updateView(
workspaceSlug: string,
projectId: string,
viewId: string,
data: Partial<IProjectView>
): Promise<IProjectView> => {
): Promise<IProjectView> {
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<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,
} 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";

View File

@ -1,2 +1,2 @@
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 "ce/services/project/view.service";