import React, { useState } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui"; import { Pencil, Trash2 } from "lucide-react"; import type { WebhookConfigInfo } from "@/lib/tauriCommands"; import { deleteResourceCmd, getResourceYamlCmd } from "@/lib/tauriCommands"; import { ResourceActionMenu } from "./ResourceActionMenu"; import { ConfirmDeleteDialog } from "./ConfirmDeleteDialog"; import { EditResourceModal } from "./EditResourceModal"; interface ValidatingWebhookListProps { items: WebhookConfigInfo[]; clusterId: string; namespace?: string; onRefresh?: () => void; } type ActiveModal = | { type: "edit"; wh: WebhookConfigInfo; yaml: string } | { type: "delete"; wh: WebhookConfigInfo } | null; export function ValidatingWebhookList({ items, clusterId, onRefresh }: ValidatingWebhookListProps) { const [activeModal, setActiveModal] = useState(null); const [isDeleting, setIsDeleting] = useState(false); const [actionError, setActionError] = useState(null); const openEdit = async (wh: WebhookConfigInfo) => { setActionError(null); try { const yaml = await getResourceYamlCmd(clusterId, "validatingwebhookconfigurations", "", wh.name); setActiveModal({ type: "edit", wh, yaml }); } catch (err) { setActionError(err instanceof Error ? err.message : String(err)); } }; const handleDelete = async () => { if (activeModal?.type !== "delete") return; setIsDeleting(true); try { await deleteResourceCmd(clusterId, "validatingwebhookconfigurations", "", activeModal.wh.name); setActiveModal(null); onRefresh?.(); } finally { setIsDeleting(false); } }; return ( <> {actionError && (

{actionError}

)}
Name Webhooks Age Actions {items.length === 0 ? ( No validating webhook configurations found ) : ( items.map((wh) => ( {wh.name} {wh.webhooks} {wh.age} openEdit(wh), }, { label: "Delete", icon: Trash2, variant: "destructive", onClick: () => setActiveModal({ type: "delete", wh }), }, ]} /> )) )}
{activeModal?.type === "edit" && ( { setActiveModal(null); onRefresh?.(); }} /> )} {activeModal?.type === "delete" && ( { if (!o) setActiveModal(null); }} resourceType="ValidatingWebhookConfiguration" resourceName={activeModal.wh.name} isLoading={isDeleting} onConfirm={handleDelete} /> )} ); }