Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 12 additions & 3 deletions apps/api/plane/app/views/project/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Django imports
from django.core.serializers.json import DjangoJSONEncoder
from django.db.models import Exists, F, OuterRef, Prefetch, Q, Subquery
from django.db.models import Exists, F, OuterRef, Prefetch, Q, Subquery, Count
from django.utils import timezone

# Third Party imports
Expand All @@ -24,18 +24,17 @@
from plane.db.models import (
UserFavorite,
DeployBoard,
ProjectUserProperty,
Intake,
Project,
ProjectIdentifier,
ProjectMember,
ProjectNetwork,
State,
DEFAULT_STATES,
UserFavorite,
Workspace,
WorkspaceMember,
)
from plane.db.models.intake import IntakeIssueStatus
from plane.utils.host import base_host


Expand Down Expand Up @@ -153,6 +152,15 @@ def list(self, request, slug):
is_active=True,
).values("role")
)
.annotate(
intake_count=Count(
"project_intakeissue",
filter=Q(
project_intakeissue__status=IntakeIssueStatus.PENDING.value,
project_intakeissue__deleted_at__isnull=True,
),
)
)
.annotate(inbox_view=F("intake_view"))
.annotate(sort_order=Subquery(sort_order))
.distinct()
Expand All @@ -163,6 +171,7 @@ def list(self, request, slug):
"sort_order",
"logo_props",
"member_role",
"intake_count",
"archived_at",
"workspace",
"cycle_view",
Expand Down
13 changes: 10 additions & 3 deletions apps/web/core/components/workspace/sidebar/project-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,19 @@ export const ProjectNavigation = observer(function ProjectNavigation(props: TPro
const hasAccess = allowPermissions(item.access, EUserPermissionsLevel.PROJECT, workspaceSlug, project.id);
if (!hasAccess) return null;

const shouldShowCount = item.key === "intake" && (project.intake_count ?? 0) > 0;

return (
<Link key={item.key} href={item.href} onClick={handleProjectClick}>
<SidebarNavItem isActive={!!isActive(item)}>
<div className="flex items-center gap-1.5 py-[1px]">
<item.icon className={`flex-shrink-0 size-4 ${item.name === "Intake" ? "stroke-1" : "stroke-[1.5]"}`} />
<span className="text-11 font-medium">{t(item.i18n_key)}</span>
<div className="flex items-center justify-between gap-1.5 py-[1px] w-full">
<div className="flex items-center gap-1.5">
<item.icon
className={`flex-shrink-0 size-4 ${item.name === "Intake" ? "stroke-1" : "stroke-[1.5]"}`}
/>
<span className="text-11 font-medium">{t(item.i18n_key)}</span>
</div>
{shouldShowCount && <span className="text-11 font-medium text-tertiary">{project.intake_count}</span>}
</div>
</SidebarNavItem>
</Link>
Expand Down
43 changes: 42 additions & 1 deletion apps/web/core/store/inbox/inbox-issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,32 @@ export class InboxIssueStore implements IInboxIssueStore {
const previousData: Partial<TInboxIssue> = {
status: this.status,
};
const previousStatus = this.status;

try {
if (!this.issue.id) return;

const inboxIssue = await this.inboxIssueService.update(this.workspaceSlug, this.projectId, this.issue.id, {
status: status,
});
runInAction(() => set(this, "status", inboxIssue?.status));
runInAction(() => {
set(this, "status", inboxIssue?.status);

// Handle intake_count transitions
if (previousStatus === EInboxIssueStatus.PENDING && inboxIssue.status !== EInboxIssueStatus.PENDING) {
// Changed from PENDING to something else: decrement
const currentCount = this.store.projectRoot.project.projectMap[this.projectId]?.intake_count ?? 0;
set(
this.store.projectRoot.project.projectMap,
[this.projectId, "intake_count"],
Math.max(0, currentCount - 1)
);
} else if (previousStatus !== EInboxIssueStatus.PENDING && inboxIssue.status === EInboxIssueStatus.PENDING) {
// Changed from something else to PENDING: increment
const currentCount = this.store.projectRoot.project.projectMap[this.projectId]?.intake_count ?? 0;
set(this.store.projectRoot.project.projectMap, [this.projectId, "intake_count"], currentCount + 1);
}
});

// If issue accepted sync issue to local db
if (status === EInboxIssueStatus.ACCEPTED) {
Expand All @@ -120,6 +138,7 @@ export class InboxIssueStore implements IInboxIssueStore {
duplicate_to: this.duplicate_to,
duplicate_issue_detail: this.duplicate_issue_detail,
};
const wasPending = this.status === EInboxIssueStatus.PENDING;
try {
if (!this.issue.id) return;
const inboxIssue = await this.inboxIssueService.update(this.workspaceSlug, this.projectId, this.issue.id, {
Expand All @@ -130,6 +149,15 @@ export class InboxIssueStore implements IInboxIssueStore {
set(this, "status", inboxIssue?.status);
set(this, "duplicate_to", inboxIssue?.duplicate_to);
set(this, "duplicate_issue_detail", inboxIssue?.duplicate_issue_detail);
// Decrement intake_count if the issue was PENDING
if (wasPending) {
const currentCount = this.store.projectRoot.project.projectMap[this.projectId]?.intake_count ?? 0;
set(
this.store.projectRoot.project.projectMap,
[this.projectId, "intake_count"],
Math.max(0, currentCount - 1)
);
}
});
} catch {
runInAction(() => {
Expand All @@ -146,6 +174,7 @@ export class InboxIssueStore implements IInboxIssueStore {
status: this.status,
snoozed_till: this.snoozed_till,
};
const previousStatus = this.status;
try {
if (!this.issue.id) return;
const inboxIssue = await this.inboxIssueService.update(this.workspaceSlug, this.projectId, this.issue.id, {
Expand All @@ -155,6 +184,18 @@ export class InboxIssueStore implements IInboxIssueStore {
runInAction(() => {
set(this, "status", inboxIssue?.status);
set(this, "snoozed_till", inboxIssue?.snoozed_till);
// Handle intake_count transitions
if (previousStatus === EInboxIssueStatus.PENDING && inboxIssue.status === EInboxIssueStatus.SNOOZED) {
const currentCount = this.store.projectRoot.project.projectMap[this.projectId]?.intake_count ?? 0;
set(
this.store.projectRoot.project.projectMap,
[this.projectId, "intake_count"],
Math.max(0, currentCount - 1)
);
} else if (previousStatus !== EInboxIssueStatus.PENDING && inboxIssue.status === EInboxIssueStatus.PENDING) {
const currentCount = this.store.projectRoot.project.projectMap[this.projectId]?.intake_count ?? 0;
set(this.store.projectRoot.project.projectMap, [this.projectId, "intake_count"], currentCount + 1);
}
});
} catch {
runInAction(() => {
Expand Down
11 changes: 11 additions & 0 deletions apps/web/core/store/inbox/project-inbox.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ export class ProjectInboxStore implements IProjectInboxStore {
["inboxIssuePaginationInfo", "total_results"],
(this.inboxIssuePaginationInfo?.total_results || 0) + 1
);
// Increment intake_count if the new issue is PENDING
if (inboxIssueResponse.status === EInboxIssueStatus.PENDING) {
const currentCount = this.store.projectRoot.project.projectMap[projectId]?.intake_count ?? 0;
set(this.store.projectRoot.project.projectMap, [projectId, "intake_count"], currentCount + 1);
}
});
return inboxIssueResponse;
} catch (error) {
Expand All @@ -483,6 +488,7 @@ export class ProjectInboxStore implements IProjectInboxStore {
*/
deleteInboxIssue = async (workspaceSlug: string, projectId: string, inboxIssueId: string) => {
const currentIssue = this.inboxIssues?.[inboxIssueId];
const wasPending = currentIssue?.status === EInboxIssueStatus.PENDING;
try {
if (!currentIssue) return;
await this.inboxIssueService.destroy(workspaceSlug, projectId, inboxIssueId).then(() => {
Expand All @@ -498,6 +504,11 @@ export class ProjectInboxStore implements IProjectInboxStore {
["inboxIssueIds"],
this.inboxIssueIds.filter((id) => id !== inboxIssueId)
);
// Decrement intake_count if the deleted issue was PENDING
if (wasPending) {
const currentCount = this.store.projectRoot.project.projectMap[projectId]?.intake_count ?? 0;
set(this.store.projectRoot.project.projectMap, [projectId, "intake_count"], Math.max(0, currentCount - 1));
}
});
});
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/project/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface IPartialProject {
// actor
created_by?: string;
updated_by?: string;
intake_count?: number;
}

export interface IProject extends IPartialProject {
Expand Down
Loading