diff --git a/web/components/profile/profile-issues.tsx b/web/components/profile/profile-issues.tsx index 8b11ca518..e7b61b4d2 100644 --- a/web/components/profile/profile-issues.tsx +++ b/web/components/profile/profile-issues.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; import { observer } from "mobx-react-lite"; @@ -36,10 +36,14 @@ export const ProfileIssuesPage = observer((props: IProfileIssuesPage) => { currentUser, } = useUser(); const { - issues: { loader, groupedIssueIds, fetchIssues }, + issues: { loader, groupedIssueIds, fetchIssues, setViewId }, issuesFilter: { issueFilters, fetchFilters }, } = useIssues(EIssuesStoreType.PROFILE); + useEffect(() => { + setViewId(type); + }, [type]); + useSWR( workspaceSlug && userId ? `CURRENT_WORKSPACE_PROFILE_ISSUES_${workspaceSlug}_${userId}_${type}` : null, async () => { diff --git a/web/store/issue/profile/issue.store.ts b/web/store/issue/profile/issue.store.ts index e754758cc..5cde37230 100644 --- a/web/store/issue/profile/issue.store.ts +++ b/web/store/issue/profile/issue.store.ts @@ -9,9 +9,7 @@ import { IIssueRootStore } from "../root.store"; import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types"; interface IProfileIssueTabTypes { - assigned: string[]; - created: string[]; - subscribed: string[]; + [key: string]: string[]; } export interface IProfileIssues { @@ -23,6 +21,7 @@ export interface IProfileIssues { groupedIssueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined; viewFlags: ViewFlags; // actions + setViewId: (viewId: "assigned" | "created" | "subscribed") => void; fetchIssues: ( workspaceSlug: string, projectId: string | undefined, @@ -73,6 +72,7 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { groupedIssueIds: computed, viewFlags: computed, // action + setViewId: action.bound, fetchIssues: action, createIssue: action, updateIssue: action, @@ -86,8 +86,11 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { get groupedIssueIds() { const userId = this.rootIssueStore.userId; + const workspaceSlug = this.rootIssueStore.workspaceSlug; const currentView = this.currentView; - if (!userId || !currentView) return undefined; + if (!userId || !currentView || !workspaceSlug) return undefined; + + const uniqueViewId = `${workspaceSlug}_${currentView}`; const displayFilters = this.rootIssueStore?.profileIssuesFilter?.issueFilters?.displayFilters; if (!displayFilters) return undefined; @@ -97,12 +100,12 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { const orderBy = displayFilters?.order_by; const layout = displayFilters?.layout; - const userIssueIds = this.issues[userId]?.[currentView]; + const userIssueIds = this.issues[userId]?.[uniqueViewId]; if (!userIssueIds) return; const _issues = this.rootStore.issues.getIssuesByIds(userIssueIds); - if (!_issues) return undefined; + if (!_issues) return []; let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined = undefined; @@ -131,6 +134,10 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { }; } + setViewId(viewId: "assigned" | "created" | "subscribed") { + this.currentView = viewId; + } + fetchIssues = async ( workspaceSlug: string, projectId: string | undefined, @@ -145,6 +152,8 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { this.loader = loadType; this.currentView = view; + const uniqueViewId = `${workspaceSlug}_${view}`; + let params: any = this.rootIssueStore?.profileIssuesFilter?.appliedFilters; params = { ...params, @@ -161,7 +170,7 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { runInAction(() => { set( this.issues, - [userId, view], + [userId, uniqueViewId], response.map((issue) => issue.id) ); this.loader = undefined; @@ -187,8 +196,10 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { const response = await this.rootIssueStore.projectIssues.createIssue(workspaceSlug, projectId, data); + const uniqueViewId = `${workspaceSlug}_${this.currentView}`; + runInAction(() => { - this.issues[userId][this.currentView].push(response.id); + this.issues[userId][uniqueViewId].push(response.id); }); this.rootStore.issues.addIssue([response]); @@ -234,10 +245,12 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues { try { const response = await this.rootIssueStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId); - const issueIndex = this.issues[userId][this.currentView].findIndex((_issueId) => _issueId === issueId); + const uniqueViewId = `${workspaceSlug}_${this.currentView}`; + + const issueIndex = this.issues[userId][uniqueViewId].findIndex((_issueId) => _issueId === issueId); if (issueIndex >= 0) runInAction(() => { - this.issues[userId][this.currentView].splice(issueIndex, 1); + this.issues[userId][uniqueViewId].splice(issueIndex, 1); }); return response; diff --git a/web/store/issue/workspace/issue.store.ts b/web/store/issue/workspace/issue.store.ts index 7e317e5b4..e168f85c2 100644 --- a/web/store/issue/workspace/issue.store.ts +++ b/web/store/issue/workspace/issue.store.ts @@ -77,14 +77,17 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue get groupedIssueIds() { const viewId = this.rootIssueStore.globalViewId; - if (!viewId) return { dataViewId: "", issueIds: undefined }; + const workspaceSlug = this.rootIssueStore.workspaceSlug; + if (!workspaceSlug || !viewId) return { dataViewId: "", issueIds: undefined }; + + const uniqueViewId = `${workspaceSlug}_${viewId}`; const displayFilters = this.rootIssueStore?.workspaceIssuesFilter?.filters?.[viewId]?.displayFilters; if (!displayFilters) return { dataViewId: viewId, issueIds: undefined }; const orderBy = displayFilters?.order_by; - const viewIssueIds = this.issues[viewId]; + const viewIssueIds = this.issues[uniqueViewId]; if (!viewIssueIds) return { dataViewId: viewId, issueIds: undefined }; @@ -102,13 +105,15 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue try { this.loader = loadType; + const uniqueViewId = `${workspaceSlug}_${viewId}`; + const params = this.rootIssueStore?.workspaceIssuesFilter?.getAppliedFilters(viewId); const response = await this.workspaceService.getViewIssues(workspaceSlug, params); runInAction(() => { set( this.issues, - [viewId], + [uniqueViewId], response.map((issue) => issue.id) ); this.loader = undefined; @@ -133,10 +138,12 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue try { if (!viewId) throw new Error("View id is required"); + const uniqueViewId = `${workspaceSlug}_${viewId}`; + const response = await this.issueService.createIssue(workspaceSlug, projectId, data); runInAction(() => { - this.issues[viewId].push(response.id); + this.issues[uniqueViewId].push(response.id); }); this.rootStore.issues.addIssue([response]); @@ -175,12 +182,14 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue try { if (!viewId) throw new Error("View id is required"); + const uniqueViewId = `${workspaceSlug}_${viewId}`; + const response = await this.issueService.deleteIssue(workspaceSlug, projectId, issueId); - const issueIndex = this.issues[viewId].findIndex((_issueId) => _issueId === issueId); + const issueIndex = this.issues[uniqueViewId].findIndex((_issueId) => _issueId === issueId); if (issueIndex >= 0) runInAction(() => { - this.issues[viewId].splice(issueIndex, 1); + this.issues[uniqueViewId].splice(issueIndex, 1); }); this.rootStore.issues.removeIssue(issueId);