From ac6fae44e808e14d6206e6a691a079d92722eaac Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:27:21 +0530 Subject: [PATCH] chore: toggle sub issue view and sub issue count in sub issues (#1312) --- apiserver/plane/api/views/issue.py | 10 +++++++++- apiserver/plane/utils/issue_filters.py | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index f5471dc6c..cd9f65e48 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -259,7 +259,9 @@ class UserWorkSpaceIssues(BaseAPIView): def get(self, request, slug): try: issues = ( - Issue.issue_objects.filter(assignees__in=[request.user], workspace__slug=slug) + Issue.issue_objects.filter( + assignees__in=[request.user], workspace__slug=slug + ) .annotate( sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("id")) .order_by() @@ -582,6 +584,12 @@ class SubIssuesEndpoint(BaseAPIView): .select_related("parent") .prefetch_related("assignees") .prefetch_related("labels") + .annotate( + sub_issues_count=Issue.issue_objects.filter(parent=OuterRef("id")) + .order_by() + .annotate(count=Func(F("id"), function="Count")) + .values("count") + ) ) state_distribution = ( diff --git a/apiserver/plane/utils/issue_filters.py b/apiserver/plane/utils/issue_filters.py index c5f147ea1..f348f642a 100644 --- a/apiserver/plane/utils/issue_filters.py +++ b/apiserver/plane/utils/issue_filters.py @@ -242,6 +242,18 @@ def filter_inbox_status(params, filter, method): return filter +def filter_sub_issue_toggle(params, filter, method): + if method == "GET": + sub_issue = params.get("sub_issue", "false") + if sub_issue == "false": + filter["parent__isnull"] = True + else: + sub_issue = params.get("sub_issue", "false") + if sub_issue == "false": + filter["parent__isnull"] = True + return filter + + def issue_filters(query_params, method): filter = dict() @@ -263,7 +275,8 @@ def issue_filters(query_params, method): "project": filter_project, "cycle": filter_cycle, "module": filter_module, - "inbox_status": filter_inbox_status + "inbox_status": filter_inbox_status, + "sub_issue": filter_sub_issue_toggle, } for key, value in ISSUE_FILTER.items():