@@ -8,7 +8,7 @@ import type { Instance } from '../../types/instance';
88import { useI18n } from '../../contexts/I18nContext' ;
99
1010type ViewMode = 'list' | 'card' ;
11- type StatusFilter = 'all' | 'running' | 'stopped' | 'creating' | 'error' ;
11+ type StatusFilter = 'all' | 'running' | 'stopped' | 'creating' | 'deleting' | ' error';
1212
1313const INSTANCE_FIELDS_TO_COMPARE : Array < keyof Instance > = [
1414 'id' ,
@@ -149,7 +149,7 @@ const InstanceCardItem = React.memo(({
149149 </ Link >
150150 < button
151151 onClick = { ( ) => onRequestDelete ( instance . id ) }
152- disabled = { deletingIds . includes ( instance . id ) }
152+ disabled = { deletingIds . includes ( instance . id ) || instance . status === 'deleting' }
153153 className = "inline-flex items-center px-3 py-1.5 border border-transparent text-xs font-medium rounded text-red-700 bg-red-100 hover:bg-red-200 focus:outline-none disabled:opacity-50"
154154 >
155155 { deletingIds . includes ( instance . id ) ? `${ t ( 'common.delete' ) } ...` : t ( 'common.delete' ) }
@@ -223,7 +223,7 @@ const InstanceListItem = React.memo(({
223223
224224 < button
225225 onClick = { ( ) => onRequestDelete ( instance . id ) }
226- disabled = { deletingIds . includes ( instance . id ) }
226+ disabled = { deletingIds . includes ( instance . id ) || instance . status === 'deleting' }
227227 className = "inline-flex items-center px-3 py-1.5 border border-transparent text-xs font-medium rounded text-red-700 bg-red-100 hover:bg-red-200 focus:outline-none disabled:opacity-50"
228228 >
229229 { deletingIds . includes ( instance . id ) ? `${ t ( 'common.delete' ) } ...` : t ( 'common.delete' ) }
@@ -269,7 +269,7 @@ const InstanceListPage: React.FC = () => {
269269 } , [ loadInstances ] ) ;
270270
271271 useEffect ( ( ) => {
272- if ( ! instances . some ( ( instance ) => instance . status === 'creating' ) ) {
272+ if ( ! instances . some ( ( instance ) => instance . status === 'creating' || instance . status === 'deleting' ) ) {
273273 return ;
274274 }
275275
@@ -280,7 +280,7 @@ const InstanceListPage: React.FC = () => {
280280 return ( ) => {
281281 window . clearInterval ( intervalId ) ;
282282 } ;
283- } , [ instances ] ) ;
283+ } , [ instances , loadInstances ] ) ;
284284
285285 // Handle WebSocket status updates
286286 const handleStatusUpdate = useCallback ( ( update : { instance_id : number ; status : string ; pod_name ?: string ; pod_ip ?: string } ) => {
@@ -330,14 +330,19 @@ const InstanceListPage: React.FC = () => {
330330 try {
331331 setDeletingIds ( ( prevIds ) => [ ...prevIds , id ] ) ;
332332 await instanceService . deleteInstance ( id ) ;
333- setInstances ( ( prevInstances ) => prevInstances . filter ( ( instance ) => instance . id !== id ) ) ;
333+ setInstances ( ( prevInstances ) =>
334+ prevInstances . map ( ( instance ) =>
335+ instance . id === id ? { ...instance , status : 'deleting' } : instance ,
336+ ) ,
337+ ) ;
334338 setPendingDeleteId ( null ) ;
339+ await loadInstances ( { silent : true } ) ;
335340 } catch ( err : any ) {
336341 alert ( err . response ?. data ?. error || t ( 'instances.failedToDelete' ) ) ;
337342 } finally {
338343 setDeletingIds ( ( prevIds ) => prevIds . filter ( ( deletingId ) => deletingId !== id ) ) ;
339344 }
340- } , [ t ] ) ;
345+ } , [ loadInstances , t ] ) ;
341346
342347 const handleStart = useCallback ( async ( id : number ) => {
343348 try {
@@ -375,10 +380,12 @@ const InstanceListPage: React.FC = () => {
375380 return 'bg-gray-100 text-gray-800' ;
376381 case 'creating' :
377382 return 'bg-yellow-100 text-yellow-800' ;
383+ case 'deleting' :
384+ return 'bg-orange-100 text-orange-800' ;
378385 case 'error' :
379386 return 'bg-red-100 text-red-800' ;
380387 default :
381- return 'VM ' ;
388+ return 'bg-gray-100 text-gray-800 ' ;
382389 }
383390 } ;
384391
@@ -403,6 +410,13 @@ const InstanceListPage: React.FC = () => {
403410 < path className = "opacity-75" fill = "currentColor" d = "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
404411 </ svg >
405412 ) ;
413+ case 'deleting' :
414+ return (
415+ < svg className = "animate-spin w-3 h-3 mr-1.5 text-orange-600" fill = "none" viewBox = "0 0 24 24" >
416+ < circle className = "opacity-25" cx = "12" cy = "12" r = "10" stroke = "currentColor" strokeWidth = "4" />
417+ < path className = "opacity-75" fill = "currentColor" d = "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
418+ </ svg >
419+ ) ;
406420 default :
407421 return null ;
408422 }
@@ -555,6 +569,7 @@ const InstanceListPage: React.FC = () => {
555569 < option value = "running" > { t ( 'status.running' ) } </ option >
556570 < option value = "stopped" > { t ( 'status.stopped' ) } </ option >
557571 < option value = "creating" > { t ( 'status.creating' ) } </ option >
572+ < option value = "deleting" > { t ( 'status.deleting' ) } </ option >
558573 < option value = "error" > { t ( 'status.error' ) } </ option >
559574 </ select >
560575
0 commit comments