feat(network): centralize proxy settings and add MCP routing (NAN-315) (#6372)
* feat(network): share proxy settings across features and MCP (NAN-315) * fix(network): address shared proxy review regressions * test(network): align rebased OAuth fixtures with runtime admission * fix(webui): configure shared proxy without leaving connection drafts * feat(webui): add optional shared proxy authentication editor * fix(webui): align proxy save tests and loading skeleton
This commit is contained in:
1 parent
872a83340d
commit
084b6bb394
181 files changed
+3740
-807
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { SettingsHint } from "@/components/settings/shared/SettingsHint";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { SharedProxyEditor } from "@/components/settings/shared/SharedProxyEditor";
|
||||
|
||||
export function SharedProxySetupDialog({ onClose, onSave, busy }: {
|
||||
busy: boolean;
|
||||
onClose: () => void;
|
||||
onSave: (address: string) => Promise<void>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [address, setAddress] = useState("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const origin = useRef(document.activeElement?.closest("[data-proxy-control]") ?? null);
|
||||
const title = t("settings.runtimeConfig.fields.network_proxy.label");
|
||||
useEffect(() => { if (error && !saving) input.current?.focus(); }, [error, saving]);
|
||||
const save = async () => {
|
||||
if (saving || busy || !address.trim()) return;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await onSave(address);
|
||||
onClose();
|
||||
} catch (cause) {
|
||||
setError(cause instanceof Error ? cause.message : String(cause));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Dialog open onOpenChange={(open) => { if (!open && !saving) onClose(); }}>
|
||||
<DialogContent className="max-w-sm" showCloseButton={!saving}
|
||||
onOpenAutoFocus={(event) => { event.preventDefault(); input.current?.focus(); }}
|
||||
onCloseAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
const row = origin.current;
|
||||
const target = row?.querySelector<HTMLElement>('[role="switch"]') ?? row?.querySelector<HTMLElement>("button:last-child");
|
||||
target?.focus();
|
||||
}}
|
||||
onEscapeKeyDown={(event) => { if (saving) event.preventDefault(); }}
|
||||
onPointerDownOutside={(event) => { if (saving) event.preventDefault(); }}>
|
||||
<form className="space-y-4" onSubmit={(event) => { event.preventDefault(); void save(); }}>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="pr-6 text-base">
|
||||
<SettingsHint description={t("settings.runtimeConfig.fields.network_proxy.help")}>{title}</SettingsHint>
|
||||
</DialogTitle>
|
||||
<DialogDescription>{t("settings.network.sharedProxyScope")}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-2">
|
||||
<SharedProxyEditor value={address} inputRef={input} disabled={saving} stackCredentials
|
||||
addressProps={{ "aria-invalid": Boolean(error), "aria-describedby": error ? "shared-proxy-setup-error" : undefined }}
|
||||
onChange={(next) => { setAddress(next); setError(""); }} />
|
||||
{error ? <p id="shared-proxy-setup-error" role="alert" className="break-words text-[13px] text-destructive">{error}</p> : null}
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="outline" disabled={saving} onClick={onClose}>{t("settings.actions.cancel")}</Button>
|
||||
<Button type="submit" disabled={saving || busy || !address.trim()}>{saving ? t("settings.actions.saving") : t("settings.actions.save")}</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user