useEventsStatsQuery.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {EventsStats, MultiSeriesEventsStats} from 'sentry/types';
  2. import EventView, {encodeSort} from 'sentry/utils/discover/eventView';
  3. import {
  4. DiscoverQueryProps,
  5. useGenericDiscoverQuery,
  6. } from 'sentry/utils/discover/genericDiscoverQuery';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. export function useEventsStatsQuery({
  10. eventView,
  11. enabled,
  12. initialData,
  13. referrer,
  14. }: {
  15. eventView: EventView;
  16. enabled?: boolean;
  17. initialData?: any;
  18. referrer?: string;
  19. }) {
  20. const location = useLocation();
  21. const organization = useOrganization();
  22. const {isLoading, data, isError} = useGenericDiscoverQuery<
  23. EventsStats | MultiSeriesEventsStats,
  24. DiscoverQueryProps
  25. >({
  26. route: 'events-stats',
  27. eventView,
  28. location,
  29. orgSlug: organization.slug,
  30. getRequestPayload: () => ({
  31. ...eventView.getEventsAPIPayload(location),
  32. yAxis: eventView.yAxis,
  33. topEvents: eventView.topEvents,
  34. excludeOther: 0,
  35. partial: 1,
  36. orderby: eventView.sorts?.[0] ? encodeSort(eventView.sorts?.[0]) : undefined,
  37. interval: eventView.interval,
  38. }),
  39. options: {
  40. enabled,
  41. retry: false,
  42. refetchOnWindowFocus: false,
  43. },
  44. referrer,
  45. });
  46. return {
  47. isLoading,
  48. data: isLoading && initialData ? initialData : data,
  49. isError,
  50. };
  51. }