domMutationRow.tsx 3.6 KB

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