refactor: filter secret empty fields on the front-end
This commit is contained in:
parent
78db9c8765
commit
75629746e7
2 changed files with 16 additions and 9 deletions
|
|
@ -22,16 +22,10 @@ const accountsSql = `update user_config set data = $2, valid = $3, schema_versio
|
|||
insert into user_config (type, data, valid, schema_version)
|
||||
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
||||
function saveAccounts (accounts) {
|
||||
console.log('accounts to save ' + JSON.stringify(accounts))
|
||||
return loadAccounts()
|
||||
.then(currentAccounts => {
|
||||
const emptySecretFields = _.compose(
|
||||
_.map(_.last),
|
||||
_.map(_.split('.')),
|
||||
_.filter(e => _.get(e, accounts) === '')
|
||||
)(SECRET_FIELDS)
|
||||
const filledAccountInfo = _.mapValues(_.omit(emptySecretFields), accounts)
|
||||
|
||||
const newAccounts = _.merge(currentAccounts, filledAccountInfo)
|
||||
const newAccounts = _.merge(currentAccounts, accounts)
|
||||
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import * as R from 'ramda'
|
|||
import React from 'react'
|
||||
|
||||
import { Button } from 'src/components/buttons'
|
||||
import { SecretInput } from 'src/components/inputs/formik'
|
||||
|
||||
const styles = {
|
||||
button: {
|
||||
|
|
@ -40,6 +41,18 @@ const FormRenderer = ({
|
|||
|
||||
const values = R.merge(initialValues, value)
|
||||
|
||||
const saveNonEmptySecret = it => {
|
||||
const emptySecretFields = R.compose(
|
||||
R.map(R.prop('code')),
|
||||
R.filter(
|
||||
elem =>
|
||||
R.prop('component', elem) === SecretInput &&
|
||||
R.isEmpty(it[R.prop('code', elem)])
|
||||
)
|
||||
)(elements)
|
||||
return save(R.omit(emptySecretFields, it))
|
||||
}
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validateOnBlur={false}
|
||||
|
|
@ -47,7 +60,7 @@ const FormRenderer = ({
|
|||
enableReinitialize
|
||||
initialValues={values}
|
||||
validationSchema={validationSchema}
|
||||
onSubmit={save}>
|
||||
onSubmit={saveNonEmptySecret}>
|
||||
<Form className={classes.form}>
|
||||
<Grid container spacing={3} className={classes.grid}>
|
||||
{elements.map(({ component, code, display, inputProps }) => (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue