fix: removing the issue from the issue root store while we are deleting from the issue bulk delete modal (#3470)

This commit is contained in:
guru_sainath 2024-01-25 16:37:59 +05:30 committed by GitHub
parent ec3cad1f25
commit c1c2a6ddce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 8 deletions

View File

@ -17,9 +17,11 @@ import { IUser, TIssue } from "@plane/types";
// fetch keys // fetch keys
import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; import { PROJECT_ISSUES_LIST } from "constants/fetch-keys";
// store hooks // store hooks
import { useProject } from "hooks/store"; import { useIssues, useProject } from "hooks/store";
// components // components
import { BulkDeleteIssuesModalItem } from "./bulk-delete-issues-modal-item"; import { BulkDeleteIssuesModalItem } from "./bulk-delete-issues-modal-item";
// constants
import { EIssuesStoreType } from "constants/issue";
type FormInput = { type FormInput = {
delete_issue_ids: string[]; delete_issue_ids: string[];
@ -40,6 +42,9 @@ export const BulkDeleteIssuesModal: React.FC<Props> = observer((props) => {
const { workspaceSlug, projectId } = router.query; const { workspaceSlug, projectId } = router.query;
// hooks // hooks
const { getProjectById } = useProject(); const { getProjectById } = useProject();
const {
issues: { removeBulkIssues },
} = useIssues(EIssuesStoreType.PROJECT);
// states // states
const [query, setQuery] = useState(""); const [query, setQuery] = useState("");
// fetching project issues. // fetching project issues.
@ -82,17 +87,13 @@ export const BulkDeleteIssuesModal: React.FC<Props> = observer((props) => {
if (!Array.isArray(data.delete_issue_ids)) data.delete_issue_ids = [data.delete_issue_ids]; if (!Array.isArray(data.delete_issue_ids)) data.delete_issue_ids = [data.delete_issue_ids];
await issueService await removeBulkIssues(workspaceSlug as string, projectId as string, data.delete_issue_ids)
.bulkDeleteIssues(workspaceSlug as string, projectId as string, {
issue_ids: data.delete_issue_ids,
})
.then(() => { .then(() => {
setToastAlert({ setToastAlert({
type: "success", type: "success",
title: "Success!", title: "Success!",
message: "Issues deleted successfully!", message: "Issues deleted successfully!",
}); });
handleClose(); handleClose();
}) })
.catch(() => .catch(() =>

View File

@ -24,6 +24,7 @@ export interface IProjectIssues {
updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => Promise<TIssue>; updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<TIssue>) => Promise<TIssue>;
removeIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssue>; removeIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<TIssue>;
quickAddIssue: (workspaceSlug: string, projectId: string, data: TIssue) => Promise<TIssue>; quickAddIssue: (workspaceSlug: string, projectId: string, data: TIssue) => Promise<TIssue>;
removeBulkIssues: (workspaceSlug: string, projectId: string, issueIds: string[]) => Promise<void>;
} }
export class ProjectIssues extends IssueHelperStore implements IProjectIssues { export class ProjectIssues extends IssueHelperStore implements IProjectIssues {
@ -53,6 +54,7 @@ export class ProjectIssues extends IssueHelperStore implements IProjectIssues {
createIssue: action, createIssue: action,
updateIssue: action, updateIssue: action,
removeIssue: action, removeIssue: action,
removeBulkIssues: action,
quickAddIssue: action, quickAddIssue: action,
}); });
// root store // root store
@ -185,4 +187,22 @@ export class ProjectIssues extends IssueHelperStore implements IProjectIssues {
throw error; throw error;
} }
}; };
removeBulkIssues = async (workspaceSlug: string, projectId: string, issueIds: string[]) => {
try {
runInAction(() => {
issueIds.forEach((issueId) => {
pull(this.issues[projectId], issueId);
this.rootStore.issues.removeIssue(issueId);
});
});
const response = await this.issueService.bulkDeleteIssues(workspaceSlug, projectId, { issue_ids: issueIds });
return response;
} catch (error) {
this.fetchIssues(workspaceSlug, projectId, "mutation");
throw error;
}
};
} }

View File

@ -164,8 +164,6 @@ export class WorkspaceIssuesFilter extends IssueFilterHelperStore implements IWo
if (!viewId) throw new Error("View id is required"); if (!viewId) throw new Error("View id is required");
const issueFilters = this.getIssueFilters(viewId); const issueFilters = this.getIssueFilters(viewId);
console.log("issueFilters", issueFilters);
if (!issueFilters || isEmpty(filters)) return; if (!issueFilters || isEmpty(filters)) return;
const _filters = { const _filters = {