mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
fix(config-editor): preserve source YAML edits and empty keys
This commit is contained in:
@@ -78,7 +78,11 @@ function setStringInDoc(doc: YamlDocument, path: YamlPath, value: unknown): void
|
||||
doc.setIn(path, safe);
|
||||
return;
|
||||
}
|
||||
if (docHas(doc, path)) doc.deleteIn(path);
|
||||
// Preserve existing empty-string keys to avoid dropping template blocks/comments.
|
||||
// Only keep the key when it already exists in the YAML.
|
||||
if (docHas(doc, path)) {
|
||||
doc.setIn(path, '');
|
||||
}
|
||||
}
|
||||
|
||||
function setIntFromStringInDoc(doc: YamlDocument, path: YamlPath, value: unknown): void {
|
||||
|
||||
@@ -123,7 +123,8 @@ export function ConfigPage() {
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
const nextMergedYaml = applyVisualChangesToYaml(content);
|
||||
// In source mode, save exactly what the user edited. In visual mode, materialize visual changes into YAML.
|
||||
const nextMergedYaml = activeTab === 'source' ? content : applyVisualChangesToYaml(content);
|
||||
const latestServerYaml = await configFileApi.fetchConfigYaml();
|
||||
|
||||
if (latestServerYaml === nextMergedYaml) {
|
||||
@@ -156,10 +157,13 @@ export function ConfigPage() {
|
||||
if (tab === activeTab) return;
|
||||
|
||||
if (tab === 'source') {
|
||||
const nextContent = applyVisualChangesToYaml(content);
|
||||
if (nextContent !== content) {
|
||||
setContent(nextContent);
|
||||
setDirty(true);
|
||||
// Only rewrite YAML when there are pending visual changes; otherwise preserve raw YAML + comments.
|
||||
if (visualDirty) {
|
||||
const nextContent = applyVisualChangesToYaml(content);
|
||||
if (nextContent !== content) {
|
||||
setContent(nextContent);
|
||||
setDirty(true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
loadVisualValuesFromYaml(content);
|
||||
@@ -167,7 +171,7 @@ export function ConfigPage() {
|
||||
|
||||
setActiveTab(tab);
|
||||
localStorage.setItem('config-management:tab', tab);
|
||||
}, [activeTab, applyVisualChangesToYaml, content, loadVisualValuesFromYaml]);
|
||||
}, [activeTab, applyVisualChangesToYaml, content, loadVisualValuesFromYaml, visualDirty]);
|
||||
|
||||
// Search functionality
|
||||
const performSearch = useCallback((query: string, direction: 'next' | 'prev' = 'next') => {
|
||||
|
||||
Reference in New Issue
Block a user