ux: easier field for allowed_referer

Massimo Melina committed Jan 25, 2023 at 22:53 UTC 1f4562ae0d368a2ef5103a5e550953f3bc022a91
1 file changed +34 -3
admin/src/ConfigPage.ts
+34 -3
@@ -7,7 +7,16 @@ import { state, useSnapState } from './state'
7 import { Info, Refresh } from '@mui/icons-material'
8 import { Dict, modifiedSx } from './misc'
9 import { subscribeKey } from 'valtio/utils'
10 -import { Form, BoolField, NumberField, SelectField, StringStringField, FieldProps, Field } from '@hfs/mui-grid-form';
10 +import {
11 + Form,
12 + BoolField,
13 + NumberField,
14 + SelectField,
15 + StringStringField,
16 + FieldProps,
17 + Field,
18 + StringField
19 +} from '@hfs/mui-grid-form';
20 import FileField from './FileField'
21 import { alertDialog, closeDialog, confirmDialog, formDialog, newDialog, toast, waitDialog } from './dialog'
22 import { proxyWarning } from './HomePage'
@@ -108,8 +117,7 @@ export default function ConfigPage() {
117 error: proxyWarning(values, status),
118 helperText: "Wrong number will prevent detection of users' IP address"
119 },
111 - { k: 'allowed_referer', placeholder: "any",
112 - helperText: values.allowed_referer ? "Leave empty to allow any" : "Use this to avoid direct links from other websites", },
120 + { k: 'allowed_referer', placeholder: "any", label: "Links from other websites", comp: AllowedReferer },
121 { k: 'delete_unfinished_uploads_after', comp: NumberField, sm: 6, md: 3, min : 0, unit: "seconds", placeholder: "Never",
122 helperText: "Leave empty to never delete" },
123 { k: 'min_available_mb', comp: NumberField, sm: 6, md: 3, min : 0, unit: "MBytes", placeholder: "None",
@@ -214,6 +222,29 @@ function ServerPort({ label, value, onChange, getApi, status, suggestedPort=1, e
222 )
223 }
224
225 +function AllowedReferer({ label, value, onChange, error }: FieldProps<string>) {
226 + const yesno = !value || value==='-'
227 + const example = 'example.com'
228 + return h(Box, { display: 'flex' },
229 + h(SelectField as Field<string>, {
230 + label,
231 + value: yesno ? value : example,
232 + options: { "allow all": '', "forbid all": '-', "allow some": example, },
233 + onChange,
234 + error,
235 + sx: yesno ? undefined : { maxWidth: '11em' },
236 + }),
237 + !yesno && h(StringField, {
238 + label: "Domain to allow",
239 + value,
240 + placeholder: 'example.com',
241 + onChange,
242 + error,
243 + helperText: "Masks supported"
244 + })
245 + )
246 +}
247 +
248 function suggestMakingCert() {
249 newDialog({
250 Content: () => h(Box, {},