useIssueDetailsDiscoverQuery.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {getInterval} from 'sentry/components/charts/utils';
  2. import type {Group} from 'sentry/types/group';
  3. import type {NewQuery, SavedQuery} from 'sentry/types/organization';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import {
  6. type DiscoverQueryProps,
  7. useGenericDiscoverQuery,
  8. } from 'sentry/utils/discover/genericDiscoverQuery';
  9. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  10. import {getPeriod} from 'sentry/utils/duration/getPeriod';
  11. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  12. import {useLocation} from 'sentry/utils/useLocation';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import usePageFilters from 'sentry/utils/usePageFilters';
  15. import {useEventQuery} from 'sentry/views/issueDetails/streamline/eventSearch';
  16. export function useIssueDetailsEventView({
  17. group,
  18. queryProps,
  19. }: {
  20. group: Group;
  21. queryProps?: Partial<SavedQuery>;
  22. }) {
  23. const {selection: pageFilters} = usePageFilters();
  24. const searchQuery = useEventQuery({group});
  25. const periodQuery = getPeriod(pageFilters.datetime);
  26. const interval = getInterval(pageFilters.datetime, 'metrics');
  27. const config = getConfigForIssueType(group, group.project);
  28. const query = [`issue:${group.shortId}`, searchQuery]
  29. .filter(s => s.length > 0)
  30. .join(' ');
  31. const discoverQuery: NewQuery = {
  32. ...periodQuery,
  33. interval,
  34. environment: pageFilters.environments,
  35. dataset: config.usesIssuePlatform
  36. ? DiscoverDatasets.ISSUE_PLATFORM
  37. : DiscoverDatasets.ERRORS,
  38. version: 2,
  39. projects: [Number(group.project.id)],
  40. range: periodQuery.statsPeriod,
  41. yAxis: ['count()', 'count_unique(user)'],
  42. fields: ['title', 'release', 'environment', 'user.display', 'timestamp'],
  43. name: group.title || group.type,
  44. ...queryProps,
  45. query,
  46. };
  47. return EventView.fromSavedQuery(discoverQuery);
  48. }
  49. export function useIssueDetailsDiscoverQuery<T>({
  50. params: {eventView, route, referrer},
  51. options,
  52. }: {
  53. params: {
  54. eventView: EventView;
  55. referrer: string;
  56. route: string;
  57. };
  58. options?: DiscoverQueryProps['options'];
  59. }) {
  60. const organization = useOrganization();
  61. const location = useLocation();
  62. return useGenericDiscoverQuery<T, DiscoverQueryProps>({
  63. route,
  64. eventView,
  65. location,
  66. orgSlug: organization.slug,
  67. getRequestPayload: () => ({
  68. ...eventView.getEventsAPIPayload(location),
  69. query: eventView.query,
  70. interval: eventView.interval,
  71. yAxis: eventView.yAxis,
  72. partial: 1,
  73. // Cursor on issue details can be used for other pagination
  74. cursor: undefined,
  75. }),
  76. options,
  77. referrer,
  78. });
  79. }