diff --git a/ui/src/routes/devices.$id.settings.network.tsx b/ui/src/routes/devices.$id.settings.network.tsx index 7be6ef51..799fb6d2 100644 --- a/ui/src/routes/devices.$id.settings.network.tsx +++ b/ui/src/routes/devices.$id.settings.network.tsx @@ -186,31 +186,71 @@ export default function SettingsNetworkRoute() { const settings = prepareSettings(data); const dirty = formState.dirtyFields; - // These fields will prompt a confirm dialog, all else save immediately - const criticalFields = [ - // Label is for the UI, key is the internal key of the field - { label: "IPv4 mode", key: "ipv4_mode" }, - { label: "IPv6 mode", key: "ipv6_mode" }, - { label: "DHCP client", key: "dhcp_client" }, - ] as { label: string; key: keyof NetworkSettings }[]; + // Build list of critical changes for display + const changes: { label: string; from: string; to: string }[] = []; - const criticalChanged = criticalFields.some(field => dirty[field.key]); + if (dirty.dhcp_client) { + changes.push({ + label: "DHCP client", + from: initialSettingsRef.current?.dhcp_client as string, + to: data.dhcp_client as string, + }); + } + + if (dirty.ipv4_mode) { + changes.push({ + label: "IPv4 mode", + from: initialSettingsRef.current?.ipv4_mode as string, + to: data.ipv4_mode as string, + }); + } + + if (dirty.ipv4_static?.address) { + changes.push({ + label: "IPv4 address", + from: initialSettingsRef.current?.ipv4_static?.address as string, + to: data.ipv4_static?.address as string, + }); + } + + if (dirty.ipv4_static?.netmask) { + changes.push({ + label: "IPv4 netmask", + from: initialSettingsRef.current?.ipv4_static?.netmask as string, + to: data.ipv4_static?.netmask as string, + }); + } + + if (dirty.ipv4_static?.gateway) { + changes.push({ + label: "IPv4 gateway", + from: initialSettingsRef.current?.ipv4_static?.gateway as string, + to: data.ipv4_static?.gateway as string, + }); + } + + if (dirty.ipv4_static?.dns) { + changes.push({ + label: "IPv4 DNS", + from: initialSettingsRef.current?.ipv4_static?.dns.join(", ").toString() ?? "", + to: data.ipv4_static?.dns.join(",").toString() ?? "", + }); + } + + if (dirty.ipv6_mode) { + changes.push({ + label: "IPv6 mode", + from: initialSettingsRef.current?.ipv6_mode as string, + to: data.ipv6_mode as string, + }); + } // If no critical fields are changed, save immediately - if (!criticalChanged) return onSubmit(settings); - - const changes = new Set<{ label: string; from: string; to: string }>(); - criticalFields.forEach(field => { - const { key, label } = field; - if (dirty[key]) { - const from = initialSettingsRef?.current?.[key] as string; - const to = data[key] as string; - changes.add({ label, from, to }); - } - }); + if (changes.length === 0) return onSubmit(settings); + // Show confirmation dialog for critical changes setStagedSettings(settings); - setCriticalChanges(Array.from(changes)); + setCriticalChanges(changes); setShowCriticalSettingsConfirm(true); }; @@ -263,7 +303,7 @@ export default function SettingsNetworkRoute() { {networkState?.mac_address} {" "} -