Skip to content

Commit 2d12c62

Browse files
oliverb123Twixes
andauthored
fix(inbox): make "Entire project" scope show project-wide reports (#2699)
Co-authored-by: Michael Matloka <michael@matloka.com>
1 parent 4bef76f commit 2d12c62

3 files changed

Lines changed: 34 additions & 18 deletions

File tree

packages/core/src/inbox/reportFiltering.test.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,17 @@ describe("filterReportsBySearch", () => {
9898
});
9999

100100
describe("buildSignalReportListOrdering", () => {
101-
it("puts status then suggested reviewer then descending field", () => {
102-
expect(buildSignalReportListOrdering("total_weight", "desc")).toBe(
103-
"status,-is_suggested_reviewer,-total_weight",
104-
);
105-
});
106-
107-
it("puts status then suggested reviewer then ascending field", () => {
108-
expect(buildSignalReportListOrdering("created_at", "asc")).toBe(
109-
"status,-is_suggested_reviewer,created_at",
110-
);
101+
it.each([
102+
["total_weight", "desc", "status,-total_weight"],
103+
["created_at", "asc", "status,created_at"],
104+
["signal_count", "desc", "status,-signal_count"],
105+
] as const)("orders by status then %s (%s)", (field, direction, expected) => {
106+
expect(buildSignalReportListOrdering(field, direction)).toBe(expected);
111107
});
112108

113-
it("works for signal_count", () => {
114-
expect(buildSignalReportListOrdering("signal_count", "desc")).toBe(
115-
"status,-is_suggested_reviewer,-signal_count",
109+
it("does not float the current user's reports via ordering", () => {
110+
expect(buildSignalReportListOrdering("priority", "asc")).not.toContain(
111+
"is_suggested_reviewer",
116112
);
117113
});
118114
});

packages/core/src/inbox/reportFiltering.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ export function buildStatusFilterParam(statuses: SignalReportStatus[]): string {
5959
/**
6060
* Comma-separated `ordering` for the signal report list API:
6161
* 1. Status rank (ready first – semantic server-side rank, always applied)
62-
* 2. Suggested reviewer (current user's reports first)
63-
* 3. Toolbar-selected field (priority, total_weight, created_at, etc.)
62+
* 2. Toolbar-selected field (priority, total_weight, created_at, etc.)
63+
*
64+
* Reviewer scope is applied via the `suggested_reviewers` param, not ordering:
65+
* a `-is_suggested_reviewer` tiebreak would float the user's reports to the top
66+
* of the first (and only loaded) page, starving the "Entire project" scope.
6467
*/
6568
export function buildSignalReportListOrdering(
6669
field: SignalReportOrderingField,
6770
direction: "asc" | "desc",
6871
): string {
6972
const fieldKey = direction === "desc" ? `-${field}` : field;
70-
return `status,-is_suggested_reviewer,${fieldKey}`;
73+
return `status,${fieldKey}`;
7174
}
7275

7376
export function buildSuggestedReviewerFilterParam(

packages/ui/src/features/inbox/hooks/useInboxAllReports.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import {
88
} from "@posthog/core/inbox/reportFiltering";
99
import {
1010
computeInboxTabCounts,
11+
INBOX_SCOPE_FOR_YOU,
1112
matchesReviewerScope,
1213
parseTeammateInboxScope,
1314
} from "@posthog/core/inbox/reportMembership";
15+
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
16+
import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
1417
import { useInboxReportsInfinite } from "@posthog/ui/features/inbox/hooks/useInboxReports";
1518
import { useInboxReviewerScopeStore } from "@posthog/ui/features/inbox/stores/inboxReviewerScopeStore";
1619
import { useInboxSignalsFilterStore } from "@posthog/ui/features/inbox/stores/inboxSignalsFilterStore";
@@ -52,7 +55,16 @@ export function useInboxAllReports(options?: {
5255
const priorityFilter = useInboxSignalsFilterStore((s) =>
5356
ignoreFilters ? EMPTY_FILTER_ARRAY : s.priorityFilter,
5457
);
58+
const client = useOptionalAuthenticatedClient();
59+
const { data: currentUser } = useCurrentUser({ client });
60+
61+
// Reviewer scope is applied server-side via `suggested_reviewers`: "For you"
62+
// filters on the current user, a teammate scope on theirs, "Entire project"
63+
// and the Runs tab (`ignoreScope`) send nothing.
64+
const isForYou = !ignoreScope && scope === INBOX_SCOPE_FOR_YOU;
5565
const teammateUuid = ignoreScope ? null : parseTeammateInboxScope(scope);
66+
const reviewerUuid =
67+
teammateUuid ?? (isForYou ? (currentUser?.uuid ?? null) : null);
5668

5769
const query = useInboxReportsInfinite(
5870
{
@@ -63,11 +75,16 @@ export function useInboxAllReports(options?: {
6375
? sourceProductFilter.join(",")
6476
: undefined,
6577
priority: buildPriorityFilterParam(priorityFilter),
66-
suggested_reviewers: teammateUuid
67-
? buildSuggestedReviewerFilterParam([teammateUuid])
78+
suggested_reviewers: reviewerUuid
79+
? buildSuggestedReviewerFilterParam([reviewerUuid])
6880
: undefined,
6981
},
7082
{
83+
// "For you" must always carry the current user's `suggested_reviewers`
84+
// filter, so hold the query until that uuid resolves rather than firing a
85+
// throwaway project-wide fetch first. Other scopes don't depend on the
86+
// user and run immediately.
87+
enabled: !isForYou || reviewerUuid != null,
7188
refetchInterval: INBOX_REFETCH_INTERVAL_MS,
7289
refetchIntervalInBackground: false,
7390
},

0 commit comments

Comments
 (0)