spanDescriptionCell.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {Fragment, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Hovercard} from 'sentry/components/hovercard';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import {FullSpanDescription} from 'sentry/views/starfish/components/fullSpanDescription';
  7. import {SpanDescriptionLink} from 'sentry/views/starfish/components/spanDescriptionLink';
  8. import {ModuleName} from 'sentry/views/starfish/types';
  9. import {SQLishFormatter} from 'sentry/views/starfish/utils/sqlish/SQLishFormatter';
  10. const formatter = new SQLishFormatter();
  11. interface Props {
  12. description: string;
  13. moduleName: ModuleName;
  14. projectId: number;
  15. endpoint?: string;
  16. endpointMethod?: string;
  17. group?: string;
  18. }
  19. export function SpanDescriptionCell({
  20. description: rawDescription,
  21. group,
  22. moduleName,
  23. endpoint,
  24. endpointMethod,
  25. projectId,
  26. }: Props) {
  27. const formatterDescription = useMemo(() => {
  28. if (moduleName !== ModuleName.DB) {
  29. return rawDescription;
  30. }
  31. return formatter.toSimpleMarkup(rawDescription);
  32. }, [moduleName, rawDescription]);
  33. if (!rawDescription) {
  34. return NULL_DESCRIPTION;
  35. }
  36. const descriptionLink = (
  37. <SpanDescriptionLink
  38. group={group}
  39. projectId={projectId}
  40. endpoint={endpoint}
  41. endpointMethod={endpointMethod}
  42. description={formatterDescription}
  43. />
  44. );
  45. if (moduleName === ModuleName.DB) {
  46. return (
  47. <DescriptionWrapper>
  48. <WiderHovercard
  49. position="right"
  50. body={
  51. <FullSpanDescription
  52. group={group}
  53. shortDescription={rawDescription}
  54. language="sql"
  55. />
  56. }
  57. >
  58. {descriptionLink}
  59. </WiderHovercard>
  60. </DescriptionWrapper>
  61. );
  62. }
  63. if (moduleName === ModuleName.HTTP) {
  64. return (
  65. <DescriptionWrapper>
  66. <WiderHovercard
  67. position="right"
  68. body={
  69. <Fragment>
  70. <TitleWrapper>{t('Example')}</TitleWrapper>
  71. <FullSpanDescription
  72. group={group}
  73. shortDescription={rawDescription}
  74. language="http"
  75. />
  76. </Fragment>
  77. }
  78. >
  79. {descriptionLink}
  80. </WiderHovercard>
  81. </DescriptionWrapper>
  82. );
  83. }
  84. return descriptionLink;
  85. }
  86. const NULL_DESCRIPTION = <span>&lt;null&gt;</span>;
  87. export const WiderHovercard = styled(
  88. ({
  89. children,
  90. className,
  91. containerClassName,
  92. ...props
  93. }: React.ComponentProps<typeof Hovercard>) => (
  94. <Hovercard
  95. className={(className ?? '') + ' wider'}
  96. containerClassName={(containerClassName ?? '') + ' inline-flex'}
  97. {...props}
  98. >
  99. {children}
  100. </Hovercard>
  101. )
  102. )`
  103. &.wider {
  104. width: auto;
  105. max-width: 550px;
  106. }
  107. `;
  108. const TitleWrapper = styled('div')`
  109. margin-bottom: ${space(1)};
  110. `;
  111. const DescriptionWrapper = styled('div')`
  112. .inline-flex {
  113. display: inline-flex;
  114. }
  115. `;