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)
|
insert into user_config (type, data, valid, schema_version)
|
||||||
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
||||||
function saveAccounts (accounts) {
|
function saveAccounts (accounts) {
|
||||||
|
console.log('accounts to save ' + JSON.stringify(accounts))
|
||||||
return loadAccounts()
|
return loadAccounts()
|
||||||
.then(currentAccounts => {
|
.then(currentAccounts => {
|
||||||
const emptySecretFields = _.compose(
|
const newAccounts = _.merge(currentAccounts, accounts)
|
||||||
_.map(_.last),
|
|
||||||
_.map(_.split('.')),
|
|
||||||
_.filter(e => _.get(e, accounts) === '')
|
|
||||||
)(SECRET_FIELDS)
|
|
||||||
const filledAccountInfo = _.mapValues(_.omit(emptySecretFields), accounts)
|
|
||||||
|
|
||||||
const newAccounts = _.merge(currentAccounts, filledAccountInfo)
|
|
||||||
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
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 React from 'react'
|
||||||
|
|
||||||
import { Button } from 'src/components/buttons'
|
import { Button } from 'src/components/buttons'
|
||||||
|
import { SecretInput } from 'src/components/inputs/formik'
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
button: {
|
button: {
|
||||||
|
|
@ -40,6 +41,18 @@ const FormRenderer = ({
|
||||||
|
|
||||||
const values = R.merge(initialValues, value)
|
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 (
|
return (
|
||||||
<Formik
|
<Formik
|
||||||
validateOnBlur={false}
|
validateOnBlur={false}
|
||||||
|
|
@ -47,7 +60,7 @@ const FormRenderer = ({
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
initialValues={values}
|
initialValues={values}
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
onSubmit={save}>
|
onSubmit={saveNonEmptySecret}>
|
||||||
<Form className={classes.form}>
|
<Form className={classes.form}>
|
||||||
<Grid container spacing={3} className={classes.grid}>
|
<Grid container spacing={3} className={classes.grid}>
|
||||||
{elements.map(({ component, code, display, inputProps }) => (
|
{elements.map(({ component, code, display, inputProps }) => (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue