useGroup.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type {Group} from 'sentry/types/group';
  2. import {
  3. type ApiQueryKey,
  4. useApiQuery,
  5. type UseApiQueryOptions,
  6. } from 'sentry/utils/queryClient';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import {useEnvironmentsFromUrl} from 'sentry/views/issueDetails/utils';
  9. type FetchGroupQueryParameters = {
  10. environments: string[];
  11. groupId: string;
  12. organizationSlug: string;
  13. };
  14. export function makeFetchGroupQueryKey({
  15. groupId,
  16. organizationSlug,
  17. environments,
  18. }: FetchGroupQueryParameters): ApiQueryKey {
  19. const query: Record<string, string | string[]> = {
  20. ...(environments.length > 0 ? {environment: environments} : {}),
  21. expand: ['inbox', 'owners'],
  22. collapse: ['release', 'tags'],
  23. };
  24. return [`/organizations/${organizationSlug}/issues/${groupId}/`, {query}];
  25. }
  26. interface UseGroupOptions {
  27. groupId: string;
  28. options?: Omit<UseApiQueryOptions<Group>, 'staleTime'>;
  29. }
  30. /**
  31. * Used to fetch group details for issue details.
  32. * Data is still synced with the GroupStore for legacy reasons.
  33. */
  34. export function useGroup({groupId, options}: UseGroupOptions) {
  35. const organization = useOrganization();
  36. const environments = useEnvironmentsFromUrl();
  37. return useApiQuery<Group>(
  38. makeFetchGroupQueryKey({organizationSlug: organization.slug, groupId, environments}),
  39. {
  40. staleTime: 30000,
  41. gcTime: 30000,
  42. retry: false,
  43. ...options,
  44. }
  45. );
  46. }