issueReplayCount.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import styled from '@emotion/styled';
  2. import Link from 'sentry/components/links/link';
  3. import {Tooltip} from 'sentry/components/tooltip';
  4. import {IconPlay} from 'sentry/icons';
  5. import {t, tn} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Group} from 'sentry/types/group';
  8. import useReplayCountForIssues from 'sentry/utils/replayCount/useReplayCountForIssues';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  11. interface Props {
  12. group: Group;
  13. }
  14. /**
  15. * Show the count of how many replays are associated to an issue.
  16. */
  17. function IssueReplayCount({group}: Props) {
  18. const organization = useOrganization();
  19. const {getReplayCountForIssue} = useReplayCountForIssues();
  20. const count = getReplayCountForIssue(group.id, group.issueCategory);
  21. if (count === undefined || count === 0) {
  22. return null;
  23. }
  24. const countDisplay = count > 50 ? '50+' : count;
  25. const titleOver50 = t('This issue has 50+ replay available to view');
  26. const title50OrLess = tn(
  27. 'This issue has %s replay available to view',
  28. 'This issue has %s replays available to view',
  29. count
  30. );
  31. return (
  32. <Tooltip title={count > 50 ? titleOver50 : title50OrLess}>
  33. <ReplayCountLink
  34. to={normalizeUrl(
  35. `/organizations/${organization.slug}/issues/${group.id}/replays/`
  36. )}
  37. aria-label={t('replay-count')}
  38. >
  39. <IconPlay size="xs" />
  40. {countDisplay}
  41. </ReplayCountLink>
  42. </Tooltip>
  43. );
  44. }
  45. const ReplayCountLink = styled(Link)`
  46. display: inline-flex;
  47. color: ${p => p.theme.gray400};
  48. font-size: ${p => p.theme.fontSizeSmall};
  49. gap: 0 ${space(0.5)};
  50. `;
  51. export default IssueReplayCount;