viewReplayLink.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {ComponentProps, ReactNode, ReactText, 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 {t} from 'sentry/locale';
  7. function ViewReplayLink({
  8. children,
  9. replayId,
  10. to,
  11. }: {
  12. children: ReactNode;
  13. replayId: ReactText | string;
  14. to: ComponentProps<typeof Link>['to'];
  15. }) {
  16. const count = useContext(ReplayCountContext)[replayId] || 0;
  17. if (count < 1) {
  18. return (
  19. <Tooltip title={t('This replay may have been rate limited or deleted.')}>
  20. <EmptyValueContainer>{t('(missing)')}</EmptyValueContainer>
  21. </Tooltip>
  22. );
  23. }
  24. return (
  25. <Tooltip title={t('View Replay')}>
  26. <StyledLink to={to}>{children}</StyledLink>
  27. </Tooltip>
  28. );
  29. }
  30. const StyledLink = styled(Link)`
  31. & div {
  32. display: inline;
  33. }
  34. `;
  35. const EmptyValueContainer = styled('span')`
  36. color: ${p => p.theme.gray300};
  37. `;
  38. export default ViewReplayLink;