breadcrumbRow.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 {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. import {ReplayTraceRow} from 'sentry/views/replays/detail/perfTable/useReplayPerfData';
  10. interface Props {
  11. extraction: Extraction | undefined;
  12. frame: ReplayFrame;
  13. index: number;
  14. onClick: ReturnType<typeof useCrumbHandlers>['onClickTimestamp'];
  15. onDimensionChange: (index: number) => void;
  16. onInspectorExpanded: (
  17. index: number,
  18. path: string,
  19. expandedState: Record<string, boolean>,
  20. event: MouseEvent<HTMLDivElement>
  21. ) => void;
  22. startTimestampMs: number;
  23. style: CSSProperties;
  24. traces: ReplayTraceRow | undefined;
  25. breadcrumbIndex?: number[][];
  26. expandPaths?: string[];
  27. }
  28. function BreadcrumbRow({
  29. expandPaths,
  30. frame,
  31. extraction,
  32. index,
  33. onClick,
  34. onDimensionChange,
  35. onInspectorExpanded,
  36. startTimestampMs,
  37. style,
  38. traces,
  39. }: Props) {
  40. const {currentTime, currentHoverTime} = useReplayContext();
  41. const {onMouseEnter, onMouseLeave} = useCrumbHandlers();
  42. const handleDimensionChange = useCallback(
  43. () => onDimensionChange(index),
  44. [onDimensionChange, index]
  45. );
  46. const handleObjectInspectorExpanded = useCallback(
  47. (path, expandedState, e) =>
  48. onInspectorExpanded && onInspectorExpanded(index, path, expandedState, e),
  49. [index, onInspectorExpanded]
  50. );
  51. const hasOccurred = currentTime >= frame.offsetMs;
  52. const isBeforeHover =
  53. currentHoverTime === undefined || currentHoverTime >= frame.offsetMs;
  54. return (
  55. <StyledTimeBorder
  56. className={classNames({
  57. beforeCurrentTime: hasOccurred,
  58. afterCurrentTime: !hasOccurred,
  59. beforeHoverTime: currentHoverTime !== undefined ? isBeforeHover : undefined,
  60. afterHoverTime: currentHoverTime !== undefined ? !isBeforeHover : undefined,
  61. })}
  62. style={style}
  63. >
  64. <BreadcrumbItem
  65. frame={frame}
  66. traces={traces}
  67. extraction={extraction}
  68. onClick={onClick}
  69. onMouseEnter={onMouseEnter}
  70. onMouseLeave={onMouseLeave}
  71. startTimestampMs={startTimestampMs}
  72. expandPaths={expandPaths}
  73. onDimensionChange={handleDimensionChange}
  74. onInspectorExpanded={handleObjectInspectorExpanded}
  75. />
  76. </StyledTimeBorder>
  77. );
  78. }
  79. const StyledTimeBorder = styled('div')`
  80. /* Overridden in TabItemContainer, depending on *CurrentTime and *HoverTime classes */
  81. border-top: 1px solid transparent;
  82. border-bottom: 1px solid transparent;
  83. `;
  84. export default BreadcrumbRow;