v0.1.10 Quick fixes for routes and validations
This commit is contained in:
parent
2eac6fbd3a
commit
77bfe683aa
|
@ -31,6 +31,14 @@ import RestartModal from './restart';
|
|||
import RouteManagement, {ValidateRoute} from './routeman';
|
||||
import { map } from 'lodash';
|
||||
|
||||
const stickyButton = {
|
||||
position: 'fixed',
|
||||
bottom: '20px',
|
||||
left: '20px',
|
||||
right: '20px',
|
||||
boxShadow: '0px 0px 10px 0px rgba(0,0,0,0.50)',
|
||||
}
|
||||
|
||||
|
||||
const ProxyManagement = () => {
|
||||
isLoggedIn();
|
||||
|
@ -38,7 +46,8 @@ const ProxyManagement = () => {
|
|||
const [openModal, setOpenModal] = React.useState(false);
|
||||
const [error, setError] = React.useState(null);
|
||||
const [submitErrors, setSubmitErrors] = React.useState([]);
|
||||
|
||||
const [needSave, setNeedSave] = React.useState(false);
|
||||
|
||||
function updateRoutes(routes) {
|
||||
let con = {
|
||||
...config,
|
||||
|
@ -51,6 +60,7 @@ const ProxyManagement = () => {
|
|||
},
|
||||
};
|
||||
setConfig(con);
|
||||
setNeedSave(true);
|
||||
return con;
|
||||
}
|
||||
|
||||
|
@ -134,6 +144,7 @@ const ProxyManagement = () => {
|
|||
<RouteManagement key={key} routeConfig={route}
|
||||
setRouteConfig={(newRoute) => {
|
||||
routes[key] = newRoute;
|
||||
setNeedSave(true);
|
||||
}}
|
||||
up={() => up(key)}
|
||||
down={() => down(key)}
|
||||
|
@ -142,20 +153,21 @@ const ProxyManagement = () => {
|
|||
<br /><br />
|
||||
</>))}
|
||||
|
||||
{routes &&
|
||||
{routes && needSave &&
|
||||
<div style={stickyButton}>
|
||||
<MainCard>
|
||||
{error && (
|
||||
<Grid item xs={12}>
|
||||
<FormHelperText error>{error}</FormHelperText>
|
||||
</Grid>
|
||||
)}
|
||||
<Grid item xs={12}>
|
||||
<Stack spacing={1}>
|
||||
{submitErrors.map((err) => {
|
||||
return <Alert severity="error">{err}</Alert>
|
||||
})}
|
||||
<AnimateButton>
|
||||
<Button
|
||||
className='shinyButton'
|
||||
disableElevation
|
||||
fullWidth
|
||||
onClick={() => {
|
||||
|
@ -174,6 +186,7 @@ const ProxyManagement = () => {
|
|||
setSubmitErrors([]);
|
||||
}
|
||||
API.config.set(cleanRoutes(updateRoutes(routes))).then(() => {
|
||||
setNeedSave(false);
|
||||
setOpenModal(true);
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
|
@ -189,8 +202,8 @@ const ProxyManagement = () => {
|
|||
</Button>
|
||||
</AnimateButton>
|
||||
</Stack>
|
||||
</Grid>
|
||||
</MainCard>
|
||||
</div>
|
||||
}
|
||||
{!routes && <>
|
||||
<Typography variant="h6" gutterBottom component="div">
|
||||
|
|
|
@ -86,7 +86,7 @@ const RouteManagement = ({ routeConfig, TargetContainer, noControls=false, lockT
|
|||
return false;
|
||||
}}
|
||||
validate={(values) => {
|
||||
//setRouteConfig(values);
|
||||
setRouteConfig(values);
|
||||
}}
|
||||
>
|
||||
{(formik) => (
|
||||
|
|
|
@ -10,7 +10,7 @@ import { styled } from '@mui/material/styles';
|
|||
import * as API from '../../api';
|
||||
import isLoggedIn from '../../isLoggedIn';
|
||||
import RestartModal from '../config/users/restart';
|
||||
import RouteManagement from '../config/users/routeman';
|
||||
import RouteManagement, { ValidateRoute } from '../config/users/routeman';
|
||||
|
||||
const Item = styled(Paper)(({ theme }) => ({
|
||||
backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
|
||||
|
@ -29,6 +29,7 @@ const ServeApps = () => {
|
|||
const [config, setConfig] = useState(null);
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
const [newRoute, setNewRoute] = useState(null);
|
||||
const [submitErrors, setSubmitErrors] = useState([]);
|
||||
const [openRestartModal, setOpenRestartModal] = useState(false);
|
||||
|
||||
const hasCosmosNetwork = (containerName) => {
|
||||
|
@ -41,6 +42,15 @@ const ServeApps = () => {
|
|||
})
|
||||
}
|
||||
|
||||
const testRoute = (route) => {
|
||||
console.log(newRoute)
|
||||
try {
|
||||
ValidateRoute.validateSync(route);
|
||||
} catch (e) {
|
||||
return e.errors;
|
||||
}
|
||||
}
|
||||
|
||||
const refreshServeApps = () => {
|
||||
API.docker.list().then((res) => {
|
||||
setServeApps(res.data);
|
||||
|
@ -146,9 +156,25 @@ const ServeApps = () => {
|
|||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
{submitErrors && submitErrors.length > 0 && <Stack spacing={2} direction={"column"}>
|
||||
<Alert severity="error">{submitErrors.map((err) => {
|
||||
return <div>{err}</div>
|
||||
})}</Alert>
|
||||
</Stack>}
|
||||
<Button onClick={() => setOpenModal(false)}>Cancel</Button>
|
||||
<Button onClick={() => {
|
||||
updateRoutes()
|
||||
let errors = testRoute(newRoute);
|
||||
if (errors && errors.length > 0) {
|
||||
errors = errors.map((err) => {
|
||||
return `${err}`;
|
||||
});
|
||||
setSubmitErrors(errors);
|
||||
return true;
|
||||
} else {
|
||||
setSubmitErrors([]);
|
||||
updateRoutes();
|
||||
}
|
||||
|
||||
}}>Connect</Button>
|
||||
</DialogActions>
|
||||
</>}
|
||||
|
|
|
@ -40,6 +40,13 @@ func LoadConfig() utils.Config {
|
|||
utils.Fatal("Reading Config File: " + errString, err)
|
||||
}
|
||||
|
||||
// check if config is valid
|
||||
utils.Log("Validating config file...")
|
||||
err = utils.Validate.Struct(config)
|
||||
if err != nil {
|
||||
utils.Fatal("Reading Config File: " + err.Error(), err)
|
||||
}
|
||||
|
||||
utils.LoadBaseMainConfig(config)
|
||||
|
||||
return config
|
||||
|
|
|
@ -71,25 +71,25 @@ type User struct {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
LoggingLevel LoggingLevel `validate:"oneof=DEBUG INFO WARNING ERROR"`
|
||||
LoggingLevel LoggingLevel `required,validate:"oneof=DEBUG INFO WARNING ERROR"`
|
||||
MongoDB string
|
||||
HTTPConfig HTTPConfig
|
||||
DisableUserManagement bool
|
||||
NewInstall bool
|
||||
NewInstall bool `validate:"boolean"`
|
||||
HTTPConfig HTTPConfig `validate:"required,dive,required"`
|
||||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
TLSCert string
|
||||
TLSCert string `validate:"omitempty,contains=\n`
|
||||
TLSKey string
|
||||
AuthPrivateKey string
|
||||
AuthPublicKey string
|
||||
GenerateMissingAuthCert bool
|
||||
HTTPSCertificateMode string
|
||||
HTTPPort string
|
||||
HTTPSPort string
|
||||
HTTPPort string `validate:"required,containsany=0123456789,min=1,max=6"`
|
||||
HTTPSPort string `validate:"required,containsany=0123456789,min=1,max=6"`
|
||||
ProxyConfig ProxyConfig
|
||||
Hostname string
|
||||
SSLEmail string
|
||||
Hostname string `validate:"required,excludesall=0x2C/ "`
|
||||
SSLEmail string `validate:"omitempty,email"`
|
||||
}
|
||||
|
||||
type ProxyConfig struct {
|
||||
|
|
|
@ -2,4 +2,4 @@ package utils
|
|||
|
||||
import "github.com/go-playground/validator/v10"
|
||||
|
||||
var Validate = validator.New()
|
||||
var Validate = validator.New()
|
||||
|
|
Loading…
Reference in a new issue