forked from github/plane
fix: issue spillover on switching workspace (#3652)
* fix global issues spillover to other workspace * fix the same for profile issues as well
This commit is contained in:
parent
5b5698ad97
commit
571b89632c
@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
@ -36,10 +36,14 @@ export const ProfileIssuesPage = observer((props: IProfileIssuesPage) => {
|
|||||||
currentUser,
|
currentUser,
|
||||||
} = useUser();
|
} = useUser();
|
||||||
const {
|
const {
|
||||||
issues: { loader, groupedIssueIds, fetchIssues },
|
issues: { loader, groupedIssueIds, fetchIssues, setViewId },
|
||||||
issuesFilter: { issueFilters, fetchFilters },
|
issuesFilter: { issueFilters, fetchFilters },
|
||||||
} = useIssues(EIssuesStoreType.PROFILE);
|
} = useIssues(EIssuesStoreType.PROFILE);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setViewId(type);
|
||||||
|
}, [type]);
|
||||||
|
|
||||||
useSWR(
|
useSWR(
|
||||||
workspaceSlug && userId ? `CURRENT_WORKSPACE_PROFILE_ISSUES_${workspaceSlug}_${userId}_${type}` : null,
|
workspaceSlug && userId ? `CURRENT_WORKSPACE_PROFILE_ISSUES_${workspaceSlug}_${userId}_${type}` : null,
|
||||||
async () => {
|
async () => {
|
||||||
|
@ -9,9 +9,7 @@ import { IIssueRootStore } from "../root.store";
|
|||||||
import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types";
|
import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types";
|
||||||
|
|
||||||
interface IProfileIssueTabTypes {
|
interface IProfileIssueTabTypes {
|
||||||
assigned: string[];
|
[key: string]: string[];
|
||||||
created: string[];
|
|
||||||
subscribed: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IProfileIssues {
|
export interface IProfileIssues {
|
||||||
@ -23,6 +21,7 @@ export interface IProfileIssues {
|
|||||||
groupedIssueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined;
|
groupedIssueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined;
|
||||||
viewFlags: ViewFlags;
|
viewFlags: ViewFlags;
|
||||||
// actions
|
// actions
|
||||||
|
setViewId: (viewId: "assigned" | "created" | "subscribed") => void;
|
||||||
fetchIssues: (
|
fetchIssues: (
|
||||||
workspaceSlug: string,
|
workspaceSlug: string,
|
||||||
projectId: string | undefined,
|
projectId: string | undefined,
|
||||||
@ -73,6 +72,7 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
|
|||||||
groupedIssueIds: computed,
|
groupedIssueIds: computed,
|
||||||
viewFlags: computed,
|
viewFlags: computed,
|
||||||
// action
|
// action
|
||||||
|
setViewId: action.bound,
|
||||||
fetchIssues: action,
|
fetchIssues: action,
|
||||||
createIssue: action,
|
createIssue: action,
|
||||||
updateIssue: action,
|
updateIssue: action,
|
||||||
@ -86,8 +86,11 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
|
|||||||
|
|
||||||
get groupedIssueIds() {
|
get groupedIssueIds() {
|
||||||
const userId = this.rootIssueStore.userId;
|
const userId = this.rootIssueStore.userId;
|
||||||
|
const workspaceSlug = this.rootIssueStore.workspaceSlug;
|
||||||
const currentView = this.currentView;
|
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;
|
const displayFilters = this.rootIssueStore?.profileIssuesFilter?.issueFilters?.displayFilters;
|
||||||
if (!displayFilters) return undefined;
|
if (!displayFilters) return undefined;
|
||||||
@ -97,12 +100,12 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
|
|||||||
const orderBy = displayFilters?.order_by;
|
const orderBy = displayFilters?.order_by;
|
||||||
const layout = displayFilters?.layout;
|
const layout = displayFilters?.layout;
|
||||||
|
|
||||||
const userIssueIds = this.issues[userId]?.[currentView];
|
const userIssueIds = this.issues[userId]?.[uniqueViewId];
|
||||||
|
|
||||||
if (!userIssueIds) return;
|
if (!userIssueIds) return;
|
||||||
|
|
||||||
const _issues = this.rootStore.issues.getIssuesByIds(userIssueIds);
|
const _issues = this.rootStore.issues.getIssuesByIds(userIssueIds);
|
||||||
if (!_issues) return undefined;
|
if (!_issues) return [];
|
||||||
|
|
||||||
let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues | undefined = undefined;
|
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 (
|
fetchIssues = async (
|
||||||
workspaceSlug: string,
|
workspaceSlug: string,
|
||||||
projectId: string | undefined,
|
projectId: string | undefined,
|
||||||
@ -145,6 +152,8 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
|
|||||||
this.loader = loadType;
|
this.loader = loadType;
|
||||||
this.currentView = view;
|
this.currentView = view;
|
||||||
|
|
||||||
|
const uniqueViewId = `${workspaceSlug}_${view}`;
|
||||||
|
|
||||||
let params: any = this.rootIssueStore?.profileIssuesFilter?.appliedFilters;
|
let params: any = this.rootIssueStore?.profileIssuesFilter?.appliedFilters;
|
||||||
params = {
|
params = {
|
||||||
...params,
|
...params,
|
||||||
@ -161,7 +170,7 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
|
|||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
set(
|
set(
|
||||||
this.issues,
|
this.issues,
|
||||||
[userId, view],
|
[userId, uniqueViewId],
|
||||||
response.map((issue) => issue.id)
|
response.map((issue) => issue.id)
|
||||||
);
|
);
|
||||||
this.loader = undefined;
|
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 response = await this.rootIssueStore.projectIssues.createIssue(workspaceSlug, projectId, data);
|
||||||
|
|
||||||
|
const uniqueViewId = `${workspaceSlug}_${this.currentView}`;
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.issues[userId][this.currentView].push(response.id);
|
this.issues[userId][uniqueViewId].push(response.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.rootStore.issues.addIssue([response]);
|
this.rootStore.issues.addIssue([response]);
|
||||||
@ -234,10 +245,12 @@ export class ProfileIssues extends IssueHelperStore implements IProfileIssues {
|
|||||||
try {
|
try {
|
||||||
const response = await this.rootIssueStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId);
|
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)
|
if (issueIndex >= 0)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.issues[userId][this.currentView].splice(issueIndex, 1);
|
this.issues[userId][uniqueViewId].splice(issueIndex, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -77,14 +77,17 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue
|
|||||||
|
|
||||||
get groupedIssueIds() {
|
get groupedIssueIds() {
|
||||||
const viewId = this.rootIssueStore.globalViewId;
|
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;
|
const displayFilters = this.rootIssueStore?.workspaceIssuesFilter?.filters?.[viewId]?.displayFilters;
|
||||||
if (!displayFilters) return { dataViewId: viewId, issueIds: undefined };
|
if (!displayFilters) return { dataViewId: viewId, issueIds: undefined };
|
||||||
|
|
||||||
const orderBy = displayFilters?.order_by;
|
const orderBy = displayFilters?.order_by;
|
||||||
|
|
||||||
const viewIssueIds = this.issues[viewId];
|
const viewIssueIds = this.issues[uniqueViewId];
|
||||||
|
|
||||||
if (!viewIssueIds) return { dataViewId: viewId, issueIds: undefined };
|
if (!viewIssueIds) return { dataViewId: viewId, issueIds: undefined };
|
||||||
|
|
||||||
@ -102,13 +105,15 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue
|
|||||||
try {
|
try {
|
||||||
this.loader = loadType;
|
this.loader = loadType;
|
||||||
|
|
||||||
|
const uniqueViewId = `${workspaceSlug}_${viewId}`;
|
||||||
|
|
||||||
const params = this.rootIssueStore?.workspaceIssuesFilter?.getAppliedFilters(viewId);
|
const params = this.rootIssueStore?.workspaceIssuesFilter?.getAppliedFilters(viewId);
|
||||||
const response = await this.workspaceService.getViewIssues(workspaceSlug, params);
|
const response = await this.workspaceService.getViewIssues(workspaceSlug, params);
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
set(
|
set(
|
||||||
this.issues,
|
this.issues,
|
||||||
[viewId],
|
[uniqueViewId],
|
||||||
response.map((issue) => issue.id)
|
response.map((issue) => issue.id)
|
||||||
);
|
);
|
||||||
this.loader = undefined;
|
this.loader = undefined;
|
||||||
@ -133,10 +138,12 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue
|
|||||||
try {
|
try {
|
||||||
if (!viewId) throw new Error("View id is required");
|
if (!viewId) throw new Error("View id is required");
|
||||||
|
|
||||||
|
const uniqueViewId = `${workspaceSlug}_${viewId}`;
|
||||||
|
|
||||||
const response = await this.issueService.createIssue(workspaceSlug, projectId, data);
|
const response = await this.issueService.createIssue(workspaceSlug, projectId, data);
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.issues[viewId].push(response.id);
|
this.issues[uniqueViewId].push(response.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.rootStore.issues.addIssue([response]);
|
this.rootStore.issues.addIssue([response]);
|
||||||
@ -175,12 +182,14 @@ export class WorkspaceIssues extends IssueHelperStore implements IWorkspaceIssue
|
|||||||
try {
|
try {
|
||||||
if (!viewId) throw new Error("View id is required");
|
if (!viewId) throw new Error("View id is required");
|
||||||
|
|
||||||
|
const uniqueViewId = `${workspaceSlug}_${viewId}`;
|
||||||
|
|
||||||
const response = await this.issueService.deleteIssue(workspaceSlug, projectId, issueId);
|
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)
|
if (issueIndex >= 0)
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.issues[viewId].splice(issueIndex, 1);
|
this.issues[uniqueViewId].splice(issueIndex, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.rootStore.issues.removeIssue(issueId);
|
this.rootStore.issues.removeIssue(issueId);
|
||||||
|
Loading…
Reference in New Issue
Block a user