@@ -3,16 +3,27 @@ import { downloadBlob } from '../../helper/csv-util';
33import { useSuspendedBackendaiClient } from '../../hooks' ;
44import { useTanQuery } from '../../hooks/reactQueryAlias' ;
55import { useMemoWithPrevious } from '../../hooks/useMemoWithPrevious' ;
6+ import AutoRefreshSwitch from '../AutoRefreshSwitch' ;
67import BAISelect from '../BAISelect' ;
78import { ReloadOutlined } from '@ant-design/icons' ;
89import { LazyLog , ScrollFollow } from '@melloware/react-logviewer' ;
9- import { Button , Divider , Grid , theme , Tooltip , Typography } from 'antd' ;
10+ import {
11+ Button ,
12+ Divider ,
13+ Grid ,
14+ theme ,
15+ TimePicker ,
16+ Tooltip ,
17+ Typography ,
18+ } from 'antd' ;
1019import { BAIFlex , BAIModal , BAIModalProps } from 'backend.ai-ui' ;
20+ import dayjs from 'dayjs' ;
1121import _ from 'lodash' ;
1222import { DownloadIcon } from 'lucide-react' ;
1323import React , { useState } from 'react' ;
1424import { useTranslation } from 'react-i18next' ;
1525import { graphql , useFragment } from 'react-relay' ;
26+ import { useBAISettingUserState } from 'src/hooks/useBAISetting' ;
1627
1728interface ContainerLogModalProps extends BAIModalProps {
1829 sessionFrgmt : ContainerLogModalFragment$key | null ;
@@ -24,9 +35,18 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
2435 defaultKernelId,
2536 ...modalProps
2637} ) => {
38+ 'use memo' ;
2739 const baiClient = useSuspendedBackendaiClient ( ) ;
2840 const { token } = theme . useToken ( ) ;
2941
42+ const [ autoRefreshEnabled , setAutoRefreshEnabled ] = useBAISettingUserState (
43+ 'container_log_auto_refresh_enabled' ,
44+ ) ;
45+ const [ autoRefreshInterval , setAutoRefreshInterval ] = useBAISettingUserState (
46+ 'container_log_auto_refresh_interval' ,
47+ ) ;
48+ const autoRefreshIntervalValue = autoRefreshInterval || 5_000 ;
49+
3050 const session = useFragment (
3151 graphql `
3252 fragment ContainerLogModalFragment on ComputeSessionNode {
@@ -86,7 +106,7 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
86106 . get_logs ( session ?. row_id , session ?. access_key , selectedKernelId , 15000 )
87107 . then ( ( req : any ) => req . result . logs ) ;
88108 } ,
89- staleTime : 5000 ,
109+ staleTime : autoRefreshInterval ,
90110 } ) ;
91111
92112 const [ lastLineNumbers , { resetPrevious : resetPreviousLineNumber } ] =
@@ -174,27 +194,6 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
174194 . value ( ) }
175195 />
176196 < Divider type = "vertical" />
177- { /* Request logs
178- <Select
179- value={logSize}
180- options={[
181- {
182- label: 'last 100 lines',
183- value: 100,
184- },
185- {
186- label: 'Full logs',
187- value: 'full',
188- },
189- ]}
190- onChange={(value) => {
191- setLogSize(value);
192- if(value!=='full'){
193- resetPreviousLineNumber();
194- }
195- refetch();
196- }}
197- ></Select> */ }
198197 < Tooltip title = { t ( 'button.Download' ) } >
199198 < Button
200199 size = "middle"
@@ -217,6 +216,33 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
217216 onClick = { ( ) => refetch ( ) }
218217 />
219218 </ Tooltip >
219+ < BAIFlex gap = "xs" align = "center" >
220+ < AutoRefreshSwitch
221+ checked = { autoRefreshEnabled }
222+ onChange = { setAutoRefreshEnabled }
223+ interval = { autoRefreshInterval }
224+ onRefresh = { ( ) => {
225+ refetch ( ) ;
226+ } }
227+ >
228+ { t ( 'button.AutoRefresh' ) } :
229+ </ AutoRefreshSwitch >
230+ < TimePicker
231+ format = "mm:ss"
232+ value = { dayjs ( )
233+ . startOf ( 'day' )
234+ . minute ( Math . floor ( autoRefreshIntervalValue / 60000 ) )
235+ . second ( Math . floor ( ( autoRefreshIntervalValue % 60000 ) / 1000 ) ) }
236+ allowClear = { false }
237+ showNow = { false }
238+ onChange = { ( time ) => {
239+ const ms =
240+ ( time ?. minute ( ) || 0 ) * 60_000 +
241+ ( time ?. second ( ) || 0 ) * 1_000 ;
242+ setAutoRefreshInterval ( ms ) ;
243+ } }
244+ />
245+ </ BAIFlex >
220246 </ BAIFlex >
221247
222248 < div
0 commit comments