|
6 | 6 | RefreshCcw, |
7 | 7 | RocketIcon, |
8 | 8 | Settings, |
| 9 | + Trash2, |
9 | 10 | } from "lucide-react"; |
10 | 11 | import React, { useEffect, useMemo, useState } from "react"; |
11 | 12 | import { toast } from "sonner"; |
@@ -78,6 +79,8 @@ export const ShowDeployments = ({ |
78 | 79 | api.rollback.rollback.useMutation(); |
79 | 80 | const { mutateAsync: killProcess, isLoading: isKillingProcess } = |
80 | 81 | api.deployment.killProcess.useMutation(); |
| 82 | + const { mutateAsync: removeDeployment, isLoading: isRemovingDeployment } = |
| 83 | + api.deployment.removeDeployment.useMutation(); |
81 | 84 |
|
82 | 85 | // Cancel deployment mutations |
83 | 86 | const { |
@@ -256,7 +259,15 @@ export const ShowDeployments = ({ |
256 | 259 | const isExpanded = expandedDescriptions.has( |
257 | 260 | deployment.deploymentId, |
258 | 261 | ); |
259 | | - |
| 262 | + const lastSuccessfulDeployment = deployments?.find( |
| 263 | + (d) => d.status === "done" |
| 264 | + ); |
| 265 | + const isLastSuccessfulDeployment = |
| 266 | + lastSuccessfulDeployment?.deploymentId === deployment.deploymentId; |
| 267 | + const canDelete = |
| 268 | + deployments && |
| 269 | + deployments.length > 1 && |
| 270 | + !isLastSuccessfulDeployment; |
260 | 271 | return ( |
261 | 272 | <div |
262 | 273 | key={deployment.deploymentId} |
@@ -372,6 +383,33 @@ export const ShowDeployments = ({ |
372 | 383 | View |
373 | 384 | </Button> |
374 | 385 |
|
| 386 | + {canDelete && ( |
| 387 | + <DialogAction |
| 388 | + title="Delete Deployment" |
| 389 | + description="Are you sure you want to delete this deployment? This action cannot be undone." |
| 390 | + type="default" |
| 391 | + onClick={async () => { |
| 392 | + try { |
| 393 | + await removeDeployment({ |
| 394 | + deploymentId: deployment.deploymentId, |
| 395 | + }); |
| 396 | + toast.success("Deployment deleted successfully"); |
| 397 | + } catch (error) { |
| 398 | + toast.error("Error deleting deployment"); |
| 399 | + } |
| 400 | + }} |
| 401 | + > |
| 402 | + <Button |
| 403 | + variant="destructive" |
| 404 | + size="sm" |
| 405 | + isLoading={isRemovingDeployment} |
| 406 | + > |
| 407 | + Delete |
| 408 | + <Trash2 className="size-4" /> |
| 409 | + </Button> |
| 410 | + </DialogAction> |
| 411 | + )} |
| 412 | + |
375 | 413 | {deployment?.rollback && |
376 | 414 | deployment.status === "done" && |
377 | 415 | type === "application" && ( |
|
0 commit comments