domMutationRow.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import {CSSProperties, useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import classNames from 'classnames';
  4. import beautify from 'js-beautify';
  5. import {CodeSnippet} from 'sentry/components/codeSnippet';
  6. import BreadcrumbIcon from 'sentry/components/events/interfaces/breadcrumbs/breadcrumb/type/icon';
  7. import {space} from 'sentry/styles/space';
  8. import type {Extraction} from 'sentry/utils/replays/extractDomNodes';
  9. import getFrameDetails from 'sentry/utils/replays/getFrameDetails';
  10. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  11. import IconWrapper from 'sentry/views/replays/detail/iconWrapper';
  12. import TimestampButton from 'sentry/views/replays/detail/timestampButton';
  13. type Props = {
  14. currentHoverTime: number | undefined;
  15. currentTime: number;
  16. mutation: Extraction;
  17. startTimestampMs: number;
  18. style: CSSProperties;
  19. };
  20. function DomMutationRow({
  21. currentHoverTime,
  22. currentTime,
  23. mutation,
  24. startTimestampMs,
  25. style,
  26. }: Props) {
  27. const {html, frame: breadcrumb} = mutation;
  28. const {handleMouseEnter, handleMouseLeave, handleClick} =
  29. useCrumbHandlers(startTimestampMs);
  30. const onClickTimestamp = useCallback(
  31. () => handleClick(breadcrumb),
  32. [handleClick, breadcrumb]
  33. );
  34. const onMouseEnter = useCallback(
  35. () => handleMouseEnter(breadcrumb),
  36. [handleMouseEnter, breadcrumb]
  37. );
  38. const onMouseLeave = useCallback(
  39. () => handleMouseLeave(breadcrumb),
  40. [handleMouseLeave, breadcrumb]
  41. );
  42. const hasOccurred = currentTime >= breadcrumb.offsetMs;
  43. const isBeforeHover =
  44. currentHoverTime === undefined || currentHoverTime >= breadcrumb.offsetMs;
  45. const {color, title, type} = getFrameDetails(breadcrumb);
  46. return (
  47. <MutationListItem
  48. className={classNames({
  49. beforeCurrentTime: hasOccurred,
  50. afterCurrentTime: !hasOccurred,
  51. beforeHoverTime: currentHoverTime !== undefined && isBeforeHover,
  52. afterHoverTime: currentHoverTime !== undefined && !isBeforeHover,
  53. })}
  54. onMouseEnter={onMouseEnter}
  55. onMouseLeave={onMouseLeave}
  56. style={style}
  57. >
  58. <IconWrapper color={color} hasOccurred={hasOccurred}>
  59. <BreadcrumbIcon type={type} />
  60. </IconWrapper>
  61. <List>
  62. <Row>
  63. <Title hasOccurred={hasOccurred}>{title}</Title>
  64. <TimestampButton
  65. onClick={onClickTimestamp}
  66. startTimestampMs={startTimestampMs}
  67. timestampMs={breadcrumb.timestampMs}
  68. />
  69. </Row>
  70. {/* @ts-expect-error */}
  71. <Selector>{breadcrumb.message ?? ''}</Selector>
  72. <CodeContainer>
  73. <CodeSnippet language="html" hideCopyButton>
  74. {beautify.html(html, {indent_size: 2})}
  75. </CodeSnippet>
  76. </CodeContainer>
  77. </List>
  78. </MutationListItem>
  79. );
  80. }
  81. const MutationListItem = styled('div')`
  82. display: flex;
  83. gap: ${space(1)};
  84. padding: ${space(1)} ${space(1.5)};
  85. /* Overridden in TabItemContainer, depending on *CurrentTime and *HoverTime classes */
  86. border-top: 1px solid transparent;
  87. border-bottom: 1px solid transparent;
  88. `;
  89. const List = styled('div')`
  90. display: flex;
  91. flex-direction: column;
  92. overflow: hidden;
  93. width: 100%;
  94. `;
  95. const Row = styled('div')`
  96. display: flex;
  97. flex-direction: row;
  98. font-size: ${p => p.theme.fontSizeSmall};
  99. `;
  100. const Title = styled('span')<{hasOccurred?: boolean}>`
  101. color: ${p => (p.hasOccurred ? p.theme.gray400 : p.theme.gray300)};
  102. font-size: ${p => p.theme.fontSizeMedium};
  103. font-weight: bold;
  104. line-height: ${p => p.theme.text.lineHeightBody};
  105. text-transform: capitalize;
  106. ${p => p.theme.overflowEllipsis};
  107. `;
  108. const Selector = styled('p')`
  109. color: ${p => p.theme.gray300};
  110. font-size: ${p => p.theme.fontSizeSmall};
  111. margin-bottom: 0;
  112. `;
  113. const CodeContainer = styled('div')`
  114. margin-top: ${space(1)};
  115. max-height: 400px;
  116. max-width: 100%;
  117. overflow: auto;
  118. `;
  119. export default DomMutationRow;