issueReplayCount.tsx 1.6 KB

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