[web] Domi UI: the web UI on @domi/ui v1.0.0 (fonts, roles, Button, TextField with seals, Checkbox, Select, Segmented)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
// Handoff §6 and §7: the add/edit panel, its validation on blur, Apply, and the progress and
|
||||
// outcome of the apply it starts. Every decision comes from control; the form only carries it.
|
||||
import { onDestroy, onMount } from "svelte";
|
||||
import { Checkbox, Select, TextField } from "@domi/ui";
|
||||
import { Banner, Button, Details, Dialog, Icon, Segmented } from "@ianitor/ui";
|
||||
import ApplyProgress from "./ApplyProgress.svelte";
|
||||
import { ApiError, call, del, get, newKey, sentence } from "../lib/api";
|
||||
@@ -60,6 +61,24 @@
|
||||
let idem = newKey();
|
||||
let lastBody = "";
|
||||
|
||||
// Every text field carries its seal (domi-design TextField): `next` moves to the next field, and the last text
|
||||
// field of the form applies it, as the Apply button does. The last one depends on what is shown.
|
||||
const lastField = $derived.by(() => {
|
||||
const keys = ["hostname", ...host.upstreams.map((_, i) => `upstreams[${i}]`)];
|
||||
if (more) {
|
||||
if (host.hc) keys.push("health_check.path");
|
||||
for (const [list, rules, secrets] of [["request_headers", host.req, true], ["response_headers", host.resp, false]] as const) {
|
||||
rules.forEach((r, i) => {
|
||||
keys.push(`${list}[${i}].name`);
|
||||
if (r.action === "set" && !(secrets && r.kind === "secret")) keys.push(`${list}[${i}].value`);
|
||||
});
|
||||
}
|
||||
}
|
||||
return keys.at(-1);
|
||||
});
|
||||
const seal = (key: string) =>
|
||||
key === lastField ? { action: "save" as const, actionLabel: "Apply this host" } : { action: "next" as const, actionLabel: undefined };
|
||||
|
||||
// ---- the apply
|
||||
let apply = $state<ApplyView | null>(null);
|
||||
let restoring = $state(false);
|
||||
@@ -392,43 +411,36 @@
|
||||
{#if topError.body.detail}<Details detail={topError.body.detail} reference={topError.requestId} />{/if}
|
||||
{/if}
|
||||
|
||||
<div class="domi-field">
|
||||
<label class="domi-field-label" for={fieldId("hostname")}>Hostname</label>
|
||||
<input id={fieldId("hostname")} class="domi-input" bind:value={host.hostname} readonly={!!hostname}
|
||||
autocapitalize="none" spellcheck="false" inputmode="url" autocomplete="off"
|
||||
aria-invalid={errAt("hostname") && touched["hostname"] ? "true" : undefined}
|
||||
aria-describedby="{fieldId('hostname')}-e {fieldId('hostname')}-h" onblur={() => blur("hostname")} />
|
||||
{#if errAt("hostname") && touched["hostname"]}
|
||||
<p class="domi-error" id="{fieldId('hostname')}-e"><Icon name="ring" />{errAt("hostname").message}
|
||||
{#if errAt("hostname").params?.suggestion}
|
||||
<button type="button" class="domi-btn link" onclick={() => { host.hostname = errAt("hostname").params.suggestion; blur("hostname"); }}>Use {errAt("hostname").params.suggestion}</button>
|
||||
{/if}
|
||||
</p>
|
||||
<div class="ia-field" onfocusout={() => blur("hostname")}>
|
||||
<TextField id={fieldId("hostname")} label="Hostname" bind:value={host.hostname} readonly={!!hostname}
|
||||
spellcheck={false} inputmode="url" autocomplete="off" {...seal("hostname")}
|
||||
error={errAt("hostname") && touched["hostname"] ? errAt("hostname").message : undefined}
|
||||
hint={hostname ? "To use another address, add a new host and remove this one." : undefined} />
|
||||
{#if errAt("hostname") && touched["hostname"] && errAt("hostname").params?.suggestion}
|
||||
<div><button type="button" class="ia-link" onclick={() => { host.hostname = errAt("hostname").params.suggestion; blur("hostname"); }}>Use {errAt("hostname").params.suggestion}</button></div>
|
||||
{/if}
|
||||
{#if hostname}<p class="ia-hint" id="{fieldId('hostname')}-h">To use another address, add a new host and remove this one.</p>{/if}
|
||||
</div>
|
||||
|
||||
{#each host.upstreams as _, i (i)}
|
||||
{@const f = `upstreams[${i}]`}
|
||||
{@const err = errAt(f) ?? (i === 0 ? errAt("upstreams") : undefined)}
|
||||
<div class="domi-field">
|
||||
{#if i === 0}<label class="domi-field-label" for={fieldId(f)}>Send traffic to</label>{/if}
|
||||
{@const shown = err && (touched[f] || touched["upstreams"])}
|
||||
<div class="ia-field" onfocusout={() => blur(f)}>
|
||||
<div class="row">
|
||||
<input id={fieldId(f)} class="domi-input" bind:value={host.upstreams[i]} autocapitalize="none" spellcheck="false" inputmode="url" autocomplete="off"
|
||||
aria-label={i === 0 ? undefined : `Also send traffic to, address ${i + 1}`}
|
||||
aria-invalid={err && (touched[f] || touched["upstreams"]) ? "true" : undefined}
|
||||
aria-describedby="{fieldId(f)}-e" onblur={() => blur(f)} />
|
||||
<div class="grow">
|
||||
<TextField id={fieldId(f)} label={i === 0 ? "Send traffic to" : `Also send traffic to, address ${i + 1}`} hideLabel={i > 0}
|
||||
bind:value={host.upstreams[i]} spellcheck={false} inputmode="url" autocomplete="off" {...seal(f)}
|
||||
error={shown ? err.message : undefined}
|
||||
hint={i === 0 && host.upstreams.length === 1 ? "Add another address later for a second server." : undefined} />
|
||||
</div>
|
||||
{#if i > 0}<button type="button" class="ia-icon-btn" aria-label="Remove this address" onclick={() => host.upstreams.splice(i, 1)}><Icon name="trash" /></button>{/if}
|
||||
</div>
|
||||
{#if err && (touched[f] || touched["upstreams"])}
|
||||
<p class="domi-error" id="{fieldId(f)}-e"><Icon name="ring" />{err.message}
|
||||
{#if err.params?.suggestion}<button type="button" class="domi-btn link" onclick={() => { host.upstreams[i] = err.params.suggestion; blur(f); }}>Use {err.params.suggestion}</button>{/if}
|
||||
</p>
|
||||
{#if shown && err.params?.suggestion}
|
||||
<div><button type="button" class="ia-link" onclick={() => { host.upstreams[i] = err.params.suggestion; blur(f); }}>Use {err.params.suggestion}</button></div>
|
||||
{/if}
|
||||
{#if i === 0 && host.upstreams.length === 1}<p class="ia-hint">Add another address later for a second server.</p>{/if}
|
||||
</div>
|
||||
{/each}
|
||||
<div><button type="button" class="domi-btn link" onclick={() => host.upstreams.push("")}>Add another address</button></div>
|
||||
<div><button type="button" class="ia-link" onclick={() => host.upstreams.push("")}>Add another address</button></div>
|
||||
|
||||
<Segmented legend="Certificate" name="tls" bind:value={host.tls}
|
||||
options={[{ value: "domi", label: "Domi certificate" }, { value: "letsencrypt", label: "Let's Encrypt" }]} />
|
||||
@@ -437,77 +449,77 @@
|
||||
<Segmented legend="Who can open it" name="auth" bind:value={host.auth} disabled={signinOk ? [] : ["forward-auth"]}
|
||||
options={[{ value: "forward-auth", label: "Sign in first" }, { value: "none", label: "Anyone" }]} />
|
||||
{#if !signinOk}<p class="ia-hint">Sign-in is not set up on this server yet, so choose Anyone for now. To set it up, add the Authelia address to ianitor.toml in the routes repository.</p>{/if}
|
||||
{#if errAt("auth")}<p class="domi-error"><Icon name="ring" />{errAt("auth").message}</p>{/if}
|
||||
{#if errAt("auth")}<p class="ia-error"><Icon name="ring" />{errAt("auth").message}</p>{/if}
|
||||
|
||||
<div>
|
||||
<button type="button" class="domi-btn link" aria-expanded={more} aria-controls="more-options" onclick={() => (more = !more)}>
|
||||
<button type="button" class="ia-link" aria-expanded={more} aria-controls="more-options" onclick={() => (more = !more)}>
|
||||
More options: headers, websockets, health check, share links, visit log
|
||||
</button>
|
||||
</div>
|
||||
{#if more}
|
||||
<div id="more-options" class="more">
|
||||
<div class="domi-field">
|
||||
<span class="domi-field-label">Health check</span>
|
||||
<label class="ia-check"><input type="checkbox" bind:checked={host.hc} /> Check that it answers</label>
|
||||
<div class="ia-field">
|
||||
<span class="ia-field-label">Health check</span>
|
||||
<Checkbox bind:checked={host.hc} label="Check that it answers" />
|
||||
<p class="ia-hint">Ianitor asks this address regularly and shows the result on the main screen.</p>
|
||||
</div>
|
||||
{#if host.hc}
|
||||
<div class="domi-field">
|
||||
<label class="domi-field-label" for={fieldId("health_check.path")}>Health check address</label>
|
||||
<input id={fieldId("health_check.path")} class="domi-input" bind:value={host.hcPath} aria-invalid={errAt("health_check.path") ? "true" : undefined} onblur={() => blur("health_check.path")} />
|
||||
{#if errAt("health_check.path")}<p class="domi-error"><Icon name="ring" />{errAt("health_check.path").message}</p>{/if}
|
||||
<p class="ia-hint">Use an address that answers without signing in, like /health.</p>
|
||||
<div class="ia-field" onfocusout={() => blur("health_check.path")}>
|
||||
<TextField id={fieldId("health_check.path")} label="Health check address" bind:value={host.hcPath} spellcheck={false}
|
||||
autocomplete="off" {...seal("health_check.path")} error={errAt("health_check.path")?.message}
|
||||
hint="Use an address that answers without signing in, like /health." />
|
||||
</div>
|
||||
<div class="domi-field">
|
||||
<label class="domi-field-label" for={fieldId("health_check.interval_secs")}>Checks every</label>
|
||||
<div class="row"><input id={fieldId("health_check.interval_secs")} class="domi-input narrow" type="number" min="1" max="3600" bind:value={host.hcEvery} onblur={() => blur("health_check.interval_secs")} /> <span class="ia-text2">seconds</span></div>
|
||||
{#if errAt("health_check.interval_secs")}<p class="domi-error"><Icon name="ring" />{errAt("health_check.interval_secs").message}</p>{/if}
|
||||
<div class="ia-field">
|
||||
<label class="ia-field-label" for={fieldId("health_check.interval_secs")}>Checks every</label>
|
||||
<div class="row"><input id={fieldId("health_check.interval_secs")} class="ia-input narrow" type="number" min="1" max="3600" bind:value={host.hcEvery} onblur={() => blur("health_check.interval_secs")} /> <span class="ia-text2">seconds</span></div>
|
||||
{#if errAt("health_check.interval_secs")}<p class="ia-error"><Icon name="ring" />{errAt("health_check.interval_secs").message}</p>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="domi-field">
|
||||
<span class="domi-field-label">Websockets</span>
|
||||
<label class="ia-check"><input type="checkbox" bind:checked={host.websockets} /> Allow websockets</label>
|
||||
<div class="ia-field">
|
||||
<span class="ia-field-label">Websockets</span>
|
||||
<Checkbox bind:checked={host.websockets} label="Allow websockets" />
|
||||
<p class="ia-hint">Live updates for apps like Home Assistant. Leave on unless you know the app does not need them.</p>
|
||||
</div>
|
||||
<div class="domi-field">
|
||||
<span class="domi-field-label">Share links</span>
|
||||
<label class="ia-check"><input type="checkbox" bind:checked={host.share_links} /> Allow share links</label>
|
||||
<div class="ia-field">
|
||||
<span class="ia-field-label">Share links</span>
|
||||
<Checkbox bind:checked={host.share_links} label="Allow share links" />
|
||||
<p class="ia-hint">Lets you make links that open this host without signing in, until they expire.</p>
|
||||
{#if shareWarning}<p class="ia-hint">Anyone can already open {name}, so a share link changes nothing.</p>{/if}
|
||||
</div>
|
||||
<div class="domi-field">
|
||||
<span class="domi-field-label">Device certificates</span>
|
||||
<label class="ia-check"><input type="checkbox" bind:checked={host.device_certs} /> Only devices with a Domi device certificate</label>
|
||||
<div class="ia-field">
|
||||
<span class="ia-field-label">Device certificates</span>
|
||||
<Checkbox bind:checked={host.device_certs} label="Only devices with a Domi device certificate" />
|
||||
<p class="ia-hint">Phones, computers and apps need a certificate from Certificates before they can open it.</p>
|
||||
</div>
|
||||
<Segmented legend="Visit log" name="access_log" bind:value={host.access_log} options={[{ value: "off", label: "Off" }, { value: "truncated", label: "On" }]} />
|
||||
<p class="ia-hint">On keeps a log on this server, with visitor addresses shortened.</p>
|
||||
{#each [{ list: "request_headers", rules: host.req, title: "Header rules sent to your service", secrets: true }, { list: "response_headers", rules: host.resp, title: "Header rules sent back to visitors", secrets: false }] as group (group.list)}
|
||||
<div class="domi-field">
|
||||
<span class="domi-field-label">{group.title}</span>
|
||||
<div class="ia-field">
|
||||
<span class="ia-field-label">{group.title}</span>
|
||||
{#each group.rules as r, i (i)}
|
||||
{@const p = `${group.list}[${i}]`}
|
||||
<div class="rule ia-card">
|
||||
<Segmented legend="Rule {i + 1}" name="{p}-action" bind:value={r.action} options={[{ value: "set", label: "Set" }, { value: "remove", label: "Remove" }]} />
|
||||
<label class="domi-field-label" for={fieldId(p + ".name")}>Header name</label>
|
||||
<input id={fieldId(p + ".name")} class="domi-input" bind:value={r.name} onblur={() => blur(p + ".name")} />
|
||||
<div onfocusout={() => blur(p + ".name")}>
|
||||
<TextField id={fieldId(p + ".name")} label="Header name" bind:value={r.name} spellcheck={false} autocomplete="off" {...seal(p + ".name")} />
|
||||
</div>
|
||||
{#if r.action === "set"}
|
||||
{#if group.secrets}
|
||||
<Segmented legend="Value" name="{p}-kind" bind:value={r.kind} disabled={(site?.secrets.length ?? 0) === 0 ? ["secret"] : []} options={[{ value: "value", label: "Fixed value" }, { value: "secret", label: "Secret" }]} />
|
||||
{/if}
|
||||
{#if r.kind === "secret" && group.secrets}
|
||||
<select class="domi-input" bind:value={r.secret} aria-label="Secret">
|
||||
{#each site?.secrets ?? [] as s (s)}<option value={s}>{s}</option>{/each}
|
||||
</select>
|
||||
<Select label="Secret" bind:value={r.secret} options={(site?.secrets ?? []).map((s) => ({ value: s, label: s }))} />
|
||||
{:else}
|
||||
<input class="domi-input" bind:value={r.value} aria-label="Value" onblur={() => blur(p + ".value")} />
|
||||
<div onfocusout={() => blur(p + ".value")}>
|
||||
<TextField label="Value" hideLabel bind:value={r.value} spellcheck={false} autocomplete="off" {...seal(p + ".value")} />
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{#each Object.entries(errors).filter(([k]) => k.startsWith(p)) as [, e] (e.code + e.field)}<p class="domi-error"><Icon name="ring" />{e.message}</p>{/each}
|
||||
{#each Object.entries(errors).filter(([k]) => k.startsWith(p)) as [, e] (e.code + e.field)}<p class="ia-error"><Icon name="ring" />{e.message}</p>{/each}
|
||||
<button type="button" class="ia-icon-btn" aria-label="Remove this rule" onclick={() => group.rules.splice(i, 1)}><Icon name="trash" /></button>
|
||||
</div>
|
||||
{/each}
|
||||
<div><button type="button" class="domi-btn link" onclick={() => group.rules.push({ action: "set", name: "", kind: "value", value: "", secret: site?.secrets[0] ?? "" })}>Add a rule</button></div>
|
||||
<div><button type="button" class="ia-link" onclick={() => group.rules.push({ action: "set", name: "", kind: "value", value: "", secret: site?.secrets[0] ?? "" })}>Add a rule</button></div>
|
||||
{#if group.secrets && (site?.secrets.length ?? 0) === 0}<p class="ia-hint">No secrets are listed in ianitor.toml.</p>{/if}
|
||||
</div>
|
||||
{/each}
|
||||
@@ -531,6 +543,7 @@
|
||||
<style>
|
||||
form { display: flex; flex-direction: column; gap: 16px; }
|
||||
.row { display: flex; gap: 8px; align-items: center; }
|
||||
.grow { flex: 1 1 auto; min-width: 0; }
|
||||
.more { display: flex; flex-direction: column; gap: 16px; }
|
||||
.rule { display: flex; flex-direction: column; gap: 8px; }
|
||||
.narrow { max-width: 8rem; }
|
||||
|
||||
Reference in New Issue
Block a user