@@ -65,6 +65,7 @@ import {
6565 PlusIcon ,
6666 Search ,
6767 X ,
68+ Trash2 ,
6869} from "lucide-react" ;
6970import type {
7071 GetServerSidePropsContext ,
@@ -276,30 +277,37 @@ const Project = (
276277 start : api . compose . start . useMutation ( ) ,
277278 stop : api . compose . stop . useMutation ( ) ,
278279 move : api . compose . move . useMutation ( ) ,
280+ delete : api . compose . delete . useMutation ( ) ,
279281 } ;
280282
281283 const applicationActions = {
282284 move : api . application . move . useMutation ( ) ,
285+ delete : api . application . delete . useMutation ( ) ,
283286 } ;
284287
285288 const postgresActions = {
286289 move : api . postgres . move . useMutation ( ) ,
290+ delete : api . postgres . remove . useMutation ( ) ,
287291 } ;
288292
289293 const mysqlActions = {
290294 move : api . mysql . move . useMutation ( ) ,
295+ delete : api . mysql . remove . useMutation ( ) ,
291296 } ;
292297
293298 const mariadbActions = {
294299 move : api . mariadb . move . useMutation ( ) ,
300+ delete : api . mariadb . remove . useMutation ( ) ,
295301 } ;
296302
297303 const redisActions = {
298304 move : api . redis . move . useMutation ( ) ,
305+ delete : api . redis . remove . useMutation ( ) ,
299306 } ;
300307
301308 const mongoActions = {
302309 move : api . mongo . move . useMutation ( ) ,
310+ delete : api . mongo . remove . useMutation ( ) ,
303311 } ;
304312
305313 const handleBulkStart = async ( ) => {
@@ -416,6 +424,68 @@ const Project = (
416424 setIsBulkActionLoading ( false ) ;
417425 } ;
418426
427+ const handleBulkDelete = async ( ) => {
428+ let success = 0 ;
429+ setIsBulkActionLoading ( true ) ;
430+ for ( const serviceId of selectedServices ) {
431+ try {
432+ const service = filteredServices . find ( ( s ) => s . id === serviceId ) ;
433+ if ( ! service ) continue ;
434+
435+ switch ( service . type ) {
436+ case "application" :
437+ await applicationActions . delete . mutateAsync ( {
438+ applicationId : serviceId ,
439+ } ) ;
440+ break ;
441+ case "compose" :
442+ await composeActions . delete . mutateAsync ( {
443+ composeId : serviceId ,
444+ deleteVolumes : false ,
445+ } ) ;
446+ break ;
447+ case "postgres" :
448+ await postgresActions . delete . mutateAsync ( {
449+ postgresId : serviceId ,
450+ } ) ;
451+ break ;
452+ case "mysql" :
453+ await mysqlActions . delete . mutateAsync ( {
454+ mysqlId : serviceId ,
455+ } ) ;
456+ break ;
457+ case "mariadb" :
458+ await mariadbActions . delete . mutateAsync ( {
459+ mariadbId : serviceId ,
460+ } ) ;
461+ break ;
462+ case "redis" :
463+ await redisActions . delete . mutateAsync ( {
464+ redisId : serviceId ,
465+ } ) ;
466+ break ;
467+ case "mongo" :
468+ await mongoActions . delete . mutateAsync ( {
469+ mongoId : serviceId ,
470+ } ) ;
471+ break ;
472+ }
473+ success ++ ;
474+ } catch ( error ) {
475+ toast . error (
476+ `Error deleting service ${ serviceId } : ${ error instanceof Error ? error . message : "Unknown error" } ` ,
477+ ) ;
478+ }
479+ }
480+ if ( success > 0 ) {
481+ toast . success ( `${ success } services deleted successfully` ) ;
482+ refetch ( ) ;
483+ }
484+ setSelectedServices ( [ ] ) ;
485+ setIsDropdownOpen ( false ) ;
486+ setIsBulkActionLoading ( false ) ;
487+ } ;
488+
419489 const filteredServices = useMemo ( ( ) => {
420490 if ( ! applications ) return [ ] ;
421491 return applications . filter (
@@ -565,6 +635,20 @@ const Project = (
565635 Stop
566636 </ Button >
567637 </ DialogAction >
638+ < DialogAction
639+ title = "Delete Services"
640+ description = { `Are you sure you want to delete ${ selectedServices . length } services? This action cannot be undone.` }
641+ type = "destructive"
642+ onClick = { handleBulkDelete }
643+ >
644+ < Button
645+ variant = "ghost"
646+ className = "w-full justify-start text-destructive"
647+ >
648+ < Trash2 className = "mr-2 h-4 w-4" />
649+ Delete
650+ </ Button >
651+ </ DialogAction >
568652 < Dialog
569653 open = { isMoveDialogOpen }
570654 onOpenChange = { setIsMoveDialogOpen }
0 commit comments