import React, { useCallback, useEffect, useState } from "react"; import { RefreshCw } from "lucide-react"; import { listCustomResourcesCmd } from "@/lib/tauriCommands"; import type { CustomResourceInfo } from "@/lib/tauriCommands"; interface CustomResourceListProps { clusterId: string; namespace: string; group: string; version: string; resource: string; kind: string; } export function CustomResourceList({ clusterId, namespace, group, version, resource, kind, }: CustomResourceListProps) { const [items, setItems] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const loadItems = useCallback(async () => { setLoading(true); setError(null); try { const data = await listCustomResourcesCmd(clusterId, group, version, resource, namespace); setItems(data); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setLoading(false); } }, [clusterId, group, version, resource, namespace]); useEffect(() => { void loadItems(); }, [loadItems]); if (loading) { return (
Loading {kind} instances…
); } if (error) { return (
{error}
); } if (items.length === 0) { return (

No {kind} instances found.

); } const showNamespace = items.some((item) => item.namespace !== ""); return (
{showNamespace && ( )} {items.map((item) => ( {showNamespace && ( )} ))}
NameNamespaceAge
{item.name}{item.namespace || "—"}{item.age}
); }