replayBadge.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 {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. >
  39. {tn('%s Replay', '%s Replays', replaysCount)}
  40. </ReplayButton>
  41. </Fragment>
  42. );
  43. }
  44. const ReplayButton = styled(LinkButton)`
  45. color: ${p => p.theme.gray300};
  46. text-decoration: underline;
  47. text-decoration-style: dotted;
  48. `;