Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[UI v2] feat: Moves delete deployment confirmation dialog logic to a re-usable hook #17001

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions ui-v2/src/components/deployments/data-table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import {
type DeploymentWithFlow,
useDeleteDeployment,
} from "@/api/deployments";
import { type DeploymentWithFlow } from "@/api/deployments";
import type { components } from "@/api/prefect";
import { useDeleteDeploymentConfirmationDialog } from "@/components/deployments/use-delete-deployment-confirmation-dialog";
import { DataTable } from "@/components/ui/data-table";
import {
DeleteConfirmationDialog,
useDeleteConfirmationDialog,
} from "@/components/ui/delete-confirmation-dialog";
import { DeleteConfirmationDialog } from "@/components/ui/delete-confirmation-dialog";
import { FlowRunActivityBarGraphTooltipProvider } from "@/components/ui/flow-run-activity-bar-graph";
import { Icon } from "@/components/ui/icons";
import { SearchInput } from "@/components/ui/input";
Expand All @@ -22,7 +17,6 @@ import {
import { StatusBadge } from "@/components/ui/status-badge";
import { TagBadgeGroup } from "@/components/ui/tag-badge-group";
import { TagsInput } from "@/components/ui/tags-input";
import { useToast } from "@/hooks/use-toast";
import { pluralize } from "@/utils";
import { Link } from "@tanstack/react-router";
import type {
Expand Down Expand Up @@ -167,9 +161,7 @@ export const DeploymentsDataTable = ({
onDuplicate,
}: DeploymentsDataTableProps) => {
const [deleteConfirmationDialogState, confirmDelete] =
useDeleteConfirmationDialog();
const { deleteDeployment } = useDeleteDeployment();
const { toast } = useToast();
useDeleteDeploymentConfirmationDialog();

const nameSearchValue = (columnFilters.find(
(filter) => filter.id === "flowOrDeploymentName",
Expand Down Expand Up @@ -224,19 +216,7 @@ export const DeploymentsDataTable = ({
const name = deployment.flow?.name
? `${deployment.flow?.name}/${deployment.name}`
: deployment.name;
confirmDelete({
title: "Delete Deployment",
description: `Are you sure you want to delete ${name}? This action cannot be undone.`,
onConfirm: () => {
deleteDeployment(deployment.id, {
onSuccess: () => {
toast({
title: "Deployment deleted",
});
},
});
},
});
confirmDelete({ ...deployment, name });
},
onDuplicate,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Deployment, useDeleteDeployment } from "@/api/deployments";
import { useDeleteConfirmationDialog } from "@/components/ui/delete-confirmation-dialog";
import { useToast } from "@/hooks/use-toast";
import { getRouteApi } from "@tanstack/react-router";

const routeApi = getRouteApi("/deployments/");

export const useDeleteDeploymentConfirmationDialog = () => {
const navigate = routeApi.useNavigate();
const { toast } = useToast();
const [dialogState, confirmDelete] = useDeleteConfirmationDialog();

const { deleteDeployment } = useDeleteDeployment();

const handleConfirmDelete = (
deployment: Deployment,
{
shouldNavigate = false,
}: {
/** Should navigate back to /deployments */
shouldNavigate?: boolean;
} = {},
) =>
confirmDelete({
title: "Delete Deployment",
description: `Are you sure you want to delete ${deployment.name}? This action cannot be undone.`,
onConfirm: () => {
deleteDeployment(deployment.id, {
onSuccess: () => {
toast({ title: "Deployment deleted" });
if (shouldNavigate) {
void navigate({ to: "/deployments" });
}
},
onError: (error) => {
const message =
error.message || "Unknown error while deleting deployment.";
console.error(message);
},
});
},
});

return [dialogState, handleConfirmDelete] as const;
};