From 128840c8614d443be7443a829b99639148b32cd7 Mon Sep 17 00:00:00 2001 From: MichaelSun48 Date: Mon, 6 Jan 2025 17:24:03 -0800 Subject: [PATCH 1/5] Add hook to fetch issue counts --- .../issueList/queries/useFetchIssueCounts.tsx | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 static/app/views/issueList/queries/useFetchIssueCounts.tsx diff --git a/static/app/views/issueList/queries/useFetchIssueCounts.tsx b/static/app/views/issueList/queries/useFetchIssueCounts.tsx new file mode 100644 index 00000000000000..74b7961e724438 --- /dev/null +++ b/static/app/views/issueList/queries/useFetchIssueCounts.tsx @@ -0,0 +1,38 @@ +import type {PageFilters} from 'sentry/types/core'; +import type {ApiQueryKey, UseApiQueryOptions} from 'sentry/utils/queryClient'; +import {useApiQuery} from 'sentry/utils/queryClient'; +import type {QueryCounts} from 'sentry/views/issueList/utils'; + +// Copied from CountEndpointParams in overview.tsx +interface FetchIssueCountsParameters extends Partial { + environment: string[]; + orgSlug: string; + project: number[]; + query: string[]; + groupStatsPeriod?: string | null; + sort?: string; + statsPeriod?: string | null; + useGroupSnubaDataset?: boolean; +} + +export const makeFetchIssueCounts = ({ + orgSlug, + ...requestParams +}: FetchIssueCountsParameters): ApiQueryKey => [ + `/organizations/${orgSlug}/issues-count/`, + { + query: { + ...requestParams, + }, + }, +]; + +export const useFetchIssueCounts = ( + params: FetchIssueCountsParameters, + options: Partial> = {} +) => { + return useApiQuery(makeFetchIssueCounts(params), { + staleTime: 0, + ...options, + }); +}; From 79a6a5443e7db1e6b1e4e57b1606c1df724496ab Mon Sep 17 00:00:00 2001 From: MichaelSun48 Date: Mon, 6 Jan 2025 17:48:54 -0800 Subject: [PATCH 2/5] Add start/end params --- static/app/views/issueList/queries/useFetchIssueCounts.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/static/app/views/issueList/queries/useFetchIssueCounts.tsx b/static/app/views/issueList/queries/useFetchIssueCounts.tsx index 74b7961e724438..65b1f5a33a4bfc 100644 --- a/static/app/views/issueList/queries/useFetchIssueCounts.tsx +++ b/static/app/views/issueList/queries/useFetchIssueCounts.tsx @@ -9,8 +9,10 @@ interface FetchIssueCountsParameters extends Partial { orgSlug: string; project: number[]; query: string[]; + end?: string | null; groupStatsPeriod?: string | null; sort?: string; + start?: string | null; statsPeriod?: string | null; useGroupSnubaDataset?: boolean; } From 47a024491918e0ebff9d4034bd9a225663907abd Mon Sep 17 00:00:00 2001 From: MichaelSun48 Date: Mon, 6 Jan 2025 18:02:04 -0800 Subject: [PATCH 3/5] Remove unncessary extend and comment --- static/app/views/issueList/queries/useFetchIssueCounts.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/static/app/views/issueList/queries/useFetchIssueCounts.tsx b/static/app/views/issueList/queries/useFetchIssueCounts.tsx index 65b1f5a33a4bfc..7656d8fc681c13 100644 --- a/static/app/views/issueList/queries/useFetchIssueCounts.tsx +++ b/static/app/views/issueList/queries/useFetchIssueCounts.tsx @@ -1,10 +1,8 @@ -import type {PageFilters} from 'sentry/types/core'; import type {ApiQueryKey, UseApiQueryOptions} from 'sentry/utils/queryClient'; import {useApiQuery} from 'sentry/utils/queryClient'; import type {QueryCounts} from 'sentry/views/issueList/utils'; -// Copied from CountEndpointParams in overview.tsx -interface FetchIssueCountsParameters extends Partial { +interface FetchIssueCountsParameters { environment: string[]; orgSlug: string; project: number[]; From 60b3d65fbfaafc0e9ff610ce6f6f8a20e4a1c9cd Mon Sep 17 00:00:00 2001 From: MichaelSun48 Date: Mon, 6 Jan 2025 18:11:14 -0800 Subject: [PATCH 4/5] Generalize return type to allow for arbitrary query --- static/app/views/issueList/queries/useFetchIssueCounts.tsx | 4 ++-- static/app/views/issueList/utils.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/static/app/views/issueList/queries/useFetchIssueCounts.tsx b/static/app/views/issueList/queries/useFetchIssueCounts.tsx index 7656d8fc681c13..30ddfac3e2eecb 100644 --- a/static/app/views/issueList/queries/useFetchIssueCounts.tsx +++ b/static/app/views/issueList/queries/useFetchIssueCounts.tsx @@ -1,6 +1,6 @@ import type {ApiQueryKey, UseApiQueryOptions} from 'sentry/utils/queryClient'; import {useApiQuery} from 'sentry/utils/queryClient'; -import type {QueryCounts} from 'sentry/views/issueList/utils'; +import type {QueryCount, QueryCounts} from 'sentry/views/issueList/utils'; interface FetchIssueCountsParameters { environment: string[]; @@ -29,7 +29,7 @@ export const makeFetchIssueCounts = ({ export const useFetchIssueCounts = ( params: FetchIssueCountsParameters, - options: Partial> = {} + options: Partial>> = {} ) => { return useApiQuery(makeFetchIssueCounts(params), { staleTime: 0, diff --git a/static/app/views/issueList/utils.tsx b/static/app/views/issueList/utils.tsx index 232de49093202c..a43e94f937bd4d 100644 --- a/static/app/views/issueList/utils.tsx +++ b/static/app/views/issueList/utils.tsx @@ -163,7 +163,7 @@ export function isForReviewQuery(query: string | undefined) { // the tab counts will look like 99+ export const TAB_MAX_COUNT = 99; -type QueryCount = { +export type QueryCount = { count: number; hasMore: boolean; }; From 810952fe5f5f1ee3e6adc63fcf33452a3849ffe5 Mon Sep 17 00:00:00 2001 From: MichaelSun48 Date: Mon, 6 Jan 2025 21:37:05 -0800 Subject: [PATCH 5/5] fix silly --- static/app/views/issueList/queries/useFetchIssueCounts.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/static/app/views/issueList/queries/useFetchIssueCounts.tsx b/static/app/views/issueList/queries/useFetchIssueCounts.tsx index 30ddfac3e2eecb..386e855332a061 100644 --- a/static/app/views/issueList/queries/useFetchIssueCounts.tsx +++ b/static/app/views/issueList/queries/useFetchIssueCounts.tsx @@ -21,9 +21,7 @@ export const makeFetchIssueCounts = ({ }: FetchIssueCountsParameters): ApiQueryKey => [ `/organizations/${orgSlug}/issues-count/`, { - query: { - ...requestParams, - }, + query: requestParams, }, ];