spanDescriptionCell.tsx 2.7 KB

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