ux: avoid helperText if unnecessary

Massimo Melina committed Mar 16, 2022 at 16:31 UTC b1976e3789e413dddc8a9b27e86f02ec70173a3c
1 file changed +10 -10
admin/src/ConfigPage.ts
+10 -10
@@ -23,7 +23,7 @@ export default function ConfigPage() {
23 if (isValidElement(res))
24 return res
25 const { changes } = snap
26 - const config = (loaded !== res) ? (state.config = loaded = res) : snap.config
26 + const values = (loaded !== res) ? (state.config = loaded = res) : snap.config
27 const maxSpeedDefaults = {
28 comp: NumberField,
29 min: 1,
@@ -32,9 +32,9 @@ export default function ConfigPage() {
32 }
33 return h(Form, {
34 sx: { maxWidth: '60em' },
35 - values: config,
35 + values,
36 set(v, k) {
37 - if (v || config[k])
37 + if (v || values[k])
38 state.config[k] = v
39 },
40 stickyBar: true,
@@ -59,25 +59,25 @@ export default function ConfigPage() {
59 fields: [
60 { k: 'port', comp: ServerPort, label:"HTTP port", status: status?.http||true, suggestedPort: 80 },
61 { k: 'https_port', comp: ServerPort, label: "HTTPS port", status: status?.https||true, suggestedPort: 443 },
62 - config.https_port >= 0 && { k: 'cert', comp: StringField, label: "HTTPS certificate file" },
63 - config.https_port >= 0 && { k: 'private_key', comp: StringField, label: "HTTPS private key file" },
62 + values.https_port >= 0 && { k: 'cert', label: "HTTPS certificate file" },
63 + values.https_port >= 0 && { k: 'private_key', label: "HTTPS private key file" },
64 { k: 'max_kbps', ...maxSpeedDefaults, label: "Limit output KB/s" },
65 { k: 'max_kbps_per_ip', ...maxSpeedDefaults, label: "Limit output KB/s per-ip" },
66 - { k: 'log', comp: StringField, label: "Main log file" },
67 - { k: 'error_log', comp: StringField, label: "Error log file" },
66 + { k: 'log', label: "Main log file" },
67 + { k: 'error_log', label: "Error log file" },
68 { k: 'log_rotation', comp: SelectField, options: [{ value:'', label:"disabled" }, 'daily', 'weekly', 'monthly' ],
69 helperText: "To avoid an endlessly-growing single log file, you can opt for rotation"
70 },
71 - { k: 'accounts', comp: StringField, label: "Accounts file" },
71 + { k: 'accounts', label: "Accounts file" },
72 { k: 'open_browser_at_start', comp: BoolField },
73 - { k: 'allowed_referer', placeholder: "any", helperText: "Leave empty to allow any", },
73 + { k: 'allowed_referer', placeholder: "any", helperText: values.allowed_referer && "Leave empty to allow any", },
74 { k: 'zip_calculate_size_for_seconds', comp: NumberField, sm: 6, label: "Calculate ZIP size for seconds",
75 helperText: "If time is not enough, the browser will not show download percentage" },
76 { k: 'mime', comp: StringStringField,
77 keyLabel: "Files", keyWidth: 7,
78 valueLabel: "Mime type", valueWidth: 4
79 },
80 - { k: 'block', label: "Blocked IPs", comp: StringField, multiline: true, minRows:3, helperText: "Enter an IP for each line",
80 + { k: 'block', label: "Blocked IPs", multiline: true, minRows:3, helperText: "Enter an IP address for each line",
81 fromField: (all:string) => all.split('\n').map(s => s.trim()).filter(Boolean).map(ip => ({ ip })),
82 toField: (all: any) => !Array.isArray(all) ? '' : all.map(x => x?.ip).filter(Boolean).join('\n')
83 },