-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(custom-views): Create FE hooks for group search view endpoint (#…
…75188) This PR creates the `useApiQuery` and `useMutation` hooks to call the GET and PUT groupsearchview endpoints, respectively. The endpoints can be found [here](https://github.com/getsentry/sentry/blob/master/src/sentry/issues/endpoints/organization_group_search_views.py)
- Loading branch information
1 parent
9741c8c
commit 2af053d
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
59 changes: 59 additions & 0 deletions
59
static/app/views/issueList/mutations/useUpdateGroupSearchViews.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {addErrorMessage} from 'sentry/actionCreators/indicator'; | ||
import {t} from 'sentry/locale'; | ||
import { | ||
setApiQueryData, | ||
useMutation, | ||
type UseMutationOptions, | ||
useQueryClient, | ||
} from 'sentry/utils/queryClient'; | ||
import type RequestError from 'sentry/utils/requestError/requestError'; | ||
import useApi from 'sentry/utils/useApi'; | ||
import {makeFetchGroupSearchViewsKey} from 'sentry/views/issueList/queries/useFetchGroupSearchViews'; | ||
import type {GroupSearchView} from 'sentry/views/issueList/types'; | ||
|
||
type UpdateGroupSearchViewsVariables = { | ||
groupSearchViews: GroupSearchView[]; | ||
orgSlug: string; | ||
}; | ||
|
||
// The PUT groupsearchviews endpoint updates the views AND returns the updated views | ||
type UpdateGroupSearchViewResponse = GroupSearchView[]; | ||
|
||
export const useUpdateGroupSearchViews = ( | ||
options: Omit< | ||
UseMutationOptions< | ||
UpdateGroupSearchViewResponse, | ||
RequestError, | ||
UpdateGroupSearchViewsVariables | ||
>, | ||
'mutationFn' | ||
> = {} | ||
) => { | ||
const api = useApi(); | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation< | ||
UpdateGroupSearchViewResponse, | ||
RequestError, | ||
UpdateGroupSearchViewsVariables | ||
>({ | ||
...options, | ||
mutationFn: ({orgSlug, groupSearchViews: data}: UpdateGroupSearchViewsVariables) => | ||
api.requestPromise(`/organizations/${orgSlug}/group-search-views/`, { | ||
method: 'PUT', | ||
data, | ||
}), | ||
onSuccess: (groupSearchViews, parameters, context) => { | ||
setApiQueryData<GroupSearchView[]>( | ||
queryClient, | ||
makeFetchGroupSearchViewsKey({orgSlug: parameters.orgSlug}), | ||
groupSearchViews // Update the cache with the new groupSearchViews | ||
); | ||
options.onSuccess?.(groupSearchViews, parameters, context); | ||
}, | ||
onError: (error, variables, context) => { | ||
addErrorMessage(t('Failed to update views')); | ||
options.onError?.(error, variables, context); | ||
}, | ||
}); | ||
}; |
27 changes: 27 additions & 0 deletions
27
static/app/views/issueList/queries/useFetchGroupSearchViews.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type {UseApiQueryOptions} from 'sentry/utils/queryClient'; | ||
import {useApiQuery} from 'sentry/utils/queryClient'; | ||
import type {GroupSearchView} from 'sentry/views/issueList/types'; | ||
|
||
type FetchGroupSearchViewsParameters = { | ||
orgSlug: string; | ||
}; | ||
|
||
type FetchGroupSearchViewsResponse = GroupSearchView[]; | ||
|
||
export const makeFetchGroupSearchViewsKey = ({ | ||
orgSlug, | ||
}: FetchGroupSearchViewsParameters) => | ||
[`/organizations/${orgSlug}/group-search-views/`] as const; | ||
|
||
export const useFetchGroupSearchViewsForOrg = ( | ||
{orgSlug}: FetchGroupSearchViewsParameters, | ||
options: Partial<UseApiQueryOptions<FetchGroupSearchViewsResponse>> = {} | ||
) => { | ||
return useApiQuery<FetchGroupSearchViewsResponse>( | ||
makeFetchGroupSearchViewsKey({orgSlug}), | ||
{ | ||
staleTime: Infinity, | ||
...options, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters