useReplayCountForIssues.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {useMemo} from 'react';
  2. import {IssueCategory} from 'sentry/types';
  3. import useReplayCount from 'sentry/utils/replayCount/useReplayCount';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. interface Props {
  6. bufferLimit?: number;
  7. statsPeriod?: string;
  8. }
  9. /**
  10. * Query results for whether an Issue/Group has replays associated.
  11. */
  12. export default function useReplayCountForIssues({
  13. bufferLimit = 25,
  14. statsPeriod = '14d',
  15. }: Props = {}) {
  16. const organization = useOrganization();
  17. const {
  18. getOne: getOneError,
  19. getMany: getManyError,
  20. hasOne: hasOneError,
  21. hasMany: hasManyError,
  22. } = useReplayCount({
  23. bufferLimit,
  24. dataSource: 'discover',
  25. fieldName: 'issue.id',
  26. organization,
  27. statsPeriod,
  28. });
  29. const {
  30. getOne: getOneIssue,
  31. getMany: getManyIssue,
  32. hasOne: hasOneIssue,
  33. hasMany: hasManyIssue,
  34. } = useReplayCount({
  35. bufferLimit,
  36. dataSource: 'search_issues',
  37. fieldName: 'issue.id',
  38. organization,
  39. statsPeriod,
  40. });
  41. return useMemo(
  42. () => ({
  43. getReplayCountForIssue: (id: string, category: IssueCategory) =>
  44. category === IssueCategory.ERROR ? getOneError(id) : getOneIssue(id),
  45. getReplayCountForIssues: (id: readonly string[], category: IssueCategory) =>
  46. category === IssueCategory.ERROR ? getManyError(id) : getManyIssue(id),
  47. issueHasReplay: (id: string, category: IssueCategory) =>
  48. category === IssueCategory.ERROR ? hasOneError(id) : hasOneIssue(id),
  49. issuesHaveReplay: (id: readonly string[], category: IssueCategory) =>
  50. category === IssueCategory.ERROR ? hasManyError(id) : hasManyIssue(id),
  51. }),
  52. [
  53. getManyError,
  54. getManyIssue,
  55. getOneError,
  56. getOneIssue,
  57. hasManyError,
  58. hasManyIssue,
  59. hasOneError,
  60. hasOneIssue,
  61. ]
  62. );
  63. }