From d021a5696a13fa25d0f52cff9cd4c24057e71c82 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Tue, 25 Apr 2023 19:00:20 +0530 Subject: [PATCH] fix: sub issues list fix (#960) --- .../app/components/issues/sub-issues-list.tsx | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/apps/app/components/issues/sub-issues-list.tsx b/apps/app/components/issues/sub-issues-list.tsx index 456140158..d4a5dd4b3 100644 --- a/apps/app/components/issues/sub-issues-list.tsx +++ b/apps/app/components/issues/sub-issues-list.tsx @@ -57,22 +57,6 @@ export const SubIssuesList: FC = ({ parentIssue }) => { : null ); - const updateSubIssuesState = (data: IIssue[]) => { - const backlogCount = data.filter((i) => i.state_detail.group === "backlog").length; - const unstartedCount = data.filter((i) => i.state_detail.group === "unstarted").length; - const startedCount = data.filter((i) => i.state_detail.group === "started").length; - const completedCount = data.filter((i) => i.state_detail.group === "completed").length; - const cancelledCount = data.filter((i) => i.state_detail.group === "cancelled").length; - - return { - backlog: backlogCount ?? 0, - unstarted: unstartedCount ?? 0, - started: startedCount ?? 0, - completed: completedCount ?? 0, - cancelled: cancelledCount ?? 0, - }; - }; - const addAsSubIssue = async (data: { issues: string[] }) => { if (!workspaceSlug || !projectId) return; @@ -86,13 +70,21 @@ export const SubIssuesList: FC = ({ parentIssue }) => { (prevData) => { if (!prevData) return prevData; let newSubIssues = prevData.sub_issues as IIssue[]; + + const stateDistribution = { ...prevData.state_distribution }; + data.issues.forEach((issueId: string) => { const issue = issues?.find((i) => i.id === issueId); - if (issue) newSubIssues.push(issue); + if (issue) { + newSubIssues.push(issue); + const issueGroup = issue.state_detail.group; + stateDistribution[issueGroup] = stateDistribution[issueGroup] + 1; + } }); + newSubIssues = orderArrayBy(newSubIssues, "created_at", "descending"); return { - state_distribution: updateSubIssuesState(newSubIssues), + state_distribution: stateDistribution, sub_issues: newSubIssues, }; }, @@ -129,8 +121,12 @@ export const SubIssuesList: FC = ({ parentIssue }) => { (prevData) => { if (!prevData) return prevData; const updatedArray = (prevData.sub_issues ?? []).filter((i) => i.id !== issueId); + + const stateDistribution = { ...prevData.state_distribution }; + const issueGroup = issues?.find((i) => i.id === issueId)?.state_detail.group ?? "backlog"; + stateDistribution[issueGroup] = stateDistribution[issueGroup] - 1; return { - state_distribution: updateSubIssuesState(updatedArray), + state_distribution: stateDistribution, sub_issues: updatedArray, }; }, @@ -222,7 +218,7 @@ export const SubIssuesList: FC = ({ parentIssue }) => { {subIssuesResponse.state_distribution && ( -
+
= ({ parentIssue }) => { }} />
- + {isNaN(completionPercentage) ? 0 : completionPercentage > 100