@@ -3,16 +3,26 @@ 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+ InputNumber ,
15+ theme ,
16+ Tooltip ,
17+ Typography ,
18+ } from 'antd' ;
1019import { BAIFlex , BAIModal , BAIModalProps } from 'backend.ai-ui' ;
1120import _ from 'lodash' ;
1221import { DownloadIcon } from 'lucide-react' ;
1322import React , { useState } from 'react' ;
1423import { useTranslation } from 'react-i18next' ;
1524import { graphql , useFragment } from 'react-relay' ;
25+ import { useBAISettingUserState } from 'src/hooks/useBAISetting' ;
1626
1727interface ContainerLogModalProps extends BAIModalProps {
1828 sessionFrgmt : ContainerLogModalFragment$key | null ;
@@ -24,9 +34,18 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
2434 defaultKernelId,
2535 ...modalProps
2636} ) => {
37+ 'use memo' ;
2738 const baiClient = useSuspendedBackendaiClient ( ) ;
2839 const { token } = theme . useToken ( ) ;
2940
41+ const [ autoRefreshEnabled , setAutoRefreshEnabled ] = useBAISettingUserState (
42+ 'container_log_auto_refresh_enabled' ,
43+ ) ;
44+ const [ autoRefreshInterval , setAutoRefreshInterval ] = useBAISettingUserState (
45+ 'container_log_auto_refresh_interval' ,
46+ ) ;
47+ const autoRefreshIntervalValue = autoRefreshInterval || 5_000 ;
48+
3049 const session = useFragment (
3150 graphql `
3251 fragment ContainerLogModalFragment on ComputeSessionNode {
@@ -86,7 +105,7 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
86105 . get_logs ( session ?. row_id , session ?. access_key , selectedKernelId , 15000 )
87106 . then ( ( req : any ) => req . result . logs ) ;
88107 } ,
89- staleTime : 5000 ,
108+ staleTime : autoRefreshInterval ,
90109 } ) ;
91110
92111 const [ lastLineNumbers , { resetPrevious : resetPreviousLineNumber } ] =
@@ -174,27 +193,6 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
174193 . value ( ) }
175194 />
176195 < 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> */ }
198196 < Tooltip title = { t ( 'button.Download' ) } >
199197 < Button
200198 size = "middle"
@@ -217,6 +215,29 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
217215 onClick = { ( ) => refetch ( ) }
218216 />
219217 </ Tooltip >
218+ < BAIFlex gap = "xs" align = "center" >
219+ < AutoRefreshSwitch
220+ checked = { autoRefreshEnabled }
221+ onChange = { setAutoRefreshEnabled }
222+ interval = { autoRefreshIntervalValue }
223+ onRefresh = { ( ) => {
224+ refetch ( ) ;
225+ } }
226+ >
227+ { t ( 'button.AutoRefresh' ) } :
228+ </ AutoRefreshSwitch >
229+ < InputNumber
230+ min = { 1 }
231+ value = { ( autoRefreshIntervalValue ?? 1000 ) / 1000 }
232+ onChange = { ( value ) => {
233+ if ( typeof value === 'number' ) {
234+ setAutoRefreshInterval ( value * 1000 ) ;
235+ }
236+ } }
237+ addonAfter = { t ( 'time.Sec' ) }
238+ style = { { maxWidth : 150 } }
239+ />
240+ </ BAIFlex >
220241 </ BAIFlex >
221242
222243 < div
0 commit comments