mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-08-29 00:41:25 +08:00
fix(config): discard drafts without reloading
This commit is contained in:
@@ -277,11 +277,7 @@ export function ConfigPage() {
|
||||
) : (
|
||||
<SourceSearchBar search={sourceSearch} disabled={disableControls || doc.loading} />
|
||||
)}
|
||||
<ModeSwitch
|
||||
mode={mode}
|
||||
disabled={doc.saving || doc.loading}
|
||||
onChange={handleModeChange}
|
||||
/>
|
||||
<ModeSwitch mode={mode} disabled={doc.saving || doc.loading} onChange={handleModeChange} />
|
||||
</div>
|
||||
|
||||
{mode === 'visual' ? (
|
||||
@@ -322,7 +318,7 @@ export function ConfigPage() {
|
||||
saveDisabled={saveDisabled}
|
||||
discardDisabled={doc.loading || doc.saving}
|
||||
onSave={doc.handleSave}
|
||||
onDiscard={doc.handleReload}
|
||||
onDiscard={doc.handleDiscard}
|
||||
/>
|
||||
|
||||
<DiffModal
|
||||
|
||||
@@ -277,6 +277,27 @@ export function useConfigDocument({
|
||||
});
|
||||
}, [isDirty, loadConfig, showConfirmation, t]);
|
||||
|
||||
/** 无需联网,直接恢复最近一次成功读取的原始服务端 YAML。 */
|
||||
const handleDiscard = useCallback(() => {
|
||||
if (!isDirty) return;
|
||||
|
||||
showConfirmation({
|
||||
title: t('common.unsaved_changes_title'),
|
||||
message: t('config_management.discard_confirm_message'),
|
||||
confirmText: t('config_management.actions.discard'),
|
||||
cancelText: t('common.cancel'),
|
||||
variant: 'danger',
|
||||
onConfirm: () => {
|
||||
setContent(previewServerYaml);
|
||||
setDirty(false);
|
||||
setDiffModalOpen(false);
|
||||
setServerYaml(previewServerYaml);
|
||||
setMergedYaml(previewServerYaml);
|
||||
loadVisualValuesFromYaml(previewServerYaml);
|
||||
},
|
||||
});
|
||||
}, [isDirty, loadVisualValuesFromYaml, previewServerYaml, showConfirmation, t]);
|
||||
|
||||
const closeDiff = useCallback(() => setDiffModalOpen(false), []);
|
||||
|
||||
return {
|
||||
@@ -297,6 +318,7 @@ export function useConfigDocument({
|
||||
handleConfirmSave,
|
||||
handleChange,
|
||||
handleReload,
|
||||
handleDiscard,
|
||||
closeDiff,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -840,6 +840,7 @@
|
||||
"discard": "Discard changes",
|
||||
"save": "Save changes"
|
||||
},
|
||||
"discard_confirm_message": "Discard all unsaved changes and restore the last server version?",
|
||||
"mode": {
|
||||
"label": "Editor mode",
|
||||
"visual": "Visual",
|
||||
|
||||
@@ -827,6 +827,7 @@
|
||||
"discard": "Отменить изменения",
|
||||
"save": "Сохранить изменения"
|
||||
},
|
||||
"discard_confirm_message": "Отменить все несохранённые изменения и восстановить последнюю версию с сервера?",
|
||||
"mode": {
|
||||
"label": "Режим редактора",
|
||||
"visual": "Визуальный",
|
||||
|
||||
@@ -840,6 +840,7 @@
|
||||
"discard": "放弃更改",
|
||||
"save": "保存更改"
|
||||
},
|
||||
"discard_confirm_message": "确定放弃所有未保存的更改并恢复到最近的服务器版本吗?",
|
||||
"mode": {
|
||||
"label": "编辑模式",
|
||||
"visual": "可视化",
|
||||
|
||||
@@ -866,6 +866,7 @@
|
||||
"discard": "放棄變更",
|
||||
"save": "儲存變更"
|
||||
},
|
||||
"discard_confirm_message": "確定放棄所有未儲存的變更並還原到最近的伺服器版本嗎?",
|
||||
"mode": {
|
||||
"label": "編輯模式",
|
||||
"visual": "視覺化",
|
||||
|
||||
Reference in New Issue
Block a user