spanEvidencePreview.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {ReactChild, useEffect} from 'react';
  2. import styled from '@emotion/styled';
  3. import {SpanEvidenceKeyValueList} from 'sentry/components/events/interfaces/performance/spanEvidenceKeyValueList';
  4. import {GroupPreviewHovercard} from 'sentry/components/groupPreviewTooltip/groupPreviewHovercard';
  5. import {
  6. useDelayedLoadingState,
  7. usePreviewEvent,
  8. } from 'sentry/components/groupPreviewTooltip/utils';
  9. import LoadingIndicator from 'sentry/components/loadingIndicator';
  10. import {t} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {EventTransaction} from 'sentry/types';
  13. type SpanEvidencePreviewProps = {
  14. children: ReactChild;
  15. groupId: string;
  16. query?: string;
  17. };
  18. type SpanEvidencePreviewBodyProps = {
  19. groupId: string;
  20. onRequestBegin: () => void;
  21. onRequestEnd: () => void;
  22. onUnmount: () => void;
  23. query?: string;
  24. };
  25. function SpanEvidencePreviewBody({
  26. groupId,
  27. onRequestBegin,
  28. onRequestEnd,
  29. onUnmount,
  30. query,
  31. }: SpanEvidencePreviewBodyProps) {
  32. const {data, isLoading, isError} = usePreviewEvent<EventTransaction>({
  33. groupId,
  34. query,
  35. });
  36. useEffect(() => {
  37. if (isLoading) {
  38. onRequestBegin();
  39. } else {
  40. onRequestEnd();
  41. }
  42. return onUnmount;
  43. }, [isLoading, onRequestBegin, onRequestEnd, onUnmount]);
  44. if (isLoading) {
  45. return (
  46. <EmptyWrapper>
  47. <LoadingIndicator hideMessage size={32} />
  48. </EmptyWrapper>
  49. );
  50. }
  51. if (isError) {
  52. return <EmptyWrapper>{t('Failed to load preview')}</EmptyWrapper>;
  53. }
  54. if (data) {
  55. return (
  56. <SpanEvidencePreviewWrapper data-test-id="span-evidence-preview-body">
  57. <SpanEvidenceKeyValueList event={data} />
  58. </SpanEvidencePreviewWrapper>
  59. );
  60. }
  61. return (
  62. <EmptyWrapper>
  63. {t('There is no span evidence available for this issue.')}
  64. </EmptyWrapper>
  65. );
  66. }
  67. export function SpanEvidencePreview({
  68. children,
  69. groupId,
  70. query,
  71. }: SpanEvidencePreviewProps) {
  72. const {shouldShowLoadingState, onRequestBegin, onRequestEnd, reset} =
  73. useDelayedLoadingState();
  74. return (
  75. <GroupPreviewHovercard
  76. hide={!shouldShowLoadingState}
  77. body={
  78. <SpanEvidencePreviewBody
  79. onRequestBegin={onRequestBegin}
  80. onRequestEnd={onRequestEnd}
  81. onUnmount={reset}
  82. groupId={groupId}
  83. query={query}
  84. />
  85. }
  86. >
  87. {children}
  88. </GroupPreviewHovercard>
  89. );
  90. }
  91. const EmptyWrapper = styled('div')`
  92. color: ${p => p.theme.subText};
  93. padding: ${space(1.5)};
  94. font-size: ${p => p.theme.fontSizeMedium};
  95. display: flex;
  96. align-items: center;
  97. justify-content: center;
  98. min-height: 56px;
  99. `;
  100. const SpanEvidencePreviewWrapper = styled('div')`
  101. width: 700px;
  102. padding: ${space(1.5)} ${space(1.5)} 0 ${space(1.5)};
  103. `;