import { useState, useEffect } from 'react'; import { DiffEditor } from '@monaco-editor/react'; import { projectsAPI } from '../api'; import { useTheme } from '../context/ThemeContext'; import './TemplateUpdateModal.css'; function TemplateUpdateModal({ projectId, resource, onClose, onComplete }) { const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [templateDiff, setTemplateDiff] = useState(null); const [loadingDiff, setLoadingDiff] = useState(true); const { theme } = useTheme(); const loadTemplateDiff = async () => { setLoadingDiff(true); try { const response = await projectsAPI.getTemplateDiff( projectId, resource.uid, resource.rawYaml ); setTemplateDiff(response.data); } catch (err) { setError(err.response?.data?.detail || 'Failed to generate template diff'); } finally { setLoadingDiff(false); } }; // Load template diff when component mounts useEffect(() => { loadTemplateDiff(); }, []); const handleUpdateTemplate = async () => { setLoading(true); setError(''); try { await projectsAPI.updateTemplate( projectId, resource.uid, resource.rawYaml ); onComplete(); } catch (err) { setError(err.response?.data?.detail || 'Failed to update template'); } finally { setLoading(false); } }; return (
e.stopPropagation()}>

Update Template File

📝 Template Changes Detected

You modified the rendered resource {resource.kind}/{resource.name}. This will update the corresponding template file.

{loadingDiff ? (

Generating template diff...

) : error ? (
Error:

{error}

) : templateDiff ? ( <>
Template File: {templateDiff.template_file}
Changes: {templateDiff.additions} additions, {templateDiff.deletions} deletions
Template File Diff (Original ← → Modified):
⚠️ Important:
  • This will modify the template file in your chart
  • Changes may affect other resources if the template uses conditions
  • Make sure to review the diff carefully before confirming
  • You can re-render after updating to see the effect
) : null}
); } export default TemplateUpdateModal;