Skip to content

Commit f2112da

Browse files
committed
deactivated scroll while scrolling in order to hide the missynchronization between tables hover
1 parent 885e84b commit f2112da

File tree

1 file changed

+36
-4
lines changed
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam

1 file changed

+36
-4
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam/route.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ function TasksTreeView({
645645
const [showQueueTime, setShowQueueTime] = useState(false);
646646
const [scale, setScale] = useState(0);
647647
const [hoveredNodeId, setHoveredNodeId] = useState<string | null>(null);
648+
const [isScrolling, setIsScrolling] = useState(false);
649+
const scrollTimeoutRef = useRef<NodeJS.Timeout | null>(null);
650+
const pendingHoverIdRef = useRef<string | null>(null);
648651
const parentRef = useRef<HTMLDivElement>(null);
649652
const treeScrollRef = useRef<HTMLDivElement>(null);
650653
const timelineScrollRef = useRef<HTMLDivElement>(null);
@@ -656,6 +659,27 @@ function TasksTreeView({
656659
const displayEvents = events;
657660
const queuedTime = showQueueTime ? undefined : queuedDuration;
658661

662+
const handleHoverChange = useCallback((nodeId: string | null) => {
663+
pendingHoverIdRef.current = nodeId;
664+
if (!isScrolling) {
665+
setHoveredNodeId(nodeId);
666+
}
667+
}, [isScrolling]);
668+
669+
const handleScroll = useCallback((scrollTop: number) => {
670+
setIsScrolling(true);
671+
if (scrollTimeoutRef.current) {
672+
clearTimeout(scrollTimeoutRef.current);
673+
}
674+
scrollTimeoutRef.current = setTimeout(() => {
675+
setIsScrolling(false);
676+
// Apply the pending hover ID when scrolling stops
677+
if (pendingHoverIdRef.current !== null) {
678+
setHoveredNodeId(pendingHoverIdRef.current);
679+
}
680+
}, 150);
681+
}, []);
682+
659683
const {
660684
nodes,
661685
getTreeProps,
@@ -788,8 +812,8 @@ function TasksTreeView({
788812
onClick={() => {
789813
selectNode(node.id);
790814
}}
791-
onMouseEnter={() => setHoveredNodeId(node.id)}
792-
onMouseLeave={() => setHoveredNodeId(null)}
815+
onMouseEnter={() => handleHoverChange(node.id)}
816+
onMouseLeave={() => handleHoverChange(null)}
793817
>
794818
<div className="flex h-8 items-center">
795819
{Array.from({ length: node.level }).map((_, index) => (
@@ -849,6 +873,7 @@ function TasksTreeView({
849873
);
850874
}}
851875
onScroll={(scrollTop) => {
876+
handleScroll(scrollTop);
852877
//sync the scroll to the tree
853878
if (timelineScrollRef.current) {
854879
timelineScrollRef.current.scrollTop = scrollTop;
@@ -882,6 +907,8 @@ function TasksTreeView({
882907
toggleNodeSelection={toggleNodeSelection}
883908
hoveredNodeId={hoveredNodeId}
884909
setHoveredNodeId={setHoveredNodeId}
910+
handleHoverChange={handleHoverChange}
911+
handleScroll={handleScroll}
885912
/>
886913
</ResizablePanel>
887914
</ResizablePanelGroup>
@@ -949,6 +976,8 @@ type TimelineViewProps = Pick<
949976
treeScrollRef: React.RefObject<HTMLDivElement>;
950977
hoveredNodeId: string | null;
951978
setHoveredNodeId: (nodeId: string | null) => void;
979+
handleHoverChange: (nodeId: string | null) => void;
980+
handleScroll: (scrollTop: number) => void;
952981
};
953982

954983
const tickCount = 5;
@@ -970,6 +999,8 @@ function TimelineView({
970999
queuedDuration,
9711000
hoveredNodeId,
9721001
setHoveredNodeId,
1002+
handleHoverChange,
1003+
handleScroll,
9731004
}: TimelineViewProps) {
9741005
const timelineContainerRef = useRef<HTMLDivElement>(null);
9751006
const initialTimelineDimensions = useInitialDimensions(timelineContainerRef);
@@ -1132,8 +1163,8 @@ function TimelineView({
11321163
onClick={(e) => {
11331164
toggleNodeSelection(node.id);
11341165
}}
1135-
onMouseEnter={() => setHoveredNodeId(node.id)}
1136-
onMouseLeave={() => setHoveredNodeId(null)}
1166+
onMouseEnter={() => handleHoverChange(node.id)}
1167+
onMouseLeave={() => handleHoverChange(null)}
11371168
>
11381169
{node.data.level === "TRACE" ? (
11391170
<>
@@ -1239,6 +1270,7 @@ function TimelineView({
12391270
);
12401271
}}
12411272
onScroll={(scrollTop) => {
1273+
handleScroll(scrollTop);
12421274
//sync the scroll to the tree
12431275
if (treeScrollRef.current) {
12441276
treeScrollRef.current.scrollTop = scrollTop;

0 commit comments

Comments
 (0)