Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(desktop): load inbox badge counts in one request (#124393)

Dylan Martind467a42e2260
diff --git a/packages/agent/packages/agent-contracts/src/domain-types.ts b/packages/agent/packages/agent-contracts/src/domain-types.ts
index 03475f3483fa..d0f67c455cf8 100644
--- a/packages/agent/packages/agent-contracts/src/domain-types.ts
+++ b/packages/agent/packages/agent-contracts/src/domain-types.ts
@@ -1182,6 +1182,20 @@ export interface SignalReportsResponse {
count: number;
}
+/** The list filters a section count request shares with the inbox list. */
+export interface SignalReportSectionCountsParams {
+ source_product?: string;
+ priority?: string;
+ suggested_reviewers?: string;
+}
+
+export interface SignalReportSectionCounts {
+ /** Ready reports with an implementation pull request. */
+ pull_requests: number;
+ /** Ready reports without an implementation pull request. */
+ reports: number;
+}
+
export interface SignalProcessingStateResponse {
paused_until: string | null;
}
diff --git a/products/desktop/packages/api-client/src/posthog-client.ts b/products/desktop/packages/api-client/src/posthog-client.ts
index f084966c08a9..d88a36004082 100644
--- a/products/desktop/packages/api-client/src/posthog-client.ts
+++ b/products/desktop/packages/api-client/src/posthog-client.ts
@@ -57,6 +57,8 @@ import type {
SignalReportArtefact,
SignalReportArtefactsResponse,
SignalReportRefundReason,
+ SignalReportSectionCounts,
+ SignalReportSectionCountsParams,
SignalReportSignalsResponse,
SignalReportStatus,
SignalReportsQueryParams,
@@ -5842,6 +5844,29 @@ export class PostHogAPIClient {
};
}
+ async getSignalReportSectionCounts(
+ params?: SignalReportSectionCountsParams,
+ ): Promise<SignalReportSectionCounts> {
+ const teamId = await this.getTeamId();
+ const path = `/api/projects/${teamId}/signals/reports/section_counts/`;
+ const url = new URL(`${this.api.baseUrl}${path}`);
+ if (params?.source_product) {
+ url.searchParams.set("source_product", params.source_product);
+ }
+ if (params?.priority) url.searchParams.set("priority", params.priority);
+ if (params?.suggested_reviewers) {
+ url.searchParams.set("suggested_reviewers", params.suggested_reviewers);
+ }
+
+ const response = await this.api.fetcher.fetch({ method: "get", url, path });
+ if (!response.ok) {
+ throw new Error(
+ `Failed to fetch signal report section counts: ${response.statusText}`,
+ );
+ }
+ return (await response.json()) as SignalReportSectionCounts;
+ }
+
async getSignalProcessingState(): Promise<SignalProcessingStateResponse> {
const teamId = await this.getTeamId();
const url = new URL(
diff --git a/products/desktop/packages/core/src/inbox/inboxQuery.ts b/products/desktop/packages/core/src/inbox/inboxQuery.ts
index bb3187b7c8d4..0db2a6b110d8 100644
--- a/products/desktop/packages/core/src/inbox/inboxQuery.ts
+++ b/products/desktop/packages/core/src/inbox/inboxQuery.ts
@@ -1,5 +1,6 @@
import type {
SignalReport,
+ SignalReportSectionCountsParams,
SignalReportsQueryParams,
SignalReportsResponse,
} from "@posthog/shared/types";
@@ -21,6 +22,8 @@ export const inboxReportKeys = {
[...inboxReportKeys.all, "list", params ?? {}] as const,
infiniteList: (params?: SignalReportsQueryParams) =>
[...inboxReportKeys.all, "infinite-list", params ?? {}] as const,
+ sectionCounts: (params?: SignalReportSectionCountsParams) =>
+ [...inboxReportKeys.all, "section-counts", params ?? {}] as const,
detail: (reportId: string) =>
[...inboxReportKeys.all, reportId, "detail"] as const,
artefacts: (reportId: string) =>
diff --git a/products/desktop/packages/ui/src/features/inbox/components/ReportsInboxView.test.tsx b/products/desktop/packages/ui/src/features/inbox/components/ReportsInboxView.test.tsx
index f378e090bb18..7d518224c263 100644
--- a/products/desktop/packages/ui/src/features/inbox/components/ReportsInboxView.test.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/components/ReportsInboxView.test.tsx
@@ -121,26 +121,6 @@ vi.mock("@posthog/ui/features/inbox/hooks/useInboxAllReports", () => ({
},
}));
-vi.mock("@posthog/ui/features/inbox/hooks/useInboxSectionCounts", () => ({
- useInboxSectionCounts: () => ({
- reviewAndMerge: mocks.activeReports.filter(
- (report) => report.status === "ready" && !!report.implementation_pr_url,
- ).length,
- needsPr: mocks.activeReports.filter(
- (report) =>
- (report.status === "ready" || report.status === "pending_input") &&
- !report.implementation_pr_url,
- ).length,
- resolved: mocks.activeReports.filter(
- (report) => report.status === "resolved",
- ).length,
- dismissed: mocks.activeReports.filter(
- (report) => report.status === "suppressed",
- ).length,
- isLoading: false,
- }),
-}));
-
vi.mock("@posthog/ui/features/inbox/hooks/useSelfDrivingSetupStatus", () => ({
useSelfDrivingSetupStatus: () => ({
isLoading: mocks.setupStatusLoading,
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.test.tsx b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.test.tsx
index 12081bb5ccb0..bb0c30c13c6c 100644
--- a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.test.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.test.tsx
@@ -14,8 +14,10 @@ const PULL_REQUEST_TOTAL = 40;
const REPORT_TAB_TOTAL = 75;
const mockGetSignalReports = vi.hoisted(() => vi.fn());
+const mockGetSectionCounts = vi.hoisted(() => vi.fn());
const mockClient = vi.hoisted(() => ({
getSignalReports: mockGetSignalReports,
+ getSignalReportSectionCounts: mockGetSectionCounts,
}));
const filterMocks = vi.hoisted(() => ({
sourceProductFilter: [] as string[],
@@ -67,18 +69,12 @@ function readyReport(index: number): SignalReport {
}
/**
- * Answers the three distinct queries the hook fires. The pipeline page is all
- * `ready` reports with no PR, which is what the server's status-ranked ordering
- * actually returns first, and is the condition under which deriving the Reports
- * badge by subtraction silently overcounts.
+ * Answers the pipeline page. It is all `ready` reports with no PR, which is
+ * what the server's status-ranked ordering actually returns first, and is the
+ * condition under which deriving the Reports badge by subtraction silently
+ * overcounts.
*/
function fakeServer(params?: SignalReportsQueryParams): SignalReportsResponse {
- if (params?.count_only && params.has_implementation_pr === true) {
- return { count: PULL_REQUEST_TOTAL, results: [] };
- }
- if (params?.count_only && params.has_implementation_pr === false) {
- return { count: REPORT_TAB_TOTAL, results: [] };
- }
const offset = params?.offset ?? 0;
const limit = params?.limit ?? 100;
const resultCount = Math.max(0, Math.min(limit, PIPELINE_TOTAL - offset));
@@ -100,15 +96,6 @@ function pipelineRequests(): SignalReportsQueryParams[] {
return requests;
}
-/** Params of the Reports-count request, or undefined if it was never fired. */
-function reportsCountParams(): SignalReportsQueryParams | undefined {
- for (const [params] of mockGetSignalReports.mock.calls) {
- if (params?.count_only && params.has_implementation_pr === false)
- return params;
- }
- return undefined;
-}
-
function renderCounts(options?: {
enabled?: boolean;
withReportsCount?: boolean;
@@ -135,6 +122,10 @@ describe("useInboxAllReports", () => {
mockGetSignalReports.mockImplementation(async (params) =>
fakeServer(params),
);
+ mockGetSectionCounts.mockResolvedValue({
+ pull_requests: PULL_REQUEST_TOTAL,
+ reports: REPORT_TAB_TOTAL,
+ });
});
it("counts Reports from the server, not by subtracting from the pipeline total", async () => {
@@ -144,12 +135,10 @@ describe("useInboxAllReports", () => {
expect(result.current.counts.reports).toBe(REPORT_TAB_TOTAL);
});
expect(result.current.counts.pulls).toBe(PULL_REQUEST_TOTAL);
-
- // Anything wider than `ready` pulls in the queued, live and failed runs that
- // the Reports tab routes elsewhere, which is what made the badge disagree
- // with the list it labels.
- expect(reportsCountParams()?.status).toBe("ready");
- expect(reportsCountParams()?.count_only).toBe(true);
+ expect(mockGetSectionCounts).toHaveBeenCalledOnce();
+ expect(
+ mockGetSignalReports.mock.calls.some(([params]) => params?.count_only),
+ ).toBe(false);
});
it("uses a 30-second desktop poll interval", () => {
@@ -176,20 +165,20 @@ describe("useInboxAllReports", () => {
]);
});
- it("skips the Reports count query for consumers that only read the pulls badge", async () => {
+ it("leaves the Reports count at 0 for consumers that only read the pulls badge", async () => {
const { result } = renderCounts();
await waitFor(() => {
expect(result.current.counts.pulls).toBe(PULL_REQUEST_TOTAL);
});
expect(result.current.counts.reports).toBe(0);
- expect(reportsCountParams()).toBeUndefined();
});
it("does not request reports when its surface is unavailable", () => {
renderCounts({ enabled: false, withReportsCount: true });
expect(mockGetSignalReports).not.toHaveBeenCalled();
+ expect(mockGetSectionCounts).not.toHaveBeenCalled();
});
it("ignores a saved source filter when its surface hides that control", async () => {
@@ -223,8 +212,6 @@ describe("useInboxAllReports", () => {
has_implementation_pr: false,
actionability: "immediately_actionable,requires_human_input",
});
- expect(
- mockGetSignalReports.mock.calls.some(([params]) => params?.count_only),
- ).toBe(false);
+ expect(mockGetSectionCounts).not.toHaveBeenCalled();
});
});
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.ts
index d6887b37b29a..83e6d7f10cc7 100644
--- a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.ts
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxAllReports.ts
@@ -6,7 +6,6 @@ import {
filterReportsBySearch,
INBOX_PIPELINE_STATUS_FILTER,
INBOX_PULL_REQUEST_STATUS_FILTER,
- INBOX_REPORTS_TAB_STATUS_FILTER,
} from "@posthog/core/inbox/reportFiltering";
import {
INBOX_SCOPE_FOR_YOU,
@@ -15,10 +14,8 @@ import {
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
import { DESKTOP_INBOX_REFETCH_INTERVAL_MS } from "@posthog/ui/features/inbox/hooks/inboxPolling";
-import {
- useInboxReports,
- useInboxReportsInfinite,
-} from "@posthog/ui/features/inbox/hooks/useInboxReports";
+import { useInboxReportsInfinite } from "@posthog/ui/features/inbox/hooks/useInboxReports";
+import { useInboxSectionCounts } from "@posthog/ui/features/inbox/hooks/useInboxSectionCounts";
import { useInboxReviewerScopeStore } from "@posthog/ui/features/inbox/stores/inboxReviewerScopeStore";
import { useInboxSignalsFilterStore } from "@posthog/ui/features/inbox/stores/inboxSignalsFilterStore";
import { useMemo } from "react";
@@ -37,9 +34,9 @@ const EMPTY_FILTER_ARRAY: never[] = [];
* When `ignoreFilters` is set, the filter-store selectors return constant
* values so unrelated filter changes don't re-render the consumer.
*
- * `withReportsCount` opts into the extra count query behind `counts.reports`;
- * without it that count stays 0. Only surfaces that render that count should
- * pay for its request.
+ * `withPullRequestCount` and `withReportsCount` choose which totals `counts`
+ * carries; one backend count request serves both, and it is skipped when
+ * neither is set.
*/
export function useInboxAllReports(options?: {
enabled?: boolean;
@@ -146,46 +143,13 @@ export function useInboxAllReports(options?: {
},
);
- // True count of pull-request reports for the active scope. The infinite list
- // only holds the first page(s), so deriving pulls from loaded reports caps at
- // the page size and depends on ordering (a PR can sit past page 1). A cheap
- // count-only query with the server-side `has_implementation_pr` filter returns
- // the real total without fetching or enriching a report row.
- const pullRequestCountQuery = useInboxReports(
- {
- status: INBOX_PULL_REQUEST_STATUS_FILTER,
- has_implementation_pr: true,
- // Mirror the list query's active filters so the badge matches the tab
- // body. These are empty when `ignoreFilters` is set (sidebar usage), so
- // the count stays scope-only there.
- source_product:
- sourceProductFilter.length > 0
- ? sourceProductFilter.join(",")
- : undefined,
- priority: buildPriorityFilterParam(priorityFilter),
- suggested_reviewers: reviewerUuid
- ? buildSuggestedReviewerFilterParam([reviewerUuid])
- : undefined,
- count_only: true,
- },
- {
- enabled:
- enabled && withPullRequestCount && (!isForYou || reviewerUuid != null),
- refetchInterval: refetchIntervalMs,
- refetchIntervalInBackground: false,
- },
- );
- const pullRequestTotal = pullRequestCountQuery.data?.count ?? 0;
-
- // True count of Reports-tab reports for the active scope, on the same
- // count-only pattern as the pull-request count above. Deriving it instead by
- // subtracting from the pipeline total only works if every non-report item is
- // visible in the loaded pages, and the list is ordered `ready` first, so the
- // queued, live and failed runs sit past page 1 and never get subtracted.
- const reportsCountQuery = useInboxReports(
+ // The badges need true totals, but the list only holds the first page(s), so
+ // deriving them from loaded reports caps at the page size and depends on
+ // ordering. One backend count returns both totals under the list's scope and
+ // filters without fetching or enriching a report row.
+ const withCounts = withPullRequestCount || withReportsCount;
+ const sectionCountsQuery = useInboxSectionCounts(
{
- status: INBOX_REPORTS_TAB_STATUS_FILTER,
- has_implementation_pr: false,
source_product:
sourceProductFilter.length > 0
? sourceProductFilter.join(",")
@@ -194,16 +158,18 @@ export function useInboxAllReports(options?: {
suggested_reviewers: reviewerUuid
? buildSuggestedReviewerFilterParam([reviewerUuid])
: undefined,
- count_only: true,
},
{
- enabled:
- enabled && withReportsCount && (!isForYou || reviewerUuid != null),
+ enabled: enabled && withCounts && (!isForYou || reviewerUuid != null),
refetchInterval: refetchIntervalMs,
- refetchIntervalInBackground: false,
},
);
- const reportsTotal = reportsCountQuery.data?.count ?? 0;
+ const pullRequestTotal = withPullRequestCount
+ ? (sectionCountsQuery.data?.pull_requests ?? 0)
+ : 0;
+ const reportsTotal = withReportsCount
+ ? (sectionCountsQuery.data?.reports ?? 0)
+ : 0;
const scopedReports = useMemo(() => {
// Reviewer scope is already applied server-side via `suggested_reviewers`.
@@ -222,12 +188,10 @@ export function useInboxAllReports(options?: {
[pullRequestTotal, reportsTotal],
);
- // Each count is its own request, so the list can succeed while they are still
- // in flight and `counts` still reads 0. Anything that records the counts once
- // and never revises them has to wait for this rather than for the list.
- const countsReady =
- (!withPullRequestCount || pullRequestCountQuery.isSuccess) &&
- (!withReportsCount || reportsCountQuery.isSuccess);
+ // The counts are their own request, so the list can succeed while they are
+ // still in flight and `counts` still reads 0. Anything that records the counts
+ // once and never revises them has to wait for this rather than for the list.
+ const countsReady = !withCounts || sectionCountsQuery.isSuccess;
return {
...query,
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.test.tsx b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.test.tsx
index fa411e5098a6..222a21fe4981 100644
--- a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.test.tsx
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.test.tsx
@@ -4,11 +4,11 @@ import { renderHook, waitFor } from "@testing-library/react";
import type { ReactNode } from "react";
import { beforeEach, describe, expect, it, vi } from "vitest";
-const mockGetSignalReports = vi.hoisted(() => vi.fn());
+const mockGetSectionCounts = vi.hoisted(() => vi.fn());
vi.mock("@posthog/ui/features/auth/authClient", () => ({
useOptionalAuthenticatedClient: () => ({
- getSignalReports: mockGetSignalReports,
+ getSignalReportSectionCounts: mockGetSectionCounts,
}),
}));
vi.mock("@posthog/ui/features/auth/useCurrentUser", () => ({
@@ -47,26 +47,24 @@ function renderCount(enabled: boolean) {
describe("useInboxDecisionCount", () => {
beforeEach(() => {
vi.clearAllMocks();
- mockGetSignalReports.mockResolvedValue({ count: 7, results: [] });
+ mockGetSectionCounts.mockResolvedValue({ pull_requests: 3, reports: 4 });
});
- it("loads only a one-row server count for the navigation badge", async () => {
+ it("sums the server's ready counts for the navigation badge", async () => {
const { result } = renderCount(true);
await waitFor(() => expect(result.current).toBe(7));
- expect(mockGetSignalReports).toHaveBeenCalledOnce();
- expect(mockGetSignalReports).toHaveBeenCalledWith(
+ expect(mockGetSectionCounts).toHaveBeenCalledOnce();
+ expect(mockGetSectionCounts).toHaveBeenCalledWith(
expect.objectContaining({
- count_only: true,
priority: undefined,
source_product: undefined,
- status: "ready",
}),
);
});
it("does not request a count when the navigation item is unavailable", () => {
expect(renderCount(false).result.current).toBe(0);
- expect(mockGetSignalReports).not.toHaveBeenCalled();
+ expect(mockGetSectionCounts).not.toHaveBeenCalled();
});
});
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.ts
index c546a47b61bd..173457694c8a 100644
--- a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.ts
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxDecisionCount.ts
@@ -8,16 +8,16 @@ import {
} from "@posthog/core/inbox/reportMembership";
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
-import { useInboxReports } from "@posthog/ui/features/inbox/hooks/useInboxReports";
+import { useInboxSectionCounts } from "@posthog/ui/features/inbox/hooks/useInboxSectionCounts";
import { useInboxReviewerScopeStore } from "@posthog/ui/features/inbox/stores/inboxReviewerScopeStore";
import { useInboxSignalsFilterStore } from "@posthog/ui/features/inbox/stores/inboxSignalsFilterStore";
const EMPTY_FILTER_ARRAY: never[] = [];
/**
- * The navigation badge needs only the ready-report count. Keeping it separate
- * from `useInboxSectionCounts` avoids polling the other two section counts on
- * every route.
+ * The navigation badge shows the ready-report count: the reports with and
+ * without an implementation PR. With the same filters as the inbox list it
+ * shares that list's count request.
*/
export function useInboxDecisionCount(options?: {
enabled?: boolean;
@@ -42,9 +42,8 @@ export function useInboxDecisionCount(options?: {
const reviewerUuid =
teammateUuid ?? (isForYou ? (currentUser?.uuid ?? null) : null);
const scopeReady = !isForYou || reviewerUuid !== null;
- const query = useInboxReports(
+ const query = useInboxSectionCounts(
{
- status: "ready",
source_product:
sourceProductFilter.length > 0
? sourceProductFilter.join(",")
@@ -53,14 +52,10 @@ export function useInboxDecisionCount(options?: {
suggested_reviewers: reviewerUuid
? buildSuggestedReviewerFilterParam([reviewerUuid])
: undefined,
- count_only: true,
- },
- {
- enabled: enabled && scopeReady,
- refetchInterval: 60_000,
- refetchIntervalInBackground: false,
},
+ { enabled: enabled && scopeReady, refetchInterval: 60_000 },
);
- return enabled ? (query.data?.count ?? 0) : 0;
+ const counts = query.data;
+ return enabled && counts ? counts.pull_requests + counts.reports : 0;
}
diff --git a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxSectionCounts.ts b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxSectionCounts.ts
index c83b6a55242a..75d059668c2d 100644
--- a/products/desktop/packages/ui/src/features/inbox/hooks/useInboxSectionCounts.ts
+++ b/products/desktop/packages/ui/src/features/inbox/hooks/useInboxSectionCounts.ts
@@ -1,99 +1,23 @@
-import {
- buildPriorityFilterParam,
- buildSuggestedReviewerFilterParam,
- INBOX_ACTIONABLE_ACTIONABILITY_FILTER,
- INBOX_ACTIONABLE_REPORT_STATUS_FILTER,
-} from "@posthog/core/inbox/reportFiltering";
-import {
- INBOX_SCOPE_FOR_YOU,
- parseTeammateInboxScope,
-} from "@posthog/core/inbox/reportMembership";
-import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
-import { useCurrentUser } from "@posthog/ui/features/auth/useCurrentUser";
-import { useInboxReports } from "@posthog/ui/features/inbox/hooks/useInboxReports";
-import { useInboxReviewerScopeStore } from "@posthog/ui/features/inbox/stores/inboxReviewerScopeStore";
-import { useInboxSignalsFilterStore } from "@posthog/ui/features/inbox/stores/inboxSignalsFilterStore";
-
-export interface InboxSectionCounts {
- reviewAndMerge: number;
- needsPr: number;
- resolved: number;
- dismissed: number;
- isLoading: boolean;
-}
+import { inboxReportKeys } from "@posthog/core/inbox/inboxQuery";
+import type {
+ SignalReportSectionCounts,
+ SignalReportSectionCountsParams,
+} from "@posthog/shared/types";
+import { useAuthenticatedQuery } from "@posthog/ui/hooks/useAuthenticatedQuery";
/**
- * Server-side counts for the inbox's sections and badges.
- *
- * Loaded pages only contain a window of the inbox, so each number uses a
- * count-only query with the same server-side filters as its section.
- *
- * Scope and the priority filter are mirrored into every query so the counts
- * move with what the list shows. Search is a client-side title match, so
- * surfaces showing searched rows must count those rows instead.
+ * Backend counts of the ready reports with and without an implementation PR,
+ * under the same server-side filters as the inbox list. One request serves the
+ * pull request badge, the reports badge, and the ready badge that sums them,
+ * so callers that pass the same filters share it.
*/
-export function useInboxSectionCounts(): InboxSectionCounts {
- const scope = useInboxReviewerScopeStore((s) => s.scope);
- const priorityFilter = useInboxSignalsFilterStore((s) => s.priorityFilter);
- const client = useOptionalAuthenticatedClient();
- const { data: currentUser } = useCurrentUser({ client });
-
- const isForYou = scope === INBOX_SCOPE_FOR_YOU;
- const teammateUuid = parseTeammateInboxScope(scope);
- const reviewerUuid =
- teammateUuid ?? (isForYou ? (currentUser?.uuid ?? null) : null);
-
- const shared = {
- priority: buildPriorityFilterParam(priorityFilter),
- suggested_reviewers: reviewerUuid
- ? buildSuggestedReviewerFilterParam([reviewerUuid])
- : undefined,
- count_only: true,
- };
- const scopeReady = !isForYou || reviewerUuid != null;
- const options = {
- refetchInterval: 60_000,
- refetchIntervalInBackground: false,
- };
-
- const reviewAndMergeQuery = useInboxReports(
- { ...shared, status: "ready", has_implementation_pr: true },
- { ...options, enabled: scopeReady },
+export function useInboxSectionCounts(
+ params: SignalReportSectionCountsParams,
+ options: { enabled: boolean; refetchInterval: number },
+) {
+ return useAuthenticatedQuery<SignalReportSectionCounts>(
+ inboxReportKeys.sectionCounts(params),
+ (client) => client.getSignalReportSectionCounts(params),
+ { ...options, refetchIntervalInBackground: false },
);
- const needsPrQuery = useInboxReports(
- {
- ...shared,
- status: INBOX_ACTIONABLE_REPORT_STATUS_FILTER,
- actionability: INBOX_ACTIONABLE_ACTIONABILITY_FILTER,
- has_implementation_pr: false,
- },
- { ...options, enabled: scopeReady },
- );
- const resolvedQuery = useInboxReports(
- {
- ...shared,
- status: "resolved",
- },
- { ...options, enabled: scopeReady },
- );
- const dismissedQuery = useInboxReports(
- {
- ...shared,
- status: "suppressed",
- },
- { ...options, enabled: scopeReady },
- );
-
- return {
- reviewAndMerge: reviewAndMergeQuery.data?.count ?? 0,
- needsPr: needsPrQuery.data?.count ?? 0,
- resolved: resolvedQuery.data?.count ?? 0,
- dismissed: dismissedQuery.data?.count ?? 0,
- isLoading:
- reviewAndMergeQuery.isLoading ||
- needsPrQuery.isLoading ||
- resolvedQuery.isLoading ||
- dismissedQuery.isLoading ||
- (isForYou && reviewerUuid == null),
- };
}