Skip to content

Commit

Permalink
don't mutate store data when creating form intialValues
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Davenport <kaiyadavenport@gmail.com>
  • Loading branch information
binocarlos committed May 30, 2019
1 parent 7486071 commit 2f4b716
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/components/form/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,16 @@ class FormWrapperInner extends React.Component {
let isInitialValid = false

const validationSchema = Validate(schema)
const useInitialValues = utils.getInitialValues(schema, initialValues)

try {
isInitialValid = validationSchema.validateSync(useInitialValues)
isInitialValid = validationSchema.validateSync(initialValues)
} catch(e) {

}

return (
<Formik
initialValues={ useInitialValues }
initialValues={ initialValues }
validationSchema={ validationSchema }
isInitialValid={ isInitialValid }
onSubmit={ (values) => {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/cluster/ClusterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const clearAccessControlResults = () => userActions.setAccessControlResults([])

const initialValues = id == 'new' ?
clusterInitialValues[provision_type] :
selectors.cluster.collection.item(state) || {}
JSON.parse(JSON.stringify(selectors.cluster.collection.item(state) || {}))

const schema = id == 'new' ?
clusterForms[provision_type].add :
Expand Down
5 changes: 4 additions & 1 deletion src/containers/deployment/DeploymentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import selectors from 'store/selectors'
import DeploymentForm from 'pages/deployment/DeploymentForm'
import Loading from 'components/system/Loading'

import formUtils from 'components/form/utils'

const onCancel = (cluster) => routerActions.navigateTo('deployments', {cluster})
const clearAccessControlResults = () => userActions.setAccessControlResults([])

Expand All @@ -30,13 +32,14 @@ const clearAccessControlResults = () => userActions.setAccessControlResults([])
// we are creating a new deployment
if(id == 'new') {
schema = deploymentForms[deployment_type].forms[deployment_version]
initialValues = formUtils.getInitialValues(schema, {})
}
// it's an existing deployment
else {
const existingValues = selectors.deployment.collection.item(state)

if(existingValues) {
initialValues = existingValues.desired_state
initialValues = JSON.parse(JSON.stringify(existingValues.desired_state))
schema = deploymentForms[existingValues.deployment_type].forms[existingValues.deployment_version]
}
}
Expand Down

0 comments on commit 2f4b716

Please sign in to comment.