-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
ref(api): type fetchMutation urls with getApiUrl #124862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,8 @@ import type { | |
| } from 'sentry/types/integrations'; | ||
| import type {Member, Team} from 'sentry/types/organization'; | ||
| import {apiOptions} from 'sentry/utils/api/apiOptions'; | ||
| import { | ||
| getExternalActorEndpointDetails, | ||
| isExternalActorMapping, | ||
| } from 'sentry/utils/integrationUtil'; | ||
| import type {getApiUrl} from 'sentry/utils/api/getApiUrl'; | ||
| import {isExternalActorMapping} from 'sentry/utils/integrationUtil'; | ||
| import {fetchMutation} from 'sentry/utils/queryClient'; | ||
| import {RequestError} from 'sentry/utils/requestError/requestError'; | ||
| import {requestErrorToFieldErrors} from 'sentry/utils/requestError/requestErrorToFieldErrors'; | ||
|
|
@@ -34,7 +32,9 @@ import {useOrganization} from 'sentry/utils/useOrganization'; | |
| type SentrySelection = {id: string; name: string}; | ||
|
|
||
| type BaseProps = { | ||
| getBaseFormEndpoint: (mapping?: ExternalActorMappingOrSuggestion) => string; | ||
| getBaseFormEndpoint: ( | ||
| mapping?: ExternalActorMappingOrSuggestion | ||
| ) => ReturnType<typeof getApiUrl>; | ||
| integration: Integration; | ||
| type: 'user' | 'team'; | ||
| defaultOptions?: Array<{label: React.ReactNode; value: SentrySelection}>; | ||
|
|
@@ -182,14 +182,11 @@ function InlineMappingForm({ | |
| initialValue={initialValue} | ||
| mutationOptions={{ | ||
| mutationFn: ({sentryId}: {sentryId: SentrySelection}) => { | ||
| const isValidMapping = Object.hasOwn(mapping || {}, 'id'); | ||
| const fullData = buildMutationData(mapping, integration, type, sentryId); | ||
| const {apiEndpoint, apiMethod} = getExternalActorEndpointDetails( | ||
| getBaseFormEndpoint(fullData as ExternalActorMappingOrSuggestion), | ||
| fullData as ExternalActorMappingOrSuggestion | ||
| ); | ||
| return fetchMutation<ExternalActorMapping>({ | ||
| url: apiEndpoint, | ||
| method: apiMethod, | ||
| url: getBaseFormEndpoint(fullData as ExternalActorMappingOrSuggestion), | ||
| method: isValidMapping ? 'PUT' : 'POST', | ||
| data: fullData, | ||
| }); | ||
|
Comment on lines
-186
to
194
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the place with the 'most' change in the PR. Before we were accepting All that gets streamlined. Now it's the job of each there's a only two real files that implement |
||
| }, | ||
|
|
@@ -264,20 +261,17 @@ function ModalMappingForm({ | |
| externalName: string; | ||
| sentryId: SentrySelection; | ||
| }) => { | ||
| const isValidMapping = mapping && Object.hasOwn(mapping || {}, 'id'); | ||
| const fullData = buildMutationData( | ||
| mapping, | ||
| integration, | ||
| type, | ||
| sentryId, | ||
| externalName | ||
| ); | ||
| const {apiEndpoint, apiMethod} = getExternalActorEndpointDetails( | ||
| getBaseFormEndpoint(fullData as ExternalActorMappingOrSuggestion), | ||
| fullData as ExternalActorMappingOrSuggestion | ||
| ); | ||
| return fetchMutation<ExternalActorMapping>({ | ||
| url: apiEndpoint, | ||
| method: apiMethod, | ||
| url: getBaseFormEndpoint(fullData as ExternalActorMappingOrSuggestion), | ||
| method: isValidMapping ? 'PUT' : 'POST', | ||
| data: fullData, | ||
| }); | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's where the type is enforced going forward!