domMutationRow.tsx 3.5 KB

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