@@ -3,12 +3,18 @@ import { useSocketLogs } from "@/lib/socketUtils"
33import { Card , CardContent , CardHeader } from "@/components/ui/card"
44import { LiveLogViewer } from "@/components/custom/general/LogViewer"
55import { DatePickerWithPresets } from "@/components/ui/date-picker-presets"
6- import { useCallback , useState } from "react"
6+ import { useCallback , useMemo , useState } from "react"
77import type { DateRange } from "react-day-picker"
88import { defaultLogPeriod } from "@/features/jobsTable/interfaces"
9+ import TabButtonGroup from "@/components/custom/general/TabButtonGroup"
10+ import LogFileList from "@/components/custom/general/LogFileList"
11+ import { useJobLogs } from "@/hooks/useLogs"
12+ import Spinner from "@/components/custom/LoadingOverlay"
913
14+ const tabList = [ "Events" , "Files" ]
1015export function EventLog ( ) {
1116 const [ period , setPeriod ] = useState < DateRange > ( defaultLogPeriod )
17+ const [ activeLogTypeTab , setActiveLogTypeTab ] = useState < string > ( tabList [ 0 ] )
1218 const { latestLogs, logs } = useSocketLogs ( {
1319 actions : [ MiscNotificationTopics . EventLog ] ,
1420 format : ( data : any ) => ( {
@@ -25,6 +31,18 @@ export function EventLog() {
2531 setPeriod ( period ?? defaultLogPeriod )
2632 } , [ ] )
2733
34+ const isEventsTabActive = useMemo (
35+ ( ) => activeLogTypeTab === "Events" ,
36+ [ activeLogTypeTab ] ,
37+ )
38+
39+ const {
40+ systemLogFiles,
41+ loading : logFileLoading ,
42+ readLogFile,
43+ downloadLogFile,
44+ } = useJobLogs ( { } )
45+
2846 return (
2947 < div className = "flex flex-col gap-4 h-full" >
3048 < div className = { "flex flex-col gap-1 mb-4" } >
@@ -39,21 +57,45 @@ export function EventLog() {
3957 < div className = "text-l font-bold tracking-tight italic flex-col gap-2 items-left" >
4058 < div > Event logs</ div >
4159 < div className = "italic text-sm" >
42- All system event logs, updated in real time
60+ { isEventsTabActive
61+ ? "All system event logs, updated in real time"
62+ : "All system event log files" }
4363 </ div >
4464 </ div >
45- < DatePickerWithPresets
46- onChange = { onPeriodFilterChange }
47- defaultValue = { period }
48- />
65+ < div className = "flex gap-2" >
66+ < DatePickerWithPresets
67+ onChange = { onPeriodFilterChange }
68+ defaultValue = { period }
69+ disabled = { ! isEventsTabActive }
70+ />
71+ < TabButtonGroup
72+ tabList = { tabList }
73+ setActiveTab = { setActiveLogTypeTab }
74+ activeTab = { activeLogTypeTab }
75+ />
76+ </ div >
4977 </ CardHeader >
5078 < CardContent className = "p-4 pt-0 h-full" >
5179 < div className = "flex flex-col gap-2 h-full" >
5280 < div className = "space-y-1 rounded bg-background text-foreground text-sm min-h-[500px] w-full flex-grow" >
53- < LiveLogViewer
54- initialLogs = { logs . map ( e => e . fullMessage ) }
55- newLogs = { latestLogs . map ( e => e . fullMessage ) }
56- />
81+ { isEventsTabActive ? (
82+ < LiveLogViewer
83+ initialLogs = { logs . map ( e => e . fullMessage ) }
84+ newLogs = { latestLogs . map ( e => e . fullMessage ) }
85+ />
86+ ) : (
87+ < Spinner
88+ isLoading = { logFileLoading }
89+ className = "flex flex-col max-h-[calc(100vh-18rem)]"
90+ >
91+ < LogFileList
92+ logFiles = { systemLogFiles }
93+ readLogFile = { readLogFile }
94+ originName = "System"
95+ downloadLogFile = { downloadLogFile }
96+ />
97+ </ Spinner >
98+ ) }
5799 </ div >
58100 </ div >
59101 </ CardContent >
0 commit comments