Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apiserver/plane/app/views/cycle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ def get_queryset(self):
),
)
)
.annotate(
pending_issues=Count(
"issue_cycle__issue__id",
distinct=True,
filter=Q(
issue_cycle__issue__state__group__in=["backlog", "unstarted", "started"],
issue_cycle__issue__archived_at__isnull=True,
issue_cycle__issue__is_draft=False,
issue_cycle__deleted_at__isnull=True,
),
)
)
.annotate(
status=Case(
When(
Expand Down Expand Up @@ -214,6 +226,7 @@ def list(self, request, slug, project_id):
"is_favorite",
"total_issues",
"completed_issues",
"pending_issues",
"assignee_ids",
"status",
"version",
Expand Down Expand Up @@ -245,6 +258,7 @@ def list(self, request, slug, project_id):
# meta fields
"is_favorite",
"total_issues",
"pending_issues",
"completed_issues",
"assignee_ids",
"status",
Expand Down
5 changes: 2 additions & 3 deletions packages/types/src/cycle/cycle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type TCycleProgress = {

export type TProgressSnapshot = {
total_issues: number;
pending_issues: number;
completed_issues: number;
backlog_issues: number;
started_issues: number;
Expand Down Expand Up @@ -120,9 +121,7 @@ export interface CycleIssueResponse {
sub_issues_count: number;
}

export type SelectCycleType =
| (ICycle & { actionType: "edit" | "delete" | "create-issue" })
| undefined;
export type SelectCycleType = (ICycle & { actionType: "edit" | "delete" | "create-issue" }) | undefined;

export type CycleDateCheckData = {
start_date: string;
Expand Down
2 changes: 1 addition & 1 deletion web/ce/components/cycles/end-cycle/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Props {
cycleId: string;
projectId: string;
workspaceSlug: string;
transferrableIssuesCount: number;
pendingIssues: number;
}

export const EndCycleModal: React.FC<Props> = () => <></>;
5 changes: 2 additions & 3 deletions web/core/components/cycles/list/cycle-list-item-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ export const CycleListItemAction: FC<Props> = observer((props) => {
// derived values
const cycleStatus = cycleDetails.status ? (cycleDetails.status.toLocaleLowerCase() as TCycleGroups) : "draft";
const showIssueCount = useMemo(() => cycleStatus === "draft" || cycleStatus === "upcoming", [cycleStatus]);
const transferableIssuesCount = cycleDetails ? cycleDetails.total_issues - cycleDetails.completed_issues : 0;
const showTransferIssues = transferableIssuesCount > 0 && cycleStatus === "completed";
const showTransferIssues = cycleDetails.pending_issues > 0 && cycleStatus === "completed";
const isEditingAllowed = allowPermissions(
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
EUserPermissionsLevel.PROJECT,
Expand Down Expand Up @@ -254,7 +253,7 @@ export const CycleListItemAction: FC<Props> = observer((props) => {
}}
>
<TransferIcon className="fill-custom-primary-200 w-4" />
<span>Transfer {transferableIssuesCount} issues</span>
<span>Transfer {cycleDetails.pending_issues} issues</span>
</div>
)}

Expand Down
3 changes: 1 addition & 2 deletions web/core/components/cycles/quick-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const CycleQuickActions: React.FC<Props> = observer((props) => {
const isArchived = !!cycleDetails?.archived_at;
const isCompleted = cycleDetails?.status?.toLowerCase() === "completed";
const isCurrentCycle = cycleDetails?.status?.toLowerCase() === "current";
const transferableIssuesCount = cycleDetails ? cycleDetails.total_issues - cycleDetails.completed_issues : 0;
// auth
const isEditingAllowed = allowPermissions(
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
Expand Down Expand Up @@ -176,7 +175,7 @@ export const CycleQuickActions: React.FC<Props> = observer((props) => {
cycleId={cycleId}
projectId={projectId}
workspaceSlug={workspaceSlug}
transferrableIssuesCount={transferableIssuesCount}
pendingIssues={cycleDetails.pending_issues}
/>
</div>
)}
Expand Down
8 changes: 8 additions & 0 deletions web/core/store/issue/cycle/issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ export class CycleIssues extends BaseIssuesStore implements ICycleIssues {
cycleId as string,
payload
);
// update pending count
runInAction(() => {
if (this.rootIssueStore.cycleMap)
set(this.rootIssueStore.cycleMap[cycleId], "pending_issues", {
...this.rootIssueStore.cycleMap[cycleId],
pending_issues: 0,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify the object structure and improve type safety.

The current implementation has a few issues that could be improved:

  1. The object spread is redundant as you're setting a new value directly.
  2. The type safety could be improved with proper null checks.
  3. Error handling could be added for edge cases.

Here's the suggested implementation:

    // update pending count
    runInAction(() => {
-      if (this.rootIssueStore.cycleMap)
-        set(this.rootIssueStore.cycleMap[cycleId], "pending_issues", {
-          ...this.rootIssueStore.cycleMap[cycleId],
-          pending_issues: 0,
-        });
+      try {
+        const cycleMap = this.rootIssueStore.cycleMap;
+        if (!cycleMap?.[cycleId]) return;
+        
+        set(cycleMap, [cycleId, "pending_issues"], 0);
+      } catch (error) {
+        console.error("Failed to update pending issues count:", error);
+      }
    });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// update pending count
runInAction(() => {
if (this.rootIssueStore.cycleMap)
set(this.rootIssueStore.cycleMap[cycleId], "pending_issues", {
...this.rootIssueStore.cycleMap[cycleId],
pending_issues: 0,
});
});
// update pending count
runInAction(() => {
try {
const cycleMap = this.rootIssueStore.cycleMap;
if (!cycleMap?.[cycleId]) return;
set(cycleMap, [cycleId, "pending_issues"], 0);
} catch (error) {
console.error("Failed to update pending issues count:", error);
}
});

// call fetch issues
if (this.paginationOptions) {
await persistence.syncIssues(projectId.toString());
Expand Down