packageLink.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import styled from '@emotion/styled';
  2. import {trimPackage} from 'sentry/components/events/interfaces/frame/utils';
  3. import {Tooltip} from 'sentry/components/tooltip';
  4. import {SLOW_TOOLTIP_DELAY} from 'sentry/constants';
  5. import {space} from 'sentry/styles/space';
  6. import {defined} from 'sentry/utils';
  7. type Props = {
  8. includeSystemFrames: boolean;
  9. onClick: (event: React.MouseEvent<HTMLAnchorElement>) => void;
  10. packagePath: string | null;
  11. withLeadHint: boolean;
  12. isClickable?: boolean;
  13. /**
  14. * Is the stack trace being previewed in a hovercard?
  15. */
  16. isHoverPreviewed?: boolean;
  17. };
  18. function PackageLink({
  19. children,
  20. includeSystemFrames,
  21. isClickable,
  22. isHoverPreviewed,
  23. onClick,
  24. packagePath,
  25. withLeadHint,
  26. }) {
  27. const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
  28. if (isClickable) {
  29. onClick(event);
  30. }
  31. };
  32. return (
  33. <Package
  34. onClick={handleClick}
  35. isClickable={isClickable}
  36. withLeadHint={withLeadHint}
  37. includeSystemFrames={includeSystemFrames}
  38. >
  39. {defined(packagePath) ? (
  40. <Tooltip
  41. title={packagePath}
  42. delay={isHoverPreviewed ? SLOW_TOOLTIP_DELAY : undefined}
  43. >
  44. <PackageName
  45. isClickable={isClickable}
  46. withLeadHint={withLeadHint}
  47. includeSystemFrames={includeSystemFrames}
  48. >
  49. {trimPackage(packagePath)}
  50. </PackageName>
  51. </Tooltip>
  52. ) : (
  53. <span>{'<unknown>'}</span>
  54. )}
  55. {children}
  56. </Package>
  57. );
  58. }
  59. export const Package = styled('a')<Partial<Props>>`
  60. font-size: 13px;
  61. font-weight: ${p => p.theme.fontWeightBold};
  62. padding: 0 0 0 ${space(0.5)};
  63. color: ${p => p.theme.textColor};
  64. :hover {
  65. color: ${p => p.theme.textColor};
  66. }
  67. cursor: ${p => (p.isClickable ? 'pointer' : 'default')};
  68. display: flex;
  69. align-items: center;
  70. ${p =>
  71. p.withLeadHint && (p.includeSystemFrames ? `max-width: 89px;` : `max-width: 76px;`)}
  72. @media (min-width: ${p => p.theme.breakpoints.large}) and (max-width: ${p =>
  73. p.theme.breakpoints.xlarge}) {
  74. ${p =>
  75. p.withLeadHint && (p.includeSystemFrames ? `max-width: 76px;` : `max-width: 63px;`)}
  76. }
  77. `;
  78. export const PackageName = styled('span')<
  79. Pick<Props, 'isClickable' | 'withLeadHint' | 'includeSystemFrames'>
  80. >`
  81. max-width: ${p =>
  82. p.withLeadHint && p.isClickable && !p.includeSystemFrames ? '45px' : '104px'};
  83. ${p => p.theme.overflowEllipsis}
  84. `;
  85. export default PackageLink;