breadcrumbRow.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/extractDomNodes';
  7. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  8. import type {ReplayFrame} from 'sentry/utils/replays/types';
  9. interface Props {
  10. extraction: Extraction | undefined;
  11. frame: ReplayFrame;
  12. index: number;
  13. onClick: ReturnType<typeof useCrumbHandlers>['onClickTimestamp'];
  14. onInspectorExpanded: (
  15. index: number,
  16. path: string,
  17. expandedState: Record<string, boolean>,
  18. event: MouseEvent<HTMLDivElement>
  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, currentHoverTime} = useReplayContext();
  36. const {onMouseEnter, onMouseLeave} = useCrumbHandlers();
  37. const handleObjectInspectorExpanded = useCallback(
  38. (path, expandedState, e) => onInspectorExpanded?.(index, path, expandedState, e),
  39. [index, onInspectorExpanded]
  40. );
  41. const hasOccurred = currentTime >= frame.offsetMs;
  42. const isBeforeHover =
  43. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  44. return (
  45. <BreadcrumbItem
  46. className={classNames({
  47. beforeCurrentTime: hasOccurred,
  48. afterCurrentTime: !hasOccurred,
  49. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  50. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  51. })}
  52. style={style}
  53. frame={frame}
  54. extraction={extraction}
  55. onClick={onClick}
  56. onMouseEnter={onMouseEnter}
  57. onMouseLeave={onMouseLeave}
  58. startTimestampMs={startTimestampMs}
  59. expandPaths={expandPaths}
  60. onInspectorExpanded={handleObjectInspectorExpanded}
  61. />
  62. );
  63. }