contextIcon.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {lazy, Suspense} from 'react';
  2. import styled from '@emotion/styled';
  3. import {generateIconName} from 'sentry/components/events/contextSummary/utils';
  4. import LoadingMask from 'sentry/components/loadingMask';
  5. import CountTooltipContent from 'sentry/components/replays/countTooltipContent';
  6. import {Tooltip} from 'sentry/components/tooltip';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. type Props = {
  10. name: string;
  11. version: undefined | string;
  12. className?: string;
  13. showTooltip?: boolean;
  14. showVersion?: boolean;
  15. };
  16. const LazyContextIcon = lazy(
  17. () => import('sentry/components/events/contextSummary/contextIcon')
  18. );
  19. const ContextIcon = styled(
  20. ({className, name, version, showVersion, showTooltip}: Props) => {
  21. const icon = generateIconName(name, version);
  22. if (!showTooltip) {
  23. return (
  24. <Suspense fallback={<LoadingMask />}>
  25. <LazyContextIcon name={icon} size="sm" />
  26. </Suspense>
  27. );
  28. }
  29. const title = (
  30. <CountTooltipContent>
  31. <dt>{t('Name:')}</dt>
  32. <dd>{name}</dd>
  33. {version ? <dt>{t('Version:')}</dt> : null}
  34. {version ? <dd>{version}</dd> : null}
  35. </CountTooltipContent>
  36. );
  37. return (
  38. <Tooltip title={title} className={className}>
  39. <Suspense fallback={<LoadingMask />}>
  40. <LazyContextIcon name={icon} size="sm" />
  41. </Suspense>
  42. {showVersion ? (version ? version : null) : undefined}
  43. </Tooltip>
  44. );
  45. }
  46. )`
  47. display: flex;
  48. gap: ${space(1)};
  49. font-variant-numeric: tabular-nums;
  50. align-items: center;
  51. `;
  52. export default ContextIcon;