replayCount.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import styled from '@emotion/styled';
  2. import Link from 'sentry/components/links/link';
  3. import Placeholder from 'sentry/components/placeholder';
  4. import Tooltip from 'sentry/components/tooltip';
  5. import {IconPlay} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import space from 'sentry/styles/space';
  8. import DiscoverQuery from 'sentry/utils/discover/discoverQuery';
  9. import EventView from 'sentry/utils/discover/eventView';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. type Props = {
  12. groupId: string;
  13. orgId: string;
  14. };
  15. function ReplayCount({orgId, groupId}: Props) {
  16. const location = useLocation();
  17. const eventView = EventView.fromNewQueryWithLocation(
  18. {
  19. id: '',
  20. name: `Errors within replay`,
  21. version: 2,
  22. fields: ['replayId', 'count()'],
  23. query: `issue.id:${groupId} !replayId:""`,
  24. projects: [],
  25. },
  26. location
  27. );
  28. return (
  29. <DiscoverQuery eventView={eventView} orgSlug={orgId} location={location} useEvents>
  30. {({isLoading, tableData}) => {
  31. if (isLoading) {
  32. return <Placeholder width="24px" height="14px" />;
  33. }
  34. const replayCount = tableData?.data?.length ?? 0;
  35. if (replayCount > 0) {
  36. return (
  37. <Tooltip
  38. title={t('This issue has %s replays available to view', replayCount)}
  39. >
  40. <ReplayCountLink
  41. to={`/organizations/${orgId}/issues/${groupId}/replays/`}
  42. data-test-id="replay-count"
  43. >
  44. <IconPlay size="xs" />
  45. {replayCount}
  46. </ReplayCountLink>
  47. </Tooltip>
  48. );
  49. }
  50. return null;
  51. }}
  52. </DiscoverQuery>
  53. );
  54. }
  55. const ReplayCountLink = styled(Link)`
  56. display: inline-flex;
  57. color: ${p => p.theme.gray400};
  58. font-size: ${p => p.theme.fontSizeSmall};
  59. gap: 0 ${space(0.5)};
  60. `;
  61. export default ReplayCount;