breadcrumbRow.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import type {CSSProperties} 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. ) => void;
  20. startTimestampMs: number;
  21. style: CSSProperties;
  22. breadcrumbIndex?: number[][];
  23. expandPaths?: string[];
  24. }
  25. export default function BreadcrumbRow({
  26. expandPaths,
  27. extraction,
  28. frame,
  29. index,
  30. onClick,
  31. onInspectorExpanded,
  32. startTimestampMs,
  33. style,
  34. }: Props) {
  35. const {currentTime} = useReplayContext();
  36. const [currentHoverTime] = useCurrentHoverTime();
  37. const {onMouseEnter, onMouseLeave} = useCrumbHandlers();
  38. const handleObjectInspectorExpanded = useCallback(
  39. (path, expandedState) => onInspectorExpanded?.(index, path, expandedState),
  40. [index, onInspectorExpanded]
  41. );
  42. const hasOccurred = currentTime >= frame.offsetMs;
  43. const isBeforeHover =
  44. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  45. return (
  46. <BreadcrumbItem
  47. className={classNames({
  48. beforeCurrentTime: hasOccurred,
  49. afterCurrentTime: !hasOccurred,
  50. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  51. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  52. })}
  53. style={style}
  54. frame={frame}
  55. extraction={extraction}
  56. onClick={onClick}
  57. onMouseEnter={onMouseEnter}
  58. onMouseLeave={onMouseLeave}
  59. startTimestampMs={startTimestampMs}
  60. expandPaths={expandPaths}
  61. onInspectorExpanded={handleObjectInspectorExpanded}
  62. />
  63. );
  64. }