spanDescriptionCell.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <WiderHovercard
  52. position="right"
  53. body={
  54. <FullSpanDescription
  55. group={group}
  56. shortDescription={rawDescription}
  57. language="sql"
  58. />
  59. }
  60. >
  61. {descriptionLink}
  62. </WiderHovercard>
  63. );
  64. }
  65. if (moduleName === ModuleName.HTTP) {
  66. return (
  67. <WiderHovercard
  68. position="right"
  69. body={
  70. <Fragment>
  71. <TitleWrapper>{t('Example')}</TitleWrapper>
  72. <FullSpanDescription
  73. group={group}
  74. shortDescription={rawDescription}
  75. language="http"
  76. filters={spanOp ? {[SPAN_OP]: spanOp} : undefined}
  77. />
  78. </Fragment>
  79. }
  80. >
  81. {descriptionLink}
  82. </WiderHovercard>
  83. );
  84. }
  85. return descriptionLink;
  86. }
  87. const NULL_DESCRIPTION = <span>&lt;null&gt;</span>;
  88. export const WiderHovercard = styled(
  89. ({children, className, ...props}: React.ComponentProps<typeof Hovercard>) => (
  90. <Hovercard
  91. className={(className ?? '') + ' wider'}
  92. containerDisplayMode="inline-flex"
  93. {...props}
  94. >
  95. {children}
  96. </Hovercard>
  97. )
  98. )`
  99. &.wider {
  100. width: auto;
  101. max-width: 550px;
  102. }
  103. `;
  104. const TitleWrapper = styled('div')`
  105. margin-bottom: ${space(1)};
  106. `;