spanDescriptionCell.tsx 2.8 KB

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