From 17c4f3a1e88314dfcbf4baca46a4a87e18442b8d Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 17 Aug 2025 09:01:09 -0600 Subject: [PATCH] fix dns form --- .../routes/authorities/item.component.ts | 2 +- .../routes/system/routes/dns/dns.component.ts | 58 +++++++++++-------- .../ui/src/app/services/api/api.types.ts | 5 +- .../services/api/embassy-live-api.service.ts | 2 +- .../services/api/embassy-mock-api.service.ts | 6 +- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/web/projects/ui/src/app/routes/portal/routes/system/routes/authorities/item.component.ts b/web/projects/ui/src/app/routes/portal/routes/system/routes/authorities/item.component.ts index cd86f4f26..4370dc27c 100644 --- a/web/projects/ui/src/app/routes/portal/routes/system/routes/authorities/item.component.ts +++ b/web/projects/ui/src/app/routes/portal/routes/system/routes/authorities/item.component.ts @@ -63,7 +63,7 @@ import { Authority, AuthorityService } from './authority.service' iconStart="@tui.download" href="/static/local-root-ca.crt" > - {{ 'Download your Root CA' | i18n }} + {{ 'Download' | i18n }} } diff --git a/web/projects/ui/src/app/routes/portal/routes/system/routes/dns/dns.component.ts b/web/projects/ui/src/app/routes/portal/routes/system/routes/dns/dns.component.ts index 0e2fd55eb..2be6d19e6 100644 --- a/web/projects/ui/src/app/routes/portal/routes/system/routes/dns/dns.component.ts +++ b/web/projects/ui/src/app/routes/portal/routes/system/routes/dns/dns.component.ts @@ -115,29 +115,27 @@ export default class SystemDnsComponent { private readonly dnsSpec = ISB.InputSpec.of({ strategy: ISB.Value.union({ - name: 'DNS Servers', - default: 'defaults', + name: 'strategy', + default: 'dhcp', variants: ISB.Variants.of({ - defaults: { - name: 'Default', + dhcp: { + name: 'DHCP', spec: ISB.InputSpec.of({ - servers: ISB.Value.list( - ISB.List.text( - { - name: 'Default DNS Servers', - }, - {}, - ), - ), + servers: ISB.Value.dynamicText(() => ({ + name: 'DHCP Servers', + default: null, + required: true, + disabled: 'Cannot edit DHCP servers', + })), }), }, - custom: { - name: 'Custom', + static: { + name: 'Static', spec: ISB.InputSpec.of({ servers: ISB.Value.list( ISB.List.text( { - name: 'DNS Servers', + name: 'Static Servers', minLength: 1, maxLength: 3, }, @@ -158,14 +156,24 @@ export default class SystemDnsComponent { switchMap(async ([pkgs, { gateways, dns }]) => { const spec = await configBuilderToSpec(this.dnsSpec) - const current = dns.staticServers - ? { - selection: 'custom', - value: dns.staticServers, - } - : { selection: 'defaults', value: dns.dhcpServers } + const dhcpServers = { servers: dns.dhcpServers.join(', ') } + const staticServers = { servers: dns.staticServers || [] } - const form = this.formService.createForm(spec, current) + const current: (typeof this.dnsSpec._TYPE)['strategy'] = + dns.staticServers + ? { + selection: 'static', + value: staticServers, + other: { + dhcp: dhcpServers, + }, + } + : { + selection: 'dhcp', + value: dhcpServers, + } + + const form = this.formService.createForm(spec, { strategy: current }) return { spec, @@ -190,8 +198,10 @@ export default class SystemDnsComponent { try { await this.api.setDns({ - servers: value.strategy.value.servers, - static: value.strategy.selection === 'custom', + servers: + value.strategy.selection === 'dhcp' + ? null + : value.strategy.value.servers, }) } catch (e: any) { this.errorService.handleError(e) diff --git a/web/projects/ui/src/app/services/api/api.types.ts b/web/projects/ui/src/app/services/api/api.types.ts index 48bb3843e..d522f132b 100644 --- a/web/projects/ui/src/app/services/api/api.types.ts +++ b/web/projects/ui/src/app/services/api/api.types.ts @@ -105,9 +105,8 @@ export namespace RR { export type DiskRepairRes = null export type SetDnsReq = { - servers: string[] - static: boolean - } // net.dns.set + servers: string[] | null + } // net.dns.set-static export type SetDnsRes = null export type QueryDnsReq = { diff --git a/web/projects/ui/src/app/services/api/embassy-live-api.service.ts b/web/projects/ui/src/app/services/api/embassy-live-api.service.ts index 49e841a59..bc24c8065 100644 --- a/web/projects/ui/src/app/services/api/embassy-live-api.service.ts +++ b/web/projects/ui/src/app/services/api/embassy-live-api.service.ts @@ -269,7 +269,7 @@ export class LiveApiService extends ApiService { async setDns(params: RR.SetDnsReq): Promise { return this.rpcRequest({ - method: 'net.dns.set', + method: 'net.dns.set-static', params, }) } diff --git a/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts b/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts index 39ea7c3ca..faa797594 100644 --- a/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts +++ b/web/projects/ui/src/app/services/api/embassy-mock-api.service.ts @@ -465,11 +465,11 @@ export class MockApiService extends ApiService { async setDns(params: RR.SetDnsReq): Promise { await pauseFor(2000) - const patch: ReplaceOperation[] = [ + const patch: ReplaceOperation[] = [ { op: PatchOp.REPLACE, - path: '/serverInfo/network/dns', - value: params, + path: '/serverInfo/network/dns/staticServers', + value: params.servers, }, ] this.mockRevision(patch)