1- import { keepPreviousData as keepPreviousDataFn } from '@tanstack/react-query' ;
1+ import { queryOptions } from '@tanstack/react-query' ;
22
33import { normalizeDateTimeParams } from 'sentry/components/pageFilters/parse' ;
44import { usePageFilters } from 'sentry/components/pageFilters/usePageFilters' ;
55import type { CaseInsensitive } from 'sentry/components/searchQueryBuilder/hooks' ;
66import type { PageFilters } from 'sentry/types/core' ;
7- import { getApiUrl } from 'sentry/utils/api/getApiUrl' ;
8- import type { QueryError } from 'sentry/utils/discover/genericDiscoverQuery' ;
9- import { parseError } from 'sentry/utils/discover/genericDiscoverQuery' ;
7+ import { apiOptions } from 'sentry/utils/api/apiOptions' ;
108import { DiscoverDatasets } from 'sentry/utils/discover/types' ;
11- import type { UseApiQueryOptions , UseApiQueryResult } from 'sentry/utils/queryClient' ;
12- import { useApiQuery } from 'sentry/utils/queryClient' ;
13- import type { RequestError } from 'sentry/utils/requestError/requestError' ;
149import { useOrganization } from 'sentry/utils/useOrganization' ;
1510
1611export const BREAKDOWN_SLICES = 40 ;
@@ -54,20 +49,15 @@ export interface TraceResult {
5449
5550type TraceBreakdownResult = TraceBreakdownProject | TraceBreakdownMissing ;
5651
57- interface TraceResults {
52+ export interface TraceResults {
5853 data : TraceResult [ ] ;
5954 meta : any ;
6055}
6156
62- interface UseTracesOptions extends Pick <
63- UseApiQueryOptions < TraceResults > ,
64- 'refetchInterval'
65- > {
57+ interface UseTracesOptions {
6658 caseInsensitive ?: CaseInsensitive ;
6759 cursor ?: string ;
6860 datetime ?: PageFilters [ 'datetime' ] ;
69- enabled ?: boolean ;
70- keepPreviousData ?: boolean ;
7161 limit ?: number ;
7262 logQuery ?: string [ ] ;
7363 metricQuery ?: string [ ] ;
@@ -76,61 +66,42 @@ interface UseTracesOptions extends Pick<
7666 spanQuery ?: string [ ] ;
7767}
7868
79- type UseTracesResult = Omit < UseApiQueryResult < TraceResults , RequestError > , 'error' > & {
80- error : QueryError | null ;
81- } ;
82-
83- export function useTraces ( {
69+ export function useTracesApiOptions ( {
8470 caseInsensitive,
8571 cursor,
8672 datetime,
87- enabled,
8873 limit,
8974 query,
9075 sort,
91- keepPreviousData,
92- refetchInterval,
9376 logQuery,
9477 metricQuery,
9578 spanQuery,
96- } : UseTracesOptions ) : UseTracesResult {
79+ } : UseTracesOptions ) {
9780 const organization = useOrganization ( ) ;
9881 const { selection} = usePageFilters ( ) ;
9982
100- const path = getApiUrl ( '/organizations/$organizationIdOrSlug/traces/' , {
101- path : { organizationIdOrSlug : organization . slug } ,
102- } ) ;
103-
104- const endpointOptions = {
105- query : {
106- project : selection . projects ,
107- environment : selection . environments ,
108- ...normalizeDateTimeParams ( datetime ?? selection . datetime ) ,
109- dataset : DiscoverDatasets . SPANS ,
110- query,
111- sort,
112- per_page : limit ,
113- cursor,
114- breakdownSlices : BREAKDOWN_SLICES ,
115- caseInsensitive : caseInsensitive ? '1' : undefined ,
116- ...( Array . isArray ( logQuery ) && logQuery . length > 0 ? { logQuery} : { } ) ,
117- ...( Array . isArray ( metricQuery ) && metricQuery . length > 0 ? { metricQuery} : { } ) ,
118- ...( Array . isArray ( spanQuery ) && spanQuery . length > 0 ? { spanQuery} : { } ) ,
119- } ,
120- } ;
121-
122- const { error, ...rest } = useApiQuery < TraceResults > ( [ path , endpointOptions ] , {
123- staleTime : 0 ,
83+ return queryOptions ( {
84+ ...apiOptions . as < TraceResults > ( ) ( '/organizations/$organizationIdOrSlug/traces/' , {
85+ path : { organizationIdOrSlug : organization . slug } ,
86+ query : {
87+ project : selection . projects ,
88+ environment : selection . environments ,
89+ ...normalizeDateTimeParams ( datetime ?? selection . datetime ) ,
90+ dataset : DiscoverDatasets . SPANS ,
91+ query,
92+ sort,
93+ per_page : limit ,
94+ cursor,
95+ breakdownSlices : BREAKDOWN_SLICES ,
96+ caseInsensitive : caseInsensitive ? '1' : undefined ,
97+ ...( Array . isArray ( logQuery ) && logQuery . length > 0 ? { logQuery} : { } ) ,
98+ ...( Array . isArray ( metricQuery ) && metricQuery . length > 0 ? { metricQuery} : { } ) ,
99+ ...( Array . isArray ( spanQuery ) && spanQuery . length > 0 ? { spanQuery} : { } ) ,
100+ } ,
101+ staleTime : 0 ,
102+ } ) ,
124103 refetchOnWindowFocus : false ,
125104 refetchOnMount : false ,
126105 retry : false ,
127- placeholderData : keepPreviousData ? keepPreviousDataFn : undefined ,
128- enabled,
129- refetchInterval,
130106 } ) ;
131-
132- return {
133- ...rest ,
134- error : parseError ( error ) ,
135- } ;
136107}
0 commit comments