useFetchCrashReport.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type {Event, Group, Organization} from 'sentry/types';
  2. import {useApiQuery} from 'sentry/utils/queryClient';
  3. interface Props {
  4. crashReportId: string;
  5. organization: Organization;
  6. projectSlug: string;
  7. }
  8. export default function useFetchCrashReport({
  9. crashReportId,
  10. organization,
  11. projectSlug,
  12. }: Props) {
  13. const eventEndpoint = `/projects/${organization.slug}/${projectSlug}/events/${crashReportId}/`;
  14. const {data: eventData, isFetching: isEventFetching} = useApiQuery<Event>(
  15. [eventEndpoint],
  16. {
  17. // The default delay is starts at 1000ms and doubles with each try. That's too slow, we'll just show the error quickly instead.
  18. retryDelay: 250,
  19. staleTime: 0,
  20. }
  21. );
  22. const issueEndpoint = `/organizations/${organization.slug}/issues/${eventData?.groupID}/`;
  23. const {data: groupData, isFetching: isGroupFetching} = useApiQuery<Group>(
  24. [issueEndpoint],
  25. {
  26. enabled: Boolean(eventData?.groupID),
  27. staleTime: 0,
  28. }
  29. );
  30. return {
  31. eventData,
  32. groupData,
  33. isFetching: isEventFetching || isGroupFetching,
  34. };
  35. }