import React from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from "@/components/ui"; import { Button } from "@/components/ui"; import { Input } from "@/components/ui"; import { Label } from "@/components/ui"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui"; import { YamlEditor } from "./YamlEditor"; import { editResourceCmd } from "@/lib/tauriCommands"; import { Loader2 } from "lucide-react"; interface EditResourceModalProps { isOpen: boolean; clusterId: string; namespace: string; resourceType: string; resourceName: string; initialYaml?: string; onClose?: () => void; } export function EditResourceModal({ isOpen, clusterId, namespace, resourceType, resourceName, initialYaml = "", onClose, }: EditResourceModalProps) { const [activeTab, setActiveTab] = React.useState("yaml"); const [name, setName] = React.useState(resourceName); const [currentNamespace, setCurrentNamespace] = React.useState(namespace); const [yamlContent, setYamlContent] = React.useState(initialYaml); const [isLoading, setIsLoading] = React.useState(false); const [error, setError] = React.useState(null); const [yamlReady, setYamlReady] = React.useState(false); React.useEffect(() => { setName(resourceName); setCurrentNamespace(namespace); setYamlContent(initialYaml); // Mark YAML as ready once we have content if (initialYaml) { setYamlReady(true); } }, [resourceName, namespace, initialYaml]); const handleSubmit = async () => { setIsLoading(true); setError(null); try { await editResourceCmd( clusterId, currentNamespace, resourceType, name, yamlContent ); onClose?.(); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setIsLoading(false); } }; return ( onClose?.()}> Edit Kubernetes Resource Form YAML
setName(e.target.value)} placeholder="Enter resource name" />

Resource Details

Name: {name || "not specified"}

Namespace: {currentNamespace}

Type: {resourceType}

{yamlReady ? ( ) : (
)}
{error && (

{error}

)}
); }