spanDescriptionCell.tsx 3.1 KB

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