diff --git a/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js b/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js index 346c88ab..3bd6b6b7 100644 --- a/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js +++ b/new-lamassu-admin/src/components/booleanPropertiesTable/BooleanPropertiesTable.js @@ -1,7 +1,7 @@ import { makeStyles } from '@material-ui/core/styles' import classnames from 'classnames' import { useFormikContext, Form, Formik, Field as FormikField } from 'formik' -import _ from 'lodash' +import _ from 'lodash/fp' import React, { useState, memo } from 'react' import * as Yup from 'yup' @@ -26,7 +26,9 @@ const BooleanCell = ({ name }) => { const BooleanPropertiesTable = memo( ({ title, disabled, data, elements, save, forcedEditing = false }) => { - const initialValues = _.fromPairs(elements.map(it => [it.name, ''])) + const initialValues = _.fromPairs( + elements.map(it => [it.name, data[it.name] || null]) + ) const schemaValidation = _.fromPairs( elements.map(it => [it.name, Yup.boolean().required()]) ) @@ -36,74 +38,83 @@ const BooleanPropertiesTable = memo( const classes = useStyles() const innerSave = async value => { - save(value) + const filteredValues = _.omitBy(_.isNil, value) + save(filteredValues) setEditing(false) } - const innerCancel = () => setEditing(false) - const radioButtonOptions = [ { display: 'Yes', code: 'true' }, { display: 'No', code: 'false' } ] - return (
-
-
-

{title}

- {editing ? ( -
- - Save - - - Cancel - + {({ resetForm }) => { + return ( + +
+

{title}

+ {editing ? ( +
+ + Save + + { + resetForm() + setEditing(false) + }} + color="secondary"> + Cancel + +
+ ) : ( + setEditing(true)}> + {disabled ? : } + + )}
- ) : ( - setEditing(true)}> - {disabled ? : } - - )} -
- - - - {elements.map((it, idx) => ( - - - {it.display} - - - {editing && ( - +
+ + {elements.map((it, idx) => ( + + + {it.display} + + + {editing && ( + )} - /> - )} - {!editing && } - - - ))} - -
- + {!editing && } + + + ))} + + + + ) + }}
)