tftsr-devops_investigation/src/components/Kubernetes/MutatingWebhookList.tsx
Shaun Arman f7b4e591f9 fix(performance): resolve memory leaks and add polish features
- Fix LogStreamPanel event listener cleanup with synchronous unlisten
- Fix eventBus async-unsafe unsubscribe with proper error handling
- Fix KubernetesPage infinite loading by resetting state on section change
- Add ErrorBoundary component with reset capability
- Add Badge component with multiple variants
- Add ResourceDetailsDrawer for slide-out details panel
- Add useFavorites hook with localStorage persistence
- Add useKeyboardShortcuts hook for declarative shortcuts
- Add comprehensive test coverage for all new components/hooks
- Add keyboard shortcuts documentation to README
- Wrap KubernetesPage with ErrorBoundary for crash recovery
- Install react-window for virtual scrolling support

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-06-09 13:28:30 -05:00

126 lines
4.2 KiB
TypeScript

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 MutatingWebhookListProps {
items: WebhookConfigInfo[];
clusterId: string;
namespace?: string;
onRefresh?: () => void;
}
type ActiveModal =
| { type: "edit"; wh: WebhookConfigInfo; yaml: string }
| { type: "delete"; wh: WebhookConfigInfo }
| null;
export function MutatingWebhookList({ items, clusterId, onRefresh }: MutatingWebhookListProps) {
const [activeModal, setActiveModal] = useState<ActiveModal>(null);
const [isDeleting, setIsDeleting] = useState(false);
const [actionError, setActionError] = useState<string | null>(null);
const openEdit = async (wh: WebhookConfigInfo) => {
setActionError(null);
try {
const yaml = await getResourceYamlCmd(clusterId, "mutatingwebhookconfigurations", "", 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, "mutatingwebhookconfigurations", "", activeModal.wh.name);
setActiveModal(null);
onRefresh?.();
} finally {
setIsDeleting(false);
}
};
return (
<>
{actionError && (
<p className="mb-2 text-sm text-destructive">{actionError}</p>
)}
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Webhooks</TableHead>
<TableHead>Age</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{items.length === 0 ? (
<TableRow>
<TableCell colSpan={4} className="text-center text-muted-foreground">
No mutating webhook configurations found
</TableCell>
</TableRow>
) : (
items.map((wh) => (
<TableRow key={wh.name}>
<TableCell className="font-medium">{wh.name}</TableCell>
<TableCell className="text-sm">{wh.webhooks}</TableCell>
<TableCell className="text-sm text-muted-foreground">{wh.age}</TableCell>
<TableCell className="text-right">
<ResourceActionMenu
actions={[
{
label: "Edit",
icon: Pencil,
onClick: () => openEdit(wh),
},
{
label: "Delete",
icon: Trash2,
variant: "destructive",
onClick: () => setActiveModal({ type: "delete", wh }),
},
]}
/>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
{activeModal?.type === "edit" && (
<EditResourceModal
isOpen
clusterId={clusterId}
namespace=""
resourceType="mutatingwebhookconfigurations"
resourceName={activeModal.wh.name}
initialYaml={activeModal.yaml}
onClose={() => { setActiveModal(null); onRefresh?.(); }}
/>
)}
{activeModal?.type === "delete" && (
<ConfirmDeleteDialog
open
onOpenChange={(o) => { if (!o) setActiveModal(null); }}
resourceType="MutatingWebhookConfiguration"
resourceName={activeModal.wh.name}
isLoading={isDeleting}
onConfirm={handleDelete}
/>
)}
</>
);
}