Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion ui/src/modules/jobs/pages/JobLogs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react"
import { useEffect, useState, useRef } from "react"
import clsx from "clsx"
import { useParams, useNavigate, Link, useSearchParams } from "react-router-dom"
import { Input, Spin, message, Button, Tooltip } from "antd"
Expand Down Expand Up @@ -36,6 +36,8 @@ const JobLogs: React.FC = () => {
fetchJobs,
} = useAppStore()

const logContainerRef = useRef<HTMLDivElement>(null)

useEffect(() => {
if (!jobs.length) {
fetchJobs()
Expand All @@ -59,6 +61,16 @@ const JobLogs: React.FC = () => {
fetchJobs,
])

useEffect(() => {
if (logContainerRef.current && taskLogs.length > 0 && !isLoadingTaskLogs) {
const { scrollTop, scrollHeight, clientHeight } = logContainerRef.current
const isAtBottom = scrollHeight - scrollTop - clientHeight < 10
if (isAtBottom) {
logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight
}
}
}, [taskLogs, isLoadingTaskLogs])

const job = jobs.find(j => j.id === Number(jobId))

const filteredLogs = taskLogs.filter(function (log) {
Expand Down Expand Up @@ -199,6 +211,7 @@ const JobLogs: React.FC = () => {
</div>
) : (
<div
ref={logContainerRef}
className={clsx(
"overflow-scroll rounded-xl bg-white",
filteredLogs.length > 0 && "border",
Expand Down
Loading