fix(config): confirm before reloading dirty config

This commit is contained in:
Supra4E8C
2026-03-07 14:00:20 +08:00
parent 091c6f7304
commit 25598dd219
4 changed files with 25 additions and 3 deletions
+1
View File
@@ -1067,6 +1067,7 @@
"title": "Config Panel",
"editor_title": "Configuration File",
"reload": "Reload",
"reload_confirm_message": "Reloading will discard your unsaved changes. Do you want to continue?",
"save": "Save",
"description": "Edit config.yaml via visual editor or source file",
"status_idle": "Waiting for action",
+1
View File
@@ -1070,6 +1070,7 @@
"title": "Панель конфигурации",
"editor_title": "Файл конфигурации",
"reload": "Перезагрузить",
"reload_confirm_message": "Перезагрузка отбросит ваши несохранённые изменения. Продолжить?",
"save": "Сохранить",
"description": "Редактируйте config.yaml через визуальный редактор или исходный файл",
"status_idle": "Ожидание действия",
+1
View File
@@ -1067,6 +1067,7 @@
"title": "配置面板",
"editor_title": "配置文件",
"reload": "重新加载",
"reload_confirm_message": "重新加载将丢弃你当前未保存的修改,确定继续吗?",
"save": "保存",
"description": "通过可视化或者源文件方式编辑 config.yaml 配置文件",
"status_idle": "等待操作",
+22 -3
View File
@@ -31,7 +31,8 @@ function readCommercialModeFromYaml(yamlContent: string): boolean {
export function ConfigPage() {
const { t } = useTranslation();
const { showNotification } = useNotificationStore();
const showNotification = useNotificationStore((state) => state.showNotification);
const showConfirmation = useNotificationStore((state) => state.showConfirmation);
const connectionStatus = useAuthStore((state) => state.connectionStatus);
const resolvedTheme = useThemeStore((state) => state.resolvedTheme);
@@ -401,6 +402,24 @@ export function ConfigPage() {
return '';
};
const handleReload = useCallback(() => {
if (!isDirty) {
void loadConfig();
return;
}
showConfirmation({
title: t('common.unsaved_changes_title'),
message: t('config_management.reload_confirm_message'),
confirmText: t('config_management.reload'),
cancelText: t('common.cancel'),
variant: 'danger',
onConfirm: async () => {
await loadConfig();
},
});
}, [isDirty, loadConfig, showConfirmation, t]);
const floatingActions = (
<div className={styles.floatingActionContainer} ref={floatingActionsRef}>
<div className={styles.floatingActionList}>
@@ -408,8 +427,8 @@ export function ConfigPage() {
<button
type="button"
className={styles.floatingActionButton}
onClick={loadConfig}
disabled={loading}
onClick={handleReload}
disabled={loading || saving}
title={t('config_management.reload')}
aria-label={t('config_management.reload')}
>