breadcrumbRow.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {CSSProperties, MouseEvent, useCallback} from 'react';
  2. import styled from '@emotion/styled';
  3. import classNames from 'classnames';
  4. import BreadcrumbItem from 'sentry/components/replays/breadcrumbs/breadcrumbItem';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import useCrumbHandlers from 'sentry/utils/replays/hooks/useCrumbHandlers';
  7. import type {ReplayFrame} from 'sentry/utils/replays/types';
  8. interface Props {
  9. frame: ReplayFrame;
  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. frame,
  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(() => handleClick(frame), [handleClick, frame]);
  34. const onMouseEnter = useCallback(
  35. () => handleMouseEnter(frame),
  36. [handleMouseEnter, frame]
  37. );
  38. const onMouseLeave = useCallback(
  39. () => handleMouseLeave(frame),
  40. [handleMouseLeave, frame]
  41. );
  42. const hasOccurred = currentTime >= frame.offsetMs;
  43. const isBeforeHover =
  44. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  45. return (
  46. <StyledTimeBorder
  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. >
  55. <BreadcrumbItem
  56. index={index}
  57. frame={frame}
  58. onClick={onClickTimestamp}
  59. onMouseEnter={onMouseEnter}
  60. onMouseLeave={onMouseLeave}
  61. startTimestampMs={startTimestampMs}
  62. expandPaths={expandPaths}
  63. onDimensionChange={onDimensionChange}
  64. />
  65. </StyledTimeBorder>
  66. );
  67. }
  68. const StyledTimeBorder = styled('div')`
  69. /* Overridden in TabItemContainer, depending on *CurrentTime and *HoverTime classes */
  70. border-top: 1px solid transparent;
  71. border-bottom: 1px solid transparent;
  72. `;
  73. export default BreadcrumbRow;