traceLink.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {useCallback, useContext} from 'react';
  2. import styled from '@emotion/styled';
  3. import Link from 'sentry/components/links/link';
  4. import {generateTraceTarget} from 'sentry/components/quickTrace/utils';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import {Event} from 'sentry/types';
  8. import {trackAnalytics} from 'sentry/utils/analytics';
  9. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. type TraceLinkProps = {
  12. event: Event;
  13. };
  14. export function TraceLink({event}: TraceLinkProps) {
  15. const organization = useOrganization();
  16. const quickTrace = useContext(QuickTraceContext);
  17. const handleTraceLink = useCallback(() => {
  18. trackAnalytics('quick_trace.trace_id.clicked', {
  19. organization,
  20. source: 'issues',
  21. });
  22. }, [organization]);
  23. if (
  24. !quickTrace ||
  25. quickTrace.isLoading ||
  26. quickTrace.error ||
  27. quickTrace.type === 'empty'
  28. ) {
  29. return null;
  30. }
  31. return (
  32. <StyledLink to={generateTraceTarget(event, organization)} onClick={handleTraceLink}>
  33. {t('View Full Trace')}
  34. </StyledLink>
  35. );
  36. }
  37. const StyledLink = styled(Link)`
  38. margin-left: ${space(1)};
  39. font-size: ${p => p.theme.fontSizeSmall};
  40. `;