refactor(k8s): 统一 YAML 精简视图与工具栏(复制/编辑/保存)
- 精简管道:对象剥离 + cleanYAML 默认值清理,查看/编辑默认精简 - 排除 status/managedFields/uid/ownerReferences 等主流噪音字段 - 移除「清理并编辑」「精简」按钮,改为「编辑」+ 文字链「原始 YAML」 - 保存走 prepareYamlForSave,ResourceVisualEditor YAML 模式同步
This commit is contained in:
1 parent
d66772481f
commit
eeba677850
3 files changed
+212
-214
No files matched your search
@@ -12,9 +12,8 @@ import { kubernetesApi } from '@/api';
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { yaml } from '@codemirror/lang-yaml';
|
||||
import { oneDark } from '@codemirror/theme-one-dark';
|
||||
import { cleanYAML } from './k8s-yaml-utils';
|
||||
import { createEmptyManifest } from './resource-create-templates';
|
||||
import { parseManifest, parseEditableManifest, dumpManifest, prepareManifestForSave } from './k8s-manifest-utils';
|
||||
import { parseManifest, parseEditableManifest, prepareManifestForSave, prepareYamlForSave } from './k8s-manifest-utils';
|
||||
|
||||
interface ResourceVisualEditorProps {
|
||||
clusterCode: string;
|
||||
@@ -89,7 +88,7 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
const handleSaveYaml = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const yamlStr = cleanYAML(editYaml);
|
||||
const yamlStr = await prepareYamlForSave(editYaml);
|
||||
if (isCreate) {
|
||||
await kubernetesApi.applyYAML(clusterCode, yamlStr);
|
||||
toast({ title: '创建成功', description: 'YAML 已应用' });
|
||||
@@ -116,10 +115,7 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
};
|
||||
|
||||
const switchToYaml = async () => {
|
||||
if (manifest) {
|
||||
const dumped = await dumpManifest(manifest);
|
||||
setEditYaml(cleanYAML(dumped));
|
||||
}
|
||||
if (manifest) setEditYaml(await prepareManifestForSave(manifest));
|
||||
setMode('yaml');
|
||||
};
|
||||
const resourceMeta: Record<string, { title: string; icon: any; color: string }> = {
|
||||
@@ -170,7 +166,6 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
<div className="flex items-center justify-center h-full py-20"><Loader2 className="h-6 w-6 animate-spin text-[var(--dg-text-muted)]" /></div>
|
||||
) : mode === 'yaml' ? (
|
||||
<div className="space-y-3">
|
||||
<p className="text-xs text-amber-400/80">⚠️ YAML 编辑模式 — 修改后点击保存。已自动清理只读字段(status/managedFields/uid)</p>
|
||||
<CodeMirror
|
||||
value={editYaml}
|
||||
height="550px"
|
||||
@@ -181,7 +176,10 @@ export function ResourceVisualEditor({ clusterCode, namespace, resource, name, o
|
||||
style={{ fontSize: '12px' }}
|
||||
/>
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => { setEditYaml(cleanYAML(rawYaml)); }}>重置</Button>
|
||||
<Button variant="outline" size="sm" onClick={async () => {
|
||||
const { yaml: stripped } = await parseEditableManifest(rawYaml);
|
||||
setEditYaml(stripped);
|
||||
}}>重置</Button>
|
||||
<Button size="sm" className="bg-blue-600 hover:bg-blue-700" onClick={handleSaveYaml} disabled={saving}>
|
||||
{saving ? <Loader2 className="h-3.5 w-3.5 animate-spin mr-1" /> : <Save className="h-3.5 w-3.5 mr-1" />}
|
||||
保存
|
||||
|
||||
Reference in new issue
Block a user