breadcrumbRow.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. export default function BreadcrumbRow({
  30. expandPaths,
  31. extraction,
  32. frame,
  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) => onInspectorExpanded?.(index, path, expandedState, e),
  49. [index, onInspectorExpanded]
  50. );
  51. const hasOccurred = currentTime >= frame.offsetMs;
  52. const isBeforeHover =
  53. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  54. return (
  55. <StyledTimeBorder
  56. className={classNames({
  57. beforeCurrentTime: hasOccurred,
  58. afterCurrentTime: !hasOccurred,
  59. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  60. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  61. })}
  62. style={style}
  63. >
  64. <BreadcrumbItem
  65. frame={frame}
  66. traces={traces}
  67. extraction={extraction}
  68. onClick={onClick}
  69. onMouseEnter={onMouseEnter}
  70. onMouseLeave={onMouseLeave}
  71. startTimestampMs={startTimestampMs}
  72. expandPaths={expandPaths}
  73. onDimensionChange={handleDimensionChange}
  74. onInspectorExpanded={handleObjectInspectorExpanded}
  75. />
  76. </StyledTimeBorder>
  77. );
  78. }
  79. const StyledTimeBorder = styled('div')`
  80. /* Overridden in TabItemContainer, depending on *CurrentTime and *HoverTime classes */
  81. border-top: 1px solid transparent;
  82. border-bottom: 1px solid transparent;
  83. `;