import React, { useCallback, useEffect, useState } from "react"; import { RefreshCw, ChevronRight, ChevronDown } from "lucide-react"; import { Badge, Button } from "@/components/ui"; import { listCrdsCmd } from "@/lib/tauriCommands"; import type { CrdInfo } from "@/lib/tauriCommands"; import { CustomResourceList } from "./CustomResourceList"; interface CrdListProps { clusterId: string; onSelectCrd?: (crd: CrdInfo) => void; } function scopeVariant(scope: string): "default" | "secondary" { return scope === "Namespaced" ? "default" : "secondary"; } export function CrdList({ clusterId, onSelectCrd }: CrdListProps) { const [crds, setCrds] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [expandedCrd, setExpandedCrd] = useState(null); const loadCrds = useCallback(async () => { setLoading(true); setError(null); try { const data = await listCrdsCmd(clusterId); setCrds(data); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setLoading(false); } }, [clusterId]); useEffect(() => { void loadCrds(); }, [loadCrds]); const handleRowClick = (crd: CrdInfo) => { const key = crd.name; setExpandedCrd((prev) => (prev === key ? null : key)); onSelectCrd?.(crd); }; if (loading) { return (
Loading CRDs…
); } return (
{crds.length} custom resource definition{crds.length !== 1 ? "s" : ""}
{error && (
{error}
)}
{crds.length === 0 ? (
No custom resource definitions found
) : ( {crds.map((crd) => { const isExpanded = expandedCrd === crd.name; return ( handleRowClick(crd)} > {isExpanded && ( )} ); })}
Name Kind Group Version Scope Age
{isExpanded ? ( ) : ( )} {crd.name}
{crd.kind} {crd.group} {crd.version} {crd.scope} {crd.age}
)}
); }