From 4bc04c88ed9655898b7fb0431f42495a9ffc8bd4 Mon Sep 17 00:00:00 2001 From: gakshita Date: Tue, 30 Jul 2024 14:55:59 +0530 Subject: [PATCH 1/2] fix: project issue creation --- web/core/hooks/use-issues-actions.tsx | 6 +++--- .../store/issue/helpers/base-issues.store.ts | 2 +- web/core/store/issue/project/issue.store.ts | 19 ++++++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/web/core/hooks/use-issues-actions.tsx b/web/core/hooks/use-issues-actions.tsx index 482618697b9..430f67d9b55 100644 --- a/web/core/hooks/use-issues-actions.tsx +++ b/web/core/hooks/use-issues-actions.tsx @@ -91,9 +91,9 @@ const useProjectIssueActions = () => { ); const createIssue = useCallback( - async (projectId: string | undefined | null, data: Partial) => { - if (!workspaceSlug || !projectId) return; - return await issues.createIssue(workspaceSlug, projectId, data); + async (issueProjectId: string | undefined | null, data: Partial) => { + if (!workspaceSlug || !issueProjectId) return; + return await issues.createIssue(workspaceSlug, issueProjectId, data, "", issueProjectId === projectId); }, [issues.createIssue, workspaceSlug] ); diff --git a/web/core/store/issue/helpers/base-issues.store.ts b/web/core/store/issue/helpers/base-issues.store.ts index a50d1585f51..c29c8b05e26 100644 --- a/web/core/store/issue/helpers/base-issues.store.ts +++ b/web/core/store/issue/helpers/base-issues.store.ts @@ -520,7 +520,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore { const response = await this.issueService.createIssue(workspaceSlug, projectId, data); // add Issue to Store - this.addIssue(response, shouldUpdateList); + shouldUpdateList && this.addIssue(response, shouldUpdateList); // If shouldUpdateList is true, call fetchParentStats shouldUpdateList && this.fetchParentStats(workspaceSlug, projectId); diff --git a/web/core/store/issue/project/issue.store.ts b/web/core/store/issue/project/issue.store.ts index e1b013e4afc..4b17b214907 100644 --- a/web/core/store/issue/project/issue.store.ts +++ b/web/core/store/issue/project/issue.store.ts @@ -1,6 +1,13 @@ -import { action, makeObservable, runInAction, } from "mobx"; +import { action, makeObservable, runInAction } from "mobx"; // types -import { TIssue, TLoader, ViewFlags, IssuePaginationOptions, TIssuesResponse, TBulkOperationsPayload } from "@plane/types"; +import { + TIssue, + TLoader, + ViewFlags, + IssuePaginationOptions, + TIssuesResponse, + TBulkOperationsPayload, +} from "@plane/types"; // helpers // base class import { BaseIssuesStore, IBaseIssuesStore } from "../helpers/base-issues.store"; @@ -29,7 +36,13 @@ export interface IProjectIssues extends IBaseIssuesStore { subGroupId?: string ) => Promise; - createIssue: (workspaceSlug: string, projectId: string, data: Partial) => Promise; + createIssue: ( + workspaceSlug: string, + projectId: string, + data: Partial, + id?: string | undefined, + shouldUpdateList?: boolean + ) => Promise; updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial) => Promise; archiveIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise; quickAddIssue: (workspaceSlug: string, projectId: string, data: TIssue) => Promise; From ceccdab8961d6e7f768e4b0e20b4b55c0303b078 Mon Sep 17 00:00:00 2001 From: gakshita Date: Wed, 31 Jul 2024 13:23:29 +0530 Subject: [PATCH 2/2] fix: refactored --- web/core/hooks/use-issues-actions.tsx | 6 ++--- .../store/issue/helpers/base-issues.store.ts | 2 +- web/core/store/issue/project/issue.store.ts | 22 +++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/web/core/hooks/use-issues-actions.tsx b/web/core/hooks/use-issues-actions.tsx index 430f67d9b55..482618697b9 100644 --- a/web/core/hooks/use-issues-actions.tsx +++ b/web/core/hooks/use-issues-actions.tsx @@ -91,9 +91,9 @@ const useProjectIssueActions = () => { ); const createIssue = useCallback( - async (issueProjectId: string | undefined | null, data: Partial) => { - if (!workspaceSlug || !issueProjectId) return; - return await issues.createIssue(workspaceSlug, issueProjectId, data, "", issueProjectId === projectId); + async (projectId: string | undefined | null, data: Partial) => { + if (!workspaceSlug || !projectId) return; + return await issues.createIssue(workspaceSlug, projectId, data); }, [issues.createIssue, workspaceSlug] ); diff --git a/web/core/store/issue/helpers/base-issues.store.ts b/web/core/store/issue/helpers/base-issues.store.ts index c29c8b05e26..a50d1585f51 100644 --- a/web/core/store/issue/helpers/base-issues.store.ts +++ b/web/core/store/issue/helpers/base-issues.store.ts @@ -520,7 +520,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore { const response = await this.issueService.createIssue(workspaceSlug, projectId, data); // add Issue to Store - shouldUpdateList && this.addIssue(response, shouldUpdateList); + this.addIssue(response, shouldUpdateList); // If shouldUpdateList is true, call fetchParentStats shouldUpdateList && this.fetchParentStats(workspaceSlug, projectId); diff --git a/web/core/store/issue/project/issue.store.ts b/web/core/store/issue/project/issue.store.ts index 4b17b214907..585f5b53a6e 100644 --- a/web/core/store/issue/project/issue.store.ts +++ b/web/core/store/issue/project/issue.store.ts @@ -36,13 +36,7 @@ export interface IProjectIssues extends IBaseIssuesStore { subGroupId?: string ) => Promise; - createIssue: ( - workspaceSlug: string, - projectId: string, - data: Partial, - id?: string | undefined, - shouldUpdateList?: boolean - ) => Promise; + createIssue: (workspaceSlug: string, projectId: string, data: Partial) => Promise; updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial) => Promise; archiveIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise; quickAddIssue: (workspaceSlug: string, projectId: string, data: TIssue) => Promise; @@ -57,6 +51,7 @@ export class ProjectIssues extends BaseIssuesStore implements IProjectIssues { enableIssueCreation: true, enableInlineEditing: true, }; + router; // filter store issueFilterStore: IProjectIssuesFilter; @@ -72,6 +67,7 @@ export class ProjectIssues extends BaseIssuesStore implements IProjectIssues { }); // filter store this.issueFilterStore = issueFilterStore; + this.router = _rootStore.rootStore.router; } /** @@ -178,6 +174,18 @@ export class ProjectIssues extends BaseIssuesStore implements IProjectIssues { return await this.fetchIssues(workspaceSlug, projectId, loadType, this.paginationOptions, true); }; + /** + * Override inherited create issue, to update list only if user is on current project + * @param workspaceSlug + * @param projectId + * @param data + * @returns + */ + override createIssue = async (workspaceSlug: string, projectId: string, data: Partial) => { + const response = await super.createIssue(workspaceSlug, projectId, data, "", projectId === this.router.projectId); + return response; + }; + // Using aliased names as they cannot be overridden in other stores archiveBulkIssues = this.bulkArchiveIssues; quickAddIssue = this.issueQuickAdd;