packageLink.tsx 2.7 KB

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