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

{actionError}

)}
Name Namespace Role Age Actions {roleBindings.length === 0 ? ( No role bindings found ) : ( roleBindings.map((rb) => ( {rb.name} {rb.namespace} {rb.role} {rb.age} openEdit(rb), }, { label: "Delete", icon: Trash2, variant: "destructive", onClick: () => setActiveModal({ type: "delete", rb }), }, ]} /> )) )}
{activeModal?.type === "edit" && ( { setActiveModal(null); onRefresh?.(); }} /> )} {activeModal?.type === "delete" && ( { if (!o) setActiveModal(null); }} resourceType="RoleBinding" resourceName={activeModal.rb.name} isLoading={isDeleting} onConfirm={handleDelete} /> )} ); }