Skip to content

Commit 6f2b294

Browse files
committed
Update visibility logic, keyboard shortcuts and position issues
1 parent 4a3a11a commit 6f2b294

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/TaskLogContent.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
import { Box, Code, VStack, IconButton } from "@chakra-ui/react";
2020
import { useVirtualizer } from "@tanstack/react-virtual";
21-
import { useLayoutEffect, useRef } from "react";
21+
import { useLayoutEffect, useMemo, useRef } from "react";
2222
import { useHotkeys } from "react-hotkeys-hook";
2323
import { useTranslation } from "react-i18next";
2424
import { FiChevronDown, FiChevronUp } from "react-icons/fi";
@@ -63,7 +63,7 @@ const ScrollToButton = ({
6363
}}
6464
aria-label={translate(`scroll.direction.${direction}`)}
6565
bg="bg.panel"
66-
bottom={direction === "bottom" ? 2 : 12}
66+
bottom={direction === "bottom" ? 4 : 14}
6767
onClick={onClick}
6868
position="absolute"
6969
rounded="full"
@@ -86,20 +86,27 @@ export const TaskLogContent = ({ error, isLoading, logError, parsedLogs, wrap }:
8686
overscan: 10,
8787
});
8888

89+
const showScrollButtons = useMemo(() => {
90+
const contentHeight = rowVirtualizer.getTotalSize();
91+
const containerHeight = rowVirtualizer.scrollElement?.clientHeight ?? 0;
92+
93+
return contentHeight > containerHeight;
94+
}, [rowVirtualizer]);
95+
8996
useLayoutEffect(() => {
9097
if (location.hash && !isLoading) {
91-
rowVirtualizer.scrollToIndex(Number(hash));
98+
rowVirtualizer.scrollToIndex(Math.min(Number(hash) + 5, parsedLogs.length - 1));
9299
}
93-
}, [isLoading, rowVirtualizer, hash]);
100+
}, [isLoading, rowVirtualizer, hash, parsedLogs]);
94101

95102
const handleScrollTo = (to: "bottom" | "top") => {
96103
if (parsedLogs.length > 0) {
97104
rowVirtualizer.scrollToIndex(to === "bottom" ? parsedLogs.length - 1 : 0);
98105
}
99106
};
100107

101-
useHotkeys("ArrowDown", () => handleScrollTo("bottom"), { enabled: !isLoading });
102-
useHotkeys("ArrowUp", () => handleScrollTo("top"), { enabled: !isLoading });
108+
useHotkeys("mod+ArrowDown", () => handleScrollTo("bottom"), { enabled: !isLoading });
109+
useHotkeys("mod+ArrowUp", () => handleScrollTo("top"), { enabled: !isLoading });
103110

104111
return (
105112
<Box display="flex" flexDirection="column" flexGrow={1} h="100%" minHeight={0} position="relative">
@@ -148,8 +155,12 @@ export const TaskLogContent = ({ error, isLoading, logError, parsedLogs, wrap }:
148155
</VStack>
149156
</Code>
150157

151-
<ScrollToButton direction="top" onClick={() => handleScrollTo("top")} />
152-
<ScrollToButton direction="bottom" onClick={() => handleScrollTo("bottom")} />
158+
{showScrollButtons ? (
159+
<>
160+
<ScrollToButton direction="top" onClick={() => handleScrollTo("top")} />
161+
<ScrollToButton direction="bottom" onClick={() => handleScrollTo("bottom")} />
162+
</>
163+
) : undefined}
153164
</Box>
154165
);
155166
};

0 commit comments

Comments
 (0)