admin/options: better error message on proxy field
Massimo Melina committed
May 6, 2023 at 12:32 UTC
72918e032b2532e6d6d748db546889e266bea099
2 files changed
+9
-6
admin/src/HomePage.ts
+4
-3
@@ -1,6 +1,6 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
-import { createElement as h, useState } from 'react'
3
+import { createElement as h, ReactNode, useState } from 'react'
4
import { Box, Button, LinearProgress, Link } from '@mui/material'
5
import { apiCall, useApi, useApiEx, useApiList } from './api'
6
import { Btn, dontBotherWithKeys, InLink, objSameKeys, onlyTruthy, prefix, REPO_URL, wait, wikiLink } from './misc'
@@ -64,7 +64,7 @@ export default function HomePage() {
64
plugins.find(x => x.badApi) && entry('warning', "Some plugins may be incompatible"),
65
!account?.adminActualAccess && entry('', md("On _localhost_ you don't need to login"),
66
SOLUTION_SEP, h(InLink, { to:'accounts' }, md("to access from another computer create an account with /admin/ permission")) ),
67
- proxyWarning(cfg, status) && entry('warning', "A proxy was detected but none is configured",
67
+ proxyWarning(cfg, status) && entry('warning', proxyWarning(cfg, status),
68
SOLUTION_SEP, cfgLink("set the number of proxies"),
69
SOLUTION_SEP, "unless you are sure and you can ", h(Button, {
70
size: 'small',
@@ -119,7 +119,7 @@ async function update() {
119
120
type Color = '' | 'success' | 'warning' | 'error'
121
122
-function entry(color: Color, ...content: any[]) {
122
+function entry(color: Color, ...content: ReactNode[]) {
123
return h(Box, {
124
fontSize: 'x-large',
125
color: th => color && th.palette[color]?.main,
@@ -140,4 +140,5 @@ function cfgLink(text=`Options page`) {
140
141
export function proxyWarning(cfg: any, status: any) {
142
return cfg && !cfg.proxies && status?.proxyDetected
143
+ && "A proxy was detected but none is configured"
144
}
mui-grid-form/index.ts
+5
-3
@@ -24,11 +24,12 @@ export * from './misc-fields'
24
export * from './StringStringField'
25
export { StringField }
26
27
-type ValidationError = string | boolean // false = no error
27
+type ValidationError = ReactNode // false = no error
28
export interface FieldDescriptor<T=any> {
29
k: string
30
comp?: any
31
label?: ReactNode
32
+ error?: ReactNode
33
getError?: (v: any, extra?: any) => Promisable<ValidationError>
34
toField?: (v: T) => any
35
fromField?: (v: any) => T
@@ -131,7 +132,7 @@ export function Form<Values extends Dict>({
132
if (isValidElement(row))
133
return h(Grid, { key: idx, item: true, xs: 12 }, row)
134
const { k, fromField=_.identity, toField=_.identity, getError, error, ...field } = row
134
- let errMsg = errors[k] || fieldExceptions[k]
135
+ let errMsg = errors[k] || error || fieldExceptions[k]
136
if (errMsg === true)
137
errMsg = "Not valid"
138
if (k) {
@@ -165,7 +166,8 @@ export function Form<Values extends Dict>({
166
field.helperText = !field.helperText ? errMsg
167
: h(Fragment, {},
168
h('span', { style: { borderBottom: '1px solid' } }, errMsg),
168
- h(Box, { color: 'text.primary' }, field.helperText),
169
+ h(Box, { color: 'text.primary', component: 'span', /*avoid console warning*/ display: 'block' },
170
+ field.helperText),
171
)
172
if (field.label === undefined)
173
field.label = labelFromKey(k)