1
- import { Box , Button , Flex , Image , MenuButton , Text } from '@chakra-ui/react'
2
- import { MyTable , SealosMenu , useMessage } from '@sealos/ui'
3
- import { useTranslations } from 'next-intl'
4
- import dynamic from 'next/dynamic'
5
- import { useCallback , useState } from 'react'
6
- import { sealosApp } from 'sealos-desktop-sdk/app'
1
+ import { Box , Button , Flex , Image , MenuButton , Text } from '@chakra-ui/react' ;
2
+ import { SealosMenu , useMessage } from '@sealos/ui' ;
3
+ import { useTranslations } from 'next-intl' ;
4
+ import dynamic from 'next/dynamic' ;
5
+ import { useCallback , useState } from 'react' ;
6
+ import { sealosApp } from 'sealos-desktop-sdk/app' ;
7
7
8
- import { pauseDevbox , restartDevbox , startDevbox } from '@/api/devbox'
9
- import { useRouter } from '@/i18n'
10
- import { useGlobalStore } from '@/stores/global'
11
- import { DevboxListItemTypeV2 } from '@/types/devbox'
8
+ import { pauseDevbox , restartDevbox , startDevbox } from '@/api/devbox' ;
9
+ import { useRouter } from '@/i18n' ;
10
+ import { useGlobalStore } from '@/stores/global' ;
11
+ import { DevboxListItemTypeV2 } from '@/types/devbox' ;
12
12
13
- import DevboxStatusTag from '@/components/DevboxStatusTag'
14
- import MyIcon from '@/components/Icon'
15
- import IDEButton from '@/components/IDEButton'
16
- import ReleaseModal from '@/components/modals/releaseModal'
17
- import PodLineChart from '@/components/PodLineChart'
13
+ import DevboxStatusTag from '@/components/DevboxStatusTag' ;
14
+ import MyIcon from '@/components/Icon' ;
15
+ import IDEButton from '@/components/IDEButton' ;
16
+ import ReleaseModal from '@/components/modals/releaseModal' ;
17
+ import PodLineChart from '@/components/PodLineChart' ;
18
+ import { AdvancedTable } from '@/components/AdvancedTable' ;
18
19
19
- const DelModal = dynamic ( ( ) => import ( '@/components/modals/DelModal' ) )
20
+ const DelModal = dynamic ( ( ) => import ( '@/components/modals/DelModal' ) ) ;
20
21
21
22
const DevboxList = ( {
22
23
devboxList = [ ] ,
23
24
refetchDevboxList
24
25
} : {
25
- devboxList : DevboxListItemTypeV2 [ ]
26
- refetchDevboxList : ( ) => void
26
+ devboxList : DevboxListItemTypeV2 [ ] ;
27
+ refetchDevboxList : ( ) => void ;
27
28
} ) => {
28
- const router = useRouter ( )
29
- const t = useTranslations ( )
30
- const { message : toast } = useMessage ( )
29
+ const router = useRouter ( ) ;
30
+ const t = useTranslations ( ) ;
31
+ const { message : toast } = useMessage ( ) ;
32
+ const duplicatedDevboxList = Array ( 20 )
33
+ . fill ( 0 )
34
+ . flatMap ( ( ) => [ ...devboxList ] ) ;
31
35
32
36
// TODO: Unified Loading Behavior
33
- const { setLoading } = useGlobalStore ( )
37
+ const { setLoading } = useGlobalStore ( ) ;
34
38
35
- const [ onOpenRelease , setOnOpenRelease ] = useState ( false )
36
- const [ delDevbox , setDelDevbox ] = useState < DevboxListItemTypeV2 | null > ( null )
39
+ const [ onOpenRelease , setOnOpenRelease ] = useState ( false ) ;
40
+ const [ delDevbox , setDelDevbox ] = useState < DevboxListItemTypeV2 | null > ( null ) ;
37
41
const [ currentDevboxListItem , setCurrentDevboxListItem ] = useState < DevboxListItemTypeV2 | null > (
38
42
null
39
- )
43
+ ) ;
40
44
41
45
const handleOpenRelease = ( devbox : DevboxListItemTypeV2 ) => {
42
- setCurrentDevboxListItem ( devbox )
43
- setOnOpenRelease ( true )
44
- }
46
+ setCurrentDevboxListItem ( devbox ) ;
47
+ setOnOpenRelease ( true ) ;
48
+ } ;
45
49
const handlePauseDevbox = useCallback (
46
50
async ( devbox : DevboxListItemTypeV2 ) => {
47
51
try {
48
- setLoading ( true )
49
- await pauseDevbox ( { devboxName : devbox . name } )
52
+ setLoading ( true ) ;
53
+ await pauseDevbox ( { devboxName : devbox . name } ) ;
50
54
toast ( {
51
55
title : t ( 'pause_success' ) ,
52
56
status : 'success'
53
- } )
57
+ } ) ;
54
58
} catch ( error : any ) {
55
59
toast ( {
56
60
title : typeof error === 'string' ? error : error . message || t ( 'pause_error' ) ,
57
61
status : 'error'
58
- } )
59
- console . error ( error )
62
+ } ) ;
63
+ console . error ( error ) ;
60
64
}
61
- refetchDevboxList ( )
62
- setLoading ( false )
65
+ refetchDevboxList ( ) ;
66
+ setLoading ( false ) ;
63
67
} ,
64
68
[ refetchDevboxList , setLoading , t , toast ]
65
- )
69
+ ) ;
66
70
const handleRestartDevbox = useCallback (
67
71
async ( devbox : DevboxListItemTypeV2 ) => {
68
72
try {
69
- setLoading ( true )
70
- await restartDevbox ( { devboxName : devbox . name } )
73
+ setLoading ( true ) ;
74
+ await restartDevbox ( { devboxName : devbox . name } ) ;
71
75
toast ( {
72
76
title : t ( 'restart_success' ) ,
73
77
status : 'success'
74
- } )
78
+ } ) ;
75
79
} catch ( error : any ) {
76
80
toast ( {
77
81
title : typeof error === 'string' ? error : error . message || t ( 'restart_error' ) ,
78
82
status : 'error'
79
- } )
80
- console . error ( error , '==' )
83
+ } ) ;
84
+ console . error ( error , '==' ) ;
81
85
}
82
- refetchDevboxList ( )
83
- setLoading ( false )
86
+ refetchDevboxList ( ) ;
87
+ setLoading ( false ) ;
84
88
} ,
85
89
[ refetchDevboxList , setLoading , t , toast ]
86
- )
90
+ ) ;
87
91
const handleStartDevbox = useCallback (
88
92
async ( devbox : DevboxListItemTypeV2 ) => {
89
93
try {
90
- setLoading ( true )
91
- await startDevbox ( { devboxName : devbox . name } )
94
+ setLoading ( true ) ;
95
+ await startDevbox ( { devboxName : devbox . name } ) ;
92
96
toast ( {
93
97
title : t ( 'start_success' ) ,
94
98
status : 'success'
95
- } )
99
+ } ) ;
96
100
} catch ( error : any ) {
97
101
toast ( {
98
102
title : typeof error === 'string' ? error : error . message || t ( 'start_error' ) ,
99
103
status : 'error'
100
- } )
101
- console . error ( error , '==' )
104
+ } ) ;
105
+ console . error ( error , '==' ) ;
102
106
}
103
- refetchDevboxList ( )
104
- setLoading ( false )
107
+ refetchDevboxList ( ) ;
108
+ setLoading ( false ) ;
105
109
} ,
106
110
[ refetchDevboxList , setLoading , t , toast ]
107
- )
111
+ ) ;
108
112
const handleGoToTerminal = useCallback (
109
113
async ( devbox : DevboxListItemTypeV2 ) => {
110
- const defaultCommand = `kubectl exec -it $(kubectl get po -l app.kubernetes.io/name=${ devbox . name } -oname) -- sh -c "clear; (bash || ash || sh)"`
114
+ const defaultCommand = `kubectl exec -it $(kubectl get po -l app.kubernetes.io/name=${ devbox . name } -oname) -- sh -c "clear; (bash || ash || sh)"` ;
111
115
try {
112
116
sealosApp . runEvents ( 'openDesktopApp' , {
113
117
appKey : 'system-terminal' ,
114
118
query : {
115
119
defaultCommand
116
120
} ,
117
121
messageData : { type : 'new terminal' , command : defaultCommand }
118
- } )
122
+ } ) ;
119
123
} catch ( error : any ) {
120
124
toast ( {
121
125
title : typeof error === 'string' ? error : error . message || t ( 'jump_terminal_error' ) ,
122
126
status : 'error'
123
- } )
124
- console . error ( error )
127
+ } ) ;
128
+ console . error ( error ) ;
125
129
}
126
130
} ,
127
131
[ t , toast ]
128
- )
132
+ ) ;
129
133
const columns : {
130
- title : string
131
- dataIndex ?: keyof DevboxListItemTypeV2
132
- key : string
133
- render ?: ( item : DevboxListItemTypeV2 ) => JSX . Element
134
+ title : string ;
135
+ dataIndex ?: keyof DevboxListItemTypeV2 ;
136
+ key : string ;
137
+ render ?: ( item : DevboxListItemTypeV2 ) => JSX . Element ;
134
138
} [ ] = [
135
139
{
136
140
title : t ( 'name' ) ,
@@ -148,7 +152,7 @@ const DevboxList = ({
148
152
{ item . name }
149
153
</ Box >
150
154
</ Flex >
151
- )
155
+ ) ;
152
156
}
153
157
} ,
154
158
{
@@ -161,7 +165,7 @@ const DevboxList = ({
161
165
dataIndex : 'createTime' ,
162
166
key : 'createTime' ,
163
167
render : ( item ) => {
164
- return < Text color = { 'grayModern.600' } > { item . createTime } </ Text >
168
+ return < Text color = { 'grayModern.600' } > { item . createTime } </ Text > ;
165
169
}
166
170
} ,
167
171
{
@@ -179,7 +183,8 @@ const DevboxList = ({
179
183
right = { '4px' }
180
184
bottom = { '0px' }
181
185
pointerEvents = { 'none' }
182
- textShadow = "1px 1px 0 #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF" >
186
+ textShadow = "1px 1px 0 #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF"
187
+ >
183
188
{ item ?. usedCpu ?. yData [ item ?. usedCpu ?. yData ?. length - 1 ] } %
184
189
</ Text >
185
190
</ Box >
@@ -201,7 +206,8 @@ const DevboxList = ({
201
206
right = { '4px' }
202
207
bottom = { '0px' }
203
208
pointerEvents = { 'none' }
204
- textShadow = "1px 1px 0 #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF" >
209
+ textShadow = "1px 1px 0 #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF"
210
+ >
205
211
{ item ?. usedMemory ?. yData [ item ?. usedMemory ?. yData ?. length - 1 ] } %
206
212
</ Text >
207
213
</ Box >
@@ -232,8 +238,9 @@ const DevboxList = ({
232
238
minW = { 'unset' }
233
239
// leftIcon={<MyIcon name={'detail'} w={'16px'} />}
234
240
onClick = { ( ) => {
235
- router . push ( `/devbox/detail/${ item . name } ` )
236
- } } >
241
+ router . push ( `/devbox/detail/${ item . name } ` ) ;
242
+ } }
243
+ >
237
244
{ /* {t('detail')} */ }
238
245
< MyIcon name = { 'detail' } w = { '16px' } />
239
246
</ Button >
@@ -337,10 +344,10 @@ const DevboxList = ({
337
344
</ Flex >
338
345
)
339
346
}
340
- ]
347
+ ] ;
341
348
return (
342
349
< >
343
- < MyTable columns = { columns } data = { devboxList } itemClass = "devboxListItem" />
350
+ < AdvancedTable columns = { columns } data = { duplicatedDevboxList } itemClass = "devboxListItem" />
344
351
{ ! ! delDevbox && (
345
352
< DelModal
346
353
devbox = { delDevbox }
@@ -352,17 +359,17 @@ const DevboxList = ({
352
359
{ ! ! onOpenRelease && ! ! currentDevboxListItem && (
353
360
< ReleaseModal
354
361
onSuccess = { ( ) => {
355
- router . push ( `/devbox/detail/${ currentDevboxListItem ?. name } ` )
362
+ router . push ( `/devbox/detail/${ currentDevboxListItem ?. name } ` ) ;
356
363
} }
357
364
onClose = { ( ) => {
358
- setOnOpenRelease ( false )
359
- setCurrentDevboxListItem ( null )
365
+ setOnOpenRelease ( false ) ;
366
+ setCurrentDevboxListItem ( null ) ;
360
367
} }
361
368
devbox = { currentDevboxListItem }
362
369
/>
363
370
) }
364
371
</ >
365
- )
366
- }
372
+ ) ;
373
+ } ;
367
374
368
- export default DevboxList
375
+ export default DevboxList ;
0 commit comments