breadcrumbRow.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {CSSProperties, memo, MouseEvent, useCallback, useMemo} from 'react';
  2. import classNames from 'classnames';
  3. import BreadcrumbItem from 'sentry/components/replays/breadcrumbs/breadcrumbItem';
  4. import {useReplayContext} from 'sentry/components/replays/replayContext';
  5. import {relativeTimeInMs} from 'sentry/components/replays/utils';
  6. import type {Crumb} from 'sentry/types/breadcrumbs';
  7. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  8. interface Props {
  9. breadcrumb: Crumb;
  10. index: number;
  11. onDimensionChange: (
  12. index: number,
  13. path: string,
  14. expandedState: Record<string, boolean>,
  15. event: MouseEvent<HTMLDivElement>
  16. ) => void;
  17. startTimestampMs: number;
  18. style: CSSProperties;
  19. breadcrumbIndex?: number[][];
  20. expandPaths?: string[];
  21. }
  22. function BreadcrumbRow({
  23. breadcrumb,
  24. expandPaths,
  25. index,
  26. onDimensionChange,
  27. startTimestampMs,
  28. style,
  29. }: Props) {
  30. const {currentTime, currentHoverTime} = useReplayContext();
  31. const {handleMouseEnter, handleMouseLeave, handleClick} =
  32. useCrumbHandlers(startTimestampMs);
  33. const onClickTimestamp = useCallback(
  34. () => handleClick(breadcrumb),
  35. [handleClick, breadcrumb]
  36. );
  37. const onMouseEnter = useCallback(
  38. () => handleMouseEnter(breadcrumb),
  39. [handleMouseEnter, breadcrumb]
  40. );
  41. const onMouseLeave = useCallback(
  42. () => handleMouseLeave(breadcrumb),
  43. [handleMouseLeave, breadcrumb]
  44. );
  45. const crumbTime = useMemo(
  46. () => relativeTimeInMs(new Date(breadcrumb.timestamp || ''), startTimestampMs),
  47. [breadcrumb.timestamp, startTimestampMs]
  48. );
  49. const hasOccurred = currentTime >= crumbTime;
  50. const isBeforeHover = currentHoverTime === undefined || currentHoverTime >= crumbTime;
  51. return (
  52. <BreadcrumbItem
  53. index={index}
  54. crumb={breadcrumb}
  55. className={classNames({
  56. beforeCurrentTime: hasOccurred,
  57. afterCurrentTime: !hasOccurred,
  58. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  59. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  60. })}
  61. onClick={onClickTimestamp}
  62. onMouseEnter={onMouseEnter}
  63. onMouseLeave={onMouseLeave}
  64. startTimestampMs={startTimestampMs}
  65. style={style}
  66. expandPaths={expandPaths}
  67. onDimensionChange={onDimensionChange}
  68. />
  69. );
  70. }
  71. export default memo(BreadcrumbRow);