import { useState, useEffect } from 'react'; import { Settings, Save, X } from 'lucide-react'; import { useConfigYaml } from '../hooks'; import { Button, Textarea } from './ui'; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger} from '@/components/ui/dialog'; export function ConfigEditor() { const { yamlContent, isLoading, error, isEndpointMissing, updateYaml, refetch } = useConfigYaml(); const [editedContent, setEditedContent] = useState(''); const [hasChanges, setHasChanges] = useState(false); // Update edited content when YAML content changes useEffect(() => { if (yamlContent) { setEditedContent(yamlContent); setHasChanges(false); } }, [yamlContent]); // Track changes useEffect(() => { setHasChanges(editedContent !== yamlContent); }, [editedContent, yamlContent]); const handleSave = () => { if (!hasChanges) return; updateYaml(editedContent, { onSuccess: () => { setHasChanges(false); }, onError: (err) => { console.error('Failed to update config:', err); } }); }; const handleOpenChange = (open: boolean) => { if (!open && hasChanges) { if (!window.confirm('You have unsaved changes. Close anyway?')) { return; } } if (open) { refetch(); } }; return ( Configuration Editor Edit the raw YAML configuration file. This provides direct access to all configuration options.
{error && error instanceof Error && error.message && (

Error: {error.message}

)} {isEndpointMissing && (

Backend endpoints missing. Raw YAML editing not available.

)}