breadcrumbRow.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import type {CSSProperties, MouseEvent} from 'react';
  2. import {useCallback} from 'react';
  3. import styled from '@emotion/styled';
  4. import classNames from 'classnames';
  5. import BreadcrumbItem from 'sentry/components/replays/breadcrumbs/breadcrumbItem';
  6. import {useReplayContext} from 'sentry/components/replays/replayContext';
  7. import type {Extraction} from 'sentry/utils/replays/extractDomNodes';
  8. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  9. import type {ReplayFrame} from 'sentry/utils/replays/types';
  10. import type {ReplayTraceRow} from 'sentry/views/replays/detail/perfTable/useReplayPerfData';
  11. interface Props {
  12. extraction: Extraction | undefined;
  13. frame: ReplayFrame;
  14. index: number;
  15. onClick: ReturnType<typeof useCrumbHandlers>['onClickTimestamp'];
  16. onDimensionChange: (index: number) => void;
  17. onInspectorExpanded: (
  18. index: number,
  19. path: string,
  20. expandedState: Record<string, boolean>,
  21. event: MouseEvent<HTMLDivElement>
  22. ) => void;
  23. startTimestampMs: number;
  24. style: CSSProperties;
  25. traces: ReplayTraceRow | undefined;
  26. breadcrumbIndex?: number[][];
  27. expandPaths?: string[];
  28. }
  29. function BreadcrumbRow({
  30. expandPaths,
  31. frame,
  32. extraction,
  33. index,
  34. onClick,
  35. onDimensionChange,
  36. onInspectorExpanded,
  37. startTimestampMs,
  38. style,
  39. traces,
  40. }: Props) {
  41. const {currentTime, currentHoverTime} = useReplayContext();
  42. const {onMouseEnter, onMouseLeave} = useCrumbHandlers();
  43. const handleDimensionChange = useCallback(
  44. () => onDimensionChange(index),
  45. [onDimensionChange, index]
  46. );
  47. const handleObjectInspectorExpanded = useCallback(
  48. (path, expandedState, e) =>
  49. onInspectorExpanded && onInspectorExpanded(index, path, expandedState, e),
  50. [index, onInspectorExpanded]
  51. );
  52. const hasOccurred = currentTime >= frame.offsetMs;
  53. const isBeforeHover =
  54. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  55. return (
  56. <StyledTimeBorder
  57. className={classNames({
  58. beforeCurrentTime: hasOccurred,
  59. afterCurrentTime: !hasOccurred,
  60. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  61. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  62. })}
  63. style={style}
  64. >
  65. <BreadcrumbItem
  66. frame={frame}
  67. traces={traces}
  68. extraction={extraction}
  69. onClick={onClick}
  70. onMouseEnter={onMouseEnter}
  71. onMouseLeave={onMouseLeave}
  72. startTimestampMs={startTimestampMs}
  73. expandPaths={expandPaths}
  74. onDimensionChange={handleDimensionChange}
  75. onInspectorExpanded={handleObjectInspectorExpanded}
  76. />
  77. </StyledTimeBorder>
  78. );
  79. }
  80. const StyledTimeBorder = styled('div')`
  81. /* Overridden in TabItemContainer, depending on *CurrentTime and *HoverTime classes */
  82. border-top: 1px solid transparent;
  83. border-bottom: 1px solid transparent;
  84. `;
  85. export default BreadcrumbRow;