Skip to content

Commit 8b15bd8

Browse files
authored
ref(tsc): move debugFile endpoint to apiOptions (#112565)
1 parent c9af9df commit 8b15bd8

File tree

4 files changed

+71
-113
lines changed

4 files changed

+71
-113
lines changed

static/app/components/events/interfaces/crashContent/exception/actionableItemsUtils.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {useQuery} from '@tanstack/react-query';
2+
13
import {ExternalLink} from '@sentry/scraps/link';
24

35
import {findBestThread} from 'sentry/components/events/interfaces/threads/threadSelector/findBestThread';
@@ -19,8 +21,7 @@ import {EntryType} from 'sentry/types/event';
1921
import type {Project} from 'sentry/types/project';
2022
import {defined} from 'sentry/utils';
2123
import {trackAnalytics} from 'sentry/utils/analytics';
22-
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
23-
import {useApiQuery} from 'sentry/utils/queryClient';
24+
import {apiOptions} from 'sentry/utils/api/apiOptions';
2425
import {useOrganization} from 'sentry/utils/useOrganization';
2526
import {semverCompare} from 'sentry/utils/versions/semverCompare';
2627

@@ -226,27 +227,24 @@ export const useFetchProguardMappingFiles = ({
226227
data: proguardMappingFiles,
227228
isSuccess,
228229
isPending,
229-
} = useApiQuery<DebugFile[]>(
230-
[
231-
getApiUrl('/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/', {
230+
} = useQuery({
231+
...apiOptions.as<DebugFile[]>()(
232+
'/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/',
233+
{
232234
path: {
233235
organizationIdOrSlug: organization.slug,
234236
projectIdOrSlug: project.slug,
235237
},
236-
}),
237-
{
238238
query: {
239239
query: proGuardImageUuid,
240240
file_formats: 'proguard',
241241
},
242-
},
243-
],
244-
{
245-
staleTime: Infinity,
246-
enabled: shouldFetch,
247-
retry: false,
248-
}
249-
);
242+
staleTime: Infinity,
243+
}
244+
),
245+
enabled: shouldFetch,
246+
retry: false,
247+
});
250248

251249
function getProguardErrorsFromMappingFiles(): EventErrorData[] {
252250
if (isShare) {

static/app/components/events/interfaces/debugMeta/debugImageDetails/index.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Fragment} from 'react';
22
import {css, type Theme} from '@emotion/react';
33
import styled from '@emotion/styled';
4+
import {useQuery} from '@tanstack/react-query';
45
import partition from 'lodash/partition';
56
import sortBy from 'lodash/sortBy';
67

@@ -19,9 +20,9 @@ import {CandidateDownloadStatus} from 'sentry/types/debugImage';
1920
import type {Event} from 'sentry/types/event';
2021
import type {Organization} from 'sentry/types/organization';
2122
import type {Project} from 'sentry/types/project';
23+
import {apiOptions} from 'sentry/utils/api/apiOptions';
2224
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
2325
import {displayReprocessEventAction} from 'sentry/utils/displayReprocessEventAction';
24-
import {useApiQuery} from 'sentry/utils/queryClient';
2526
import {useApi} from 'sentry/utils/useApi';
2627
import {useOrganization} from 'sentry/utils/useOrganization';
2728
import {getPrettyFileType} from 'sentry/views/settings/projectDebugFiles/utils';
@@ -218,15 +219,14 @@ export function DebugImageDetails({
218219
isPending,
219220
isError,
220221
refetch,
221-
} = useApiQuery<DebugFile[]>(
222-
[
223-
getApiUrl('/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/', {
222+
} = useQuery({
223+
...apiOptions.as<DebugFile[]>()(
224+
'/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/',
225+
{
224226
path: {
225227
organizationIdOrSlug: organization.slug,
226228
projectIdOrSlug: projSlug,
227229
},
228-
}),
229-
{
230230
query: {
231231
debug_id: image?.debug_id,
232232
code_id: image?.code_id,
@@ -246,13 +246,11 @@ export function DebugImageDetails({
246246
'portablepdb',
247247
],
248248
},
249-
},
250-
],
251-
{
252-
enabled: hasUploadedDebugFiles,
253-
staleTime: 0,
254-
}
255-
);
249+
staleTime: 0,
250+
}
251+
),
252+
enabled: hasUploadedDebugFiles,
253+
});
256254

257255
const {code_file, status} = image ?? {};
258256
const candidates = getCandidates({debugFiles, image, isLoading: isPending});

static/app/views/settings/projectDebugFiles/index.tsx

Lines changed: 33 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Fragment, useCallback, useState} from 'react';
22
import styled from '@emotion/styled';
3+
import {useQuery, useQueryClient} from '@tanstack/react-query';
34

45
import {Checkbox} from '@sentry/scraps/checkbox';
56

@@ -16,13 +17,8 @@ import {SearchBar} from 'sentry/components/searchBar';
1617
import {SentryDocumentTitle} from 'sentry/components/sentryDocumentTitle';
1718
import {t} from 'sentry/locale';
1819
import type {BuiltinSymbolSource, CustomRepo, DebugFile} from 'sentry/types/debugFiles';
19-
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
20-
import {
21-
useApiQuery,
22-
useMutation,
23-
useQueryClient,
24-
type ApiQueryKey,
25-
} from 'sentry/utils/queryClient';
20+
import {apiOptions, selectJsonWithHeaders} from 'sentry/utils/api/apiOptions';
21+
import {useMutation} from 'sentry/utils/queryClient';
2622
import type {RequestError} from 'sentry/utils/requestError/requestError';
2723
import {routeTitleGen} from 'sentry/utils/routeTitle';
2824
import {useApi} from 'sentry/utils/useApi';
@@ -37,38 +33,6 @@ import {useProjectSettingsOutlet} from 'sentry/views/settings/project/projectSet
3733
import {DebugFileRow} from './debugFileRow';
3834
import {Sources} from './sources';
3935

40-
function makeDebugFilesQueryKey({
41-
orgSlug,
42-
projectSlug,
43-
query,
44-
}: {
45-
orgSlug: string;
46-
projectSlug: string;
47-
query: {cursor: string | undefined; query: string | undefined};
48-
}): ApiQueryKey {
49-
return [
50-
getApiUrl('/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/', {
51-
path: {organizationIdOrSlug: orgSlug, projectIdOrSlug: projectSlug},
52-
}),
53-
{query},
54-
];
55-
}
56-
57-
function makeSymbolSourcesQueryKey({
58-
orgSlug,
59-
platform,
60-
}: {
61-
orgSlug: string;
62-
platform?: string;
63-
}): ApiQueryKey {
64-
return [
65-
getApiUrl('/organizations/$organizationIdOrSlug/builtin-symbol-sources/', {
66-
path: {organizationIdOrSlug: orgSlug},
67-
}),
68-
{query: {platform}},
69-
];
70-
}
71-
7236
export default function ProjectDebugSymbols() {
7337
const organization = useOrganization();
7438
const {project} = useProjectSettingsOutlet();
@@ -82,21 +46,34 @@ export default function ProjectDebugSymbols() {
8246
const cursor = location.query.cursor as string | undefined;
8347
const hasSymbolSourcesFeatureFlag = organization.features.includes('symbol-sources');
8448

49+
const debugFilesApiOptions = apiOptions.as<DebugFile[]>()(
50+
'/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/',
51+
{
52+
path: {organizationIdOrSlug: organization.slug, projectIdOrSlug: project.slug},
53+
query: {query, cursor},
54+
staleTime: 0,
55+
}
56+
);
57+
8558
const {
86-
data: debugFiles,
87-
getResponseHeader: getDebugFilesResponseHeader,
59+
data: debugFilesResponse,
8860
isPending: isLoadingDebugFiles,
8961
isLoadingError: isLoadingErrorDebugFiles,
9062
refetch: refetchDebugFiles,
91-
} = useApiQuery<DebugFile[] | null>(
92-
makeDebugFilesQueryKey({
93-
projectSlug: project.slug,
94-
orgSlug: organization.slug,
95-
query: {query, cursor},
96-
}),
63+
} = useQuery({
64+
...debugFilesApiOptions,
65+
select: selectJsonWithHeaders,
66+
retry: false,
67+
});
68+
69+
const debugFiles = debugFilesResponse?.json;
70+
71+
const symbolSourcesOptions = apiOptions.as<BuiltinSymbolSource[] | null>()(
72+
'/organizations/$organizationIdOrSlug/builtin-symbol-sources/',
9773
{
74+
path: {organizationIdOrSlug: organization.slug},
75+
query: {platform: project.platform},
9876
staleTime: 0,
99-
retry: false,
10077
}
10178
);
10279

@@ -105,17 +82,11 @@ export default function ProjectDebugSymbols() {
10582
isPending: isLoadingSymbolSources,
10683
isError: isErrorSymbolSources,
10784
refetch: refetchSymbolSources,
108-
} = useApiQuery<BuiltinSymbolSource[] | null>(
109-
makeSymbolSourcesQueryKey({
110-
orgSlug: organization.slug,
111-
platform: project.platform,
112-
}),
113-
{
114-
staleTime: 0,
115-
enabled: hasSymbolSourcesFeatureFlag,
116-
retry: 0,
117-
}
118-
);
85+
} = useQuery({
86+
...symbolSourcesOptions,
87+
enabled: hasSymbolSourcesFeatureFlag,
88+
retry: 0,
89+
});
11990

12091
const handleSearch = useCallback(
12192
(value: string) => {
@@ -144,19 +115,12 @@ export default function ProjectDebugSymbols() {
144115

145116
// invalidate debug files query
146117
queryClient.invalidateQueries({
147-
queryKey: makeDebugFilesQueryKey({
148-
projectSlug: project.slug,
149-
orgSlug: organization.slug,
150-
query: {query, cursor},
151-
}),
118+
queryKey: debugFilesApiOptions.queryKey,
152119
});
153120

154121
// invalidate symbol sources query
155122
queryClient.invalidateQueries({
156-
queryKey: makeSymbolSourcesQueryKey({
157-
orgSlug: organization.slug,
158-
platform: project.platform,
159-
}),
123+
queryKey: symbolSourcesOptions.queryKey,
160124
});
161125
},
162126
onError: () => {
@@ -267,7 +231,7 @@ export default function ProjectDebugSymbols() {
267231
})
268232
: null}
269233
</StyledPanelTable>
270-
<Pagination pageLinks={getDebugFilesResponseHeader?.('Link')} />
234+
<Pagination pageLinks={debugFilesResponse?.headers.Link} />
271235
</Fragment>
272236
)}
273237
</SentryDocumentTitle>

static/app/views/settings/projectProguard/index.tsx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Fragment, useCallback, useState} from 'react';
22
import styled from '@emotion/styled';
3+
import {useQuery} from '@tanstack/react-query';
34

45
import {ExternalLink} from '@sentry/scraps/link';
56

@@ -9,8 +10,7 @@ import {PanelTable} from 'sentry/components/panels/panelTable';
910
import {SearchBar} from 'sentry/components/searchBar';
1011
import {t, tct} from 'sentry/locale';
1112
import type {DebugFile} from 'sentry/types/debugFiles';
12-
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
13-
import {useApiQuery} from 'sentry/utils/queryClient';
13+
import {apiOptions, selectJsonWithHeaders} from 'sentry/utils/api/apiOptions';
1414
import {useApi} from 'sentry/utils/useApi';
1515
import {useLocation} from 'sentry/utils/useLocation';
1616
import {useNavigate} from 'sentry/utils/useNavigate';
@@ -34,29 +34,27 @@ export default function ProjectProguard() {
3434
const [loading, setLoading] = useState(false);
3535

3636
const {
37-
data: mappings,
37+
data: mappingsResp,
3838
isPending: dataLoading,
39-
getResponseHeader,
4039
refetch: fetchData,
41-
} = useApiQuery<DebugFile[]>(
42-
[
43-
getApiUrl('/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/', {
44-
path: {organizationIdOrSlug: organization.slug, projectIdOrSlug: project.slug},
45-
}),
40+
} = useQuery({
41+
...apiOptions.as<DebugFile[]>()(
42+
'/projects/$organizationIdOrSlug/$projectIdOrSlug/files/dsyms/',
4643
{
44+
path: {organizationIdOrSlug: organization.slug, projectIdOrSlug: project.slug},
4745
query: {
4846
query: location.query.query,
4947
file_formats: 'proguard',
5048
cursor: location.query.cursor,
5149
},
52-
},
53-
],
54-
{
55-
staleTime: 0,
56-
}
57-
);
50+
staleTime: 0,
51+
}
52+
),
53+
select: selectJsonWithHeaders,
54+
});
55+
const mappings = mappingsResp?.json;
5856

59-
const mappingsPageLinks = getResponseHeader?.('Link');
57+
const mappingsPageLinks = mappingsResp?.headers.Link;
6058

6159
const handleSearch = useCallback(
6260
(query: string) => {

0 commit comments

Comments
 (0)