breadcrumbRow.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type {CSSProperties, MouseEvent} from 'react';
  2. import {useCallback} from 'react';
  3. import classNames from 'classnames';
  4. import BreadcrumbItem from 'sentry/components/replays/breadcrumbs/breadcrumbItem';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import type {Extraction} from 'sentry/utils/replays/extractHtml';
  7. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  8. import useCurrentHoverTime from 'sentry/utils/replays/playback/providers/useCurrentHoverTime';
  9. import type {ReplayFrame} from 'sentry/utils/replays/types';
  10. interface Props {
  11. extraction: Extraction | undefined;
  12. frame: ReplayFrame;
  13. index: number;
  14. onClick: ReturnType<typeof useCrumbHandlers>['onClickTimestamp'];
  15. onInspectorExpanded: (
  16. index: number,
  17. path: string,
  18. expandedState: Record<string, boolean>,
  19. event: MouseEvent<HTMLDivElement>
  20. ) => void;
  21. startTimestampMs: number;
  22. style: CSSProperties;
  23. breadcrumbIndex?: number[][];
  24. expandPaths?: string[];
  25. }
  26. export default function BreadcrumbRow({
  27. expandPaths,
  28. extraction,
  29. frame,
  30. index,
  31. onClick,
  32. onInspectorExpanded,
  33. startTimestampMs,
  34. style,
  35. }: Props) {
  36. const {currentTime} = useReplayContext();
  37. const [currentHoverTime] = useCurrentHoverTime();
  38. const {onMouseEnter, onMouseLeave} = useCrumbHandlers();
  39. const handleObjectInspectorExpanded = useCallback(
  40. (path, expandedState, e) => onInspectorExpanded?.(index, path, expandedState, e),
  41. [index, onInspectorExpanded]
  42. );
  43. const hasOccurred = currentTime >= frame.offsetMs;
  44. const isBeforeHover =
  45. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  46. return (
  47. <BreadcrumbItem
  48. className={classNames({
  49. beforeCurrentTime: hasOccurred,
  50. afterCurrentTime: !hasOccurred,
  51. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  52. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  53. })}
  54. style={style}
  55. frame={frame}
  56. extraction={extraction}
  57. onClick={onClick}
  58. onMouseEnter={onMouseEnter}
  59. onMouseLeave={onMouseLeave}
  60. startTimestampMs={startTimestampMs}
  61. expandPaths={expandPaths}
  62. onInspectorExpanded={handleObjectInspectorExpanded}
  63. />
  64. );
  65. }