fix dns form

This commit is contained in:
Matt Hill
2025-08-17 09:01:09 -06:00
parent a0a2c20b08
commit 17c4f3a1e8
5 changed files with 41 additions and 32 deletions

View File

@@ -63,7 +63,7 @@ import { Authority, AuthorityService } from './authority.service'
iconStart="@tui.download" iconStart="@tui.download"
href="/static/local-root-ca.crt" href="/static/local-root-ca.crt"
> >
{{ 'Download your Root CA' | i18n }} {{ 'Download' | i18n }}
</a> </a>
</tui-opt-group> </tui-opt-group>
} }

View File

@@ -115,29 +115,27 @@ export default class SystemDnsComponent {
private readonly dnsSpec = ISB.InputSpec.of({ private readonly dnsSpec = ISB.InputSpec.of({
strategy: ISB.Value.union({ strategy: ISB.Value.union({
name: 'DNS Servers', name: 'strategy',
default: 'defaults', default: 'dhcp',
variants: ISB.Variants.of({ variants: ISB.Variants.of({
defaults: { dhcp: {
name: 'Default', name: 'DHCP',
spec: ISB.InputSpec.of({ spec: ISB.InputSpec.of({
servers: ISB.Value.list( servers: ISB.Value.dynamicText(() => ({
ISB.List.text( name: 'DHCP Servers',
{ default: null,
name: 'Default DNS Servers', required: true,
}, disabled: 'Cannot edit DHCP servers',
{}, })),
),
),
}), }),
}, },
custom: { static: {
name: 'Custom', name: 'Static',
spec: ISB.InputSpec.of({ spec: ISB.InputSpec.of({
servers: ISB.Value.list( servers: ISB.Value.list(
ISB.List.text( ISB.List.text(
{ {
name: 'DNS Servers', name: 'Static Servers',
minLength: 1, minLength: 1,
maxLength: 3, maxLength: 3,
}, },
@@ -158,14 +156,24 @@ export default class SystemDnsComponent {
switchMap(async ([pkgs, { gateways, dns }]) => { switchMap(async ([pkgs, { gateways, dns }]) => {
const spec = await configBuilderToSpec(this.dnsSpec) const spec = await configBuilderToSpec(this.dnsSpec)
const current = dns.staticServers const dhcpServers = { servers: dns.dhcpServers.join(', ') }
? { const staticServers = { servers: dns.staticServers || [] }
selection: 'custom',
value: dns.staticServers,
}
: { selection: 'defaults', value: dns.dhcpServers }
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 { return {
spec, spec,
@@ -190,8 +198,10 @@ export default class SystemDnsComponent {
try { try {
await this.api.setDns({ await this.api.setDns({
servers: value.strategy.value.servers, servers:
static: value.strategy.selection === 'custom', value.strategy.selection === 'dhcp'
? null
: value.strategy.value.servers,
}) })
} catch (e: any) { } catch (e: any) {
this.errorService.handleError(e) this.errorService.handleError(e)

View File

@@ -105,9 +105,8 @@ export namespace RR {
export type DiskRepairRes = null export type DiskRepairRes = null
export type SetDnsReq = { export type SetDnsReq = {
servers: string[] servers: string[] | null
static: boolean } // net.dns.set-static
} // net.dns.set
export type SetDnsRes = null export type SetDnsRes = null
export type QueryDnsReq = { export type QueryDnsReq = {

View File

@@ -269,7 +269,7 @@ export class LiveApiService extends ApiService {
async setDns(params: RR.SetDnsReq): Promise<RR.SetDnsRes> { async setDns(params: RR.SetDnsReq): Promise<RR.SetDnsRes> {
return this.rpcRequest({ return this.rpcRequest({
method: 'net.dns.set', method: 'net.dns.set-static',
params, params,
}) })
} }

View File

@@ -465,11 +465,11 @@ export class MockApiService extends ApiService {
async setDns(params: RR.SetDnsReq): Promise<RR.SetDnsRes> { async setDns(params: RR.SetDnsReq): Promise<RR.SetDnsRes> {
await pauseFor(2000) await pauseFor(2000)
const patch: ReplaceOperation<RR.SetDnsReq>[] = [ const patch: ReplaceOperation<T.DnsSettings['staticServers']>[] = [
{ {
op: PatchOp.REPLACE, op: PatchOp.REPLACE,
path: '/serverInfo/network/dns', path: '/serverInfo/network/dns/staticServers',
value: params, value: params.servers,
}, },
] ]
this.mockRevision(patch) this.mockRevision(patch)