replayBadge.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {LinkButton} from 'sentry/components/button';
  4. import {IconPlay} from 'sentry/icons';
  5. import {t, tn} from 'sentry/locale';
  6. import type {Group} from 'sentry/types/group';
  7. import type {Project} from 'sentry/types/project';
  8. import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
  9. import useReplayCountForIssues from 'sentry/utils/replayCount/useReplayCountForIssues';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import {Divider} from 'sentry/views/issueDetails/divider';
  12. import {Tab, TabPaths} from 'sentry/views/issueDetails/types';
  13. import {useGroupDetailsRoute} from 'sentry/views/issueDetails/useGroupDetailsRoute';
  14. export function ReplayBadge({group, project}: {group: Group; project: Project}) {
  15. const {baseUrl} = useGroupDetailsRoute();
  16. const location = useLocation();
  17. const issueTypeConfig = getConfigForIssueType(group, project);
  18. const {getReplayCountForIssue} = useReplayCountForIssues({
  19. statsPeriod: '90d',
  20. });
  21. const replaysCount = getReplayCountForIssue(group.id, group.issueCategory) ?? 0;
  22. if (!issueTypeConfig.replays.enabled || replaysCount <= 0) {
  23. return null;
  24. }
  25. return (
  26. <Fragment>
  27. <Divider />
  28. <ReplayButton
  29. type="button"
  30. priority="link"
  31. size="zero"
  32. icon={<IconPlay size="xs" />}
  33. to={{
  34. pathname: `${baseUrl}${TabPaths[Tab.REPLAYS]}`,
  35. query: location.query,
  36. replace: true,
  37. }}
  38. aria-label={t("View this issue's replays")}
  39. >
  40. {replaysCount > 50
  41. ? t('50+ Replays')
  42. : tn('%s Replay', '%s Replays', replaysCount)}
  43. </ReplayButton>
  44. </Fragment>
  45. );
  46. }
  47. const ReplayButton = styled(LinkButton)`
  48. color: ${p => p.theme.gray300};
  49. text-decoration: underline;
  50. text-decoration-style: dotted;
  51. `;