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"
href="/static/local-root-ca.crt"
>
{{ 'Download your Root CA' | i18n }}
{{ 'Download' | i18n }}
</a>
</tui-opt-group>
}

View File

@@ -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)

View File

@@ -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 = {

View File

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

View File

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