spanDescriptionCell.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {Fragment} 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. moduleName: ModuleName;
  13. projectId: number;
  14. description?: string;
  15. endpoint?: string;
  16. endpointMethod?: string;
  17. group?: string;
  18. }
  19. export function SpanDescriptionCell({
  20. description,
  21. group,
  22. moduleName,
  23. endpoint,
  24. endpointMethod,
  25. projectId,
  26. }: Props) {
  27. if (!description) {
  28. return NULL_DESCRIPTION;
  29. }
  30. const descriptionLink = (
  31. <SpanDescriptionLink
  32. group={group}
  33. projectId={projectId}
  34. endpoint={endpoint}
  35. endpointMethod={endpointMethod}
  36. description={
  37. moduleName === ModuleName.DB ? formatter.toSimpleMarkup(description) : description
  38. }
  39. />
  40. );
  41. if (moduleName === ModuleName.DB) {
  42. return (
  43. <DescriptionWrapper>
  44. <WiderHovercard
  45. position="right"
  46. body={
  47. <FullSpanDescription
  48. group={group}
  49. shortDescription={description}
  50. language="sql"
  51. />
  52. }
  53. >
  54. {descriptionLink}
  55. </WiderHovercard>
  56. </DescriptionWrapper>
  57. );
  58. }
  59. if (moduleName === ModuleName.HTTP) {
  60. return (
  61. <DescriptionWrapper>
  62. <WiderHovercard
  63. position="right"
  64. body={
  65. <Fragment>
  66. <TitleWrapper>{t('Example')}</TitleWrapper>
  67. <FullSpanDescription
  68. group={group}
  69. shortDescription={description}
  70. language="http"
  71. />
  72. </Fragment>
  73. }
  74. >
  75. {descriptionLink}
  76. </WiderHovercard>
  77. </DescriptionWrapper>
  78. );
  79. }
  80. return descriptionLink;
  81. }
  82. const NULL_DESCRIPTION = <span>&lt;null&gt;</span>;
  83. export const WiderHovercard = styled(
  84. ({
  85. children,
  86. className,
  87. containerClassName,
  88. ...props
  89. }: React.ComponentProps<typeof Hovercard>) => (
  90. <Hovercard
  91. className={(className ?? '') + ' wider'}
  92. containerClassName={(containerClassName ?? '') + ' 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. `;
  107. const DescriptionWrapper = styled('div')`
  108. .inline-flex {
  109. display: inline-flex;
  110. }
  111. `;