pierrejeambrun commented on code in PR #64013:
URL: https://github.com/apache/airflow/pull/64013#discussion_r3334188145
##########
airflow/www/static/js/dag/details/taskInstance/Logs/LogBlock.tsx:
##########
@@ -35,27 +40,63 @@ const LogBlock = ({
setUnfoldedLogGroup,
}: Props) => {
const [autoScroll, setAutoScroll] = useState(true);
+ const [logHeight, setLogHeight] = useState<number>();
const logBoxRef = useRef<HTMLPreElement>(null);
- const offsetTop = useOffsetTop(logBoxRef);
+
+ const resizeLogBlock = useCallback(() => {
+ requestAnimationFrame(() => {
+ const logBox = logBoxRef.current;
+ if (!logBox) return;
+
+ const footerHeight =
+ parseInt(getComputedStyle(document.body).paddingBottom, 10) || 0;
+ const viewportHeight =
+ window.visualViewport?.height ?? window.innerHeight;
+ const { top } = logBox.getBoundingClientRect();
+
+ setLogHeight(Math.max(0, viewportHeight - top - footerHeight));
+ });
+ }, []);
Review Comment:
This really seems hacky to force the container size while all that shouldn't
be needed IMO.
##########
airflow/www/static/js/dag/details/taskInstance/Logs/LogBlock.tsx:
##########
@@ -35,27 +40,63 @@ const LogBlock = ({
setUnfoldedLogGroup,
}: Props) => {
const [autoScroll, setAutoScroll] = useState(true);
+ const [logHeight, setLogHeight] = useState<number>();
const logBoxRef = useRef<HTMLPreElement>(null);
- const offsetTop = useOffsetTop(logBoxRef);
+
+ const resizeLogBlock = useCallback(() => {
+ requestAnimationFrame(() => {
+ const logBox = logBoxRef.current;
+ if (!logBox) return;
+
+ const footerHeight =
+ parseInt(getComputedStyle(document.body).paddingBottom, 10) || 0;
+ const viewportHeight =
+ window.visualViewport?.height ?? window.innerHeight;
+ const { top } = logBox.getBoundingClientRect();
+
+ setLogHeight(Math.max(0, viewportHeight - top - footerHeight));
+ });
+ }, []);
const scrollToBottom = () => {
- if (logBoxRef.current) {
- logBoxRef.current.scrollTop = logBoxRef.current.scrollHeight;
- }
+ requestAnimationFrame(() => {
+ if (logBoxRef.current) {
+ logBoxRef.current.scrollTop = logBoxRef.current.scrollHeight;
+ }
+ });
};
+ useLayoutEffect(() => {
+ window.addEventListener("resize", resizeLogBlock);
+ window.visualViewport?.addEventListener("resize", resizeLogBlock);
+
+ return () => {
+ window.removeEventListener("resize", resizeLogBlock);
+ window.visualViewport?.removeEventListener("resize", resizeLogBlock);
+ };
+ }, [resizeLogBlock]);
+
+ useLayoutEffect(() => {
+ resizeLogBlock();
+ }, [resizeLogBlock, wrap]);
+
useEffect(() => {
Review Comment:
Same here, super hacky, many listeners, just to force a container hight.
There must be a cleaner way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]