traceLink.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 {trackAnalyticsEvent} 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. trackAnalyticsEvent({
  19. eventKey: 'quick_trace.trace_id.clicked',
  20. eventName: 'Quick Trace: Trace ID clicked',
  21. organization_id: parseInt(organization.id, 10),
  22. source: 'issues',
  23. });
  24. }, [organization.id]);
  25. if (
  26. !quickTrace ||
  27. quickTrace.isLoading ||
  28. quickTrace.error ||
  29. quickTrace.type === 'empty'
  30. ) {
  31. return null;
  32. }
  33. return (
  34. <LinkContainer>
  35. <Link to={generateTraceTarget(event, organization)} onClick={handleTraceLink}>
  36. {t('View Full Trace')}
  37. </Link>
  38. </LinkContainer>
  39. );
  40. }
  41. const LinkContainer = styled('span')`
  42. margin-left: ${space(1)};
  43. padding-left: ${space(1)};
  44. position: relative;
  45. &:before {
  46. display: block;
  47. position: absolute;
  48. content: '';
  49. left: 0;
  50. top: 2px;
  51. height: 14px;
  52. border-left: 1px solid ${p => p.theme.border};
  53. }
  54. `;