fix(webui): allow closing image settings without valid credentials

Separate capability dialog dismissal from save completion while retaining controller-owned drafts and visible errors.

Co-authored-by: QQQ300kuai <934795001@qq.com>
This commit is contained in:
chengyongruandQQQ300kuai authored and chengyongru committed 2026-11-04 16:30:07 +08:00
1 parent 34bab234b5
commit 1c66b90088
3 files changed
+61 -17

No files matched your search

@@ -230,20 +230,20 @@ export function SettingsPage({
{!showSidebar && settings.requires_restart ? <RestartRequiredNotice message={t("settings.status.savedRestartApply")}
onRestart={restartViaSettingsSurface} isRestarting={restartInProgress} /> : null}
</div>
<SettingsFeature onBeforeClose={controller.imageEdits.needsCompletion() ? controller.imageEdits.commit : undefined} title={t("settings.rows.imageGeneration")} enabled={capabilityState.imageGenerationForm.enabled}
<SettingsFeature onClose={() => { void controller.imageEdits.commit(); }} title={t("settings.rows.imageGeneration")} enabled={capabilityState.imageGenerationForm.enabled}
error={capabilityState.imageGenerationForm.enabled && !settings.image_generation.providers.find((provider) => provider.name === capabilityState.imageGenerationForm.provider)?.configured
? t("settings.image.missingCredential") : capabilityState.capabilityErrors.image}
disabled={restartInProgress || capabilityState.imageGenerationSaving} initialOpen={activeSection === "image"}
onChange={(enabled) => capabilityState.setImageGenerationForm((prev) => ({ ...prev, enabled }))}>
{renderSection("image", true)}
</SettingsFeature>
<SettingsFeature onBeforeClose={controller.transcriptionEdits.needsCompletion() ? controller.transcriptionEdits.commit : undefined} title={t("settings.rows.transcription")} enabled={capabilityState.transcriptionForm.enabled}
<SettingsFeature onClose={() => { void controller.transcriptionEdits.commit(); }} title={t("settings.rows.transcription")} enabled={capabilityState.transcriptionForm.enabled}
error={capabilityState.capabilityErrors.voice}
disabled={restartInProgress || capabilityState.transcriptionSaving} initialOpen={activeSection === "voice"}
onChange={(enabled) => capabilityState.setTranscriptionForm((prev) => ({ ...prev, enabled }))}>
{renderSection("voice", true)}
</SettingsFeature>
<SettingsFeature onBeforeClose={controller.webEdits.needsCompletion() ? controller.webEdits.commit : undefined} title={t("settings.runtimeConfig.groups.web.title")}
<SettingsFeature onClose={() => { void controller.webEdits.commit(); }} title={t("settings.runtimeConfig.groups.web.title")}
enabled={settings.runtime_config ? state.value("tools.web.enable") === true : settings.web.enable}
disabled={restartInProgress || state.saving === "web" || !settings.runtime_config}
initialOpen={activeSection === "browser"} error={state.errors.web || capabilityState.capabilityErrors.web}
@@ -22,7 +22,7 @@ export function SettingsAdvancedOptions({ children }: { children: ReactNode }) {
}
export function SettingsFeature({
title, enabled, onChange, disabled, initialOpen = false, error, children, onBeforeClose,
title, enabled, onChange, disabled, initialOpen = false, error, children, onClose,
}: {
title: string;
enabled: boolean;
@@ -31,7 +31,7 @@ export function SettingsFeature({
initialOpen?: boolean;
error?: string;
children?: ReactNode;
onBeforeClose?: () => Promise<boolean>;
onClose?: () => void;
}) {
const { t } = useTranslation();
const [open, setOpen] = useState(initialOpen && enabled);
@@ -45,9 +45,8 @@ export function SettingsFeature({
return (
<section ref={section} aria-label={title}>
<Dialog open={Boolean(children) && open} onOpenChange={(next) => {
if (!next && onBeforeClose) {
void onBeforeClose().then((saved) => { if (saved) setOpen(false); });
} else setOpen(next);
setOpen(next);
if (!next) onClose?.();
}}>
<SettingsGroup>
<SettingsRow title={children ? (