refactor: extract building of initial values
This commit is contained in:
parent
08c87f4f18
commit
9e5f027379
1 changed files with 10 additions and 11 deletions
|
|
@ -173,6 +173,14 @@ const Wizard = ({
|
||||||
const isEditing = !R.isNil(toBeEdited)
|
const isEditing = !R.isNil(toBeEdited)
|
||||||
const [step, setStep] = useState(isEditing ? 1 : 0)
|
const [step, setStep] = useState(isEditing ? 1 : 0)
|
||||||
|
|
||||||
|
const defaultValues = {
|
||||||
|
...nameOfReqDefaults,
|
||||||
|
...screen1InfoDefaults,
|
||||||
|
...screen2InfoDefaults,
|
||||||
|
...chooseTypeDefaults,
|
||||||
|
...typeFieldsDefaults
|
||||||
|
}
|
||||||
|
|
||||||
// If we're editing, filter out the requirement being edited so that validation schemas don't enter in circular conflicts
|
// If we're editing, filter out the requirement being edited so that validation schemas don't enter in circular conflicts
|
||||||
const _existingRequirements = isEditing
|
const _existingRequirements = isEditing
|
||||||
? R.filter(it => it.id !== toBeEdited.id, existingRequirements)
|
? R.filter(it => it.id !== toBeEdited.id, existingRequirements)
|
||||||
|
|
@ -201,6 +209,7 @@ const Wizard = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
const editingValues = isEditing ? makeEditingValues(toBeEdited) : {}
|
const editingValues = isEditing ? makeEditingValues(toBeEdited) : {}
|
||||||
|
const initialValues = R.mergeWith(chooseNotNull, defaultValues, editingValues)
|
||||||
const wizardTitle = isEditing
|
const wizardTitle = isEditing
|
||||||
? 'Editing custom requirement'
|
? 'Editing custom requirement'
|
||||||
: 'New custom requirement'
|
: 'New custom requirement'
|
||||||
|
|
@ -225,17 +234,7 @@ const Wizard = ({
|
||||||
validateOnChange={false}
|
validateOnChange={false}
|
||||||
enableReinitialize={true}
|
enableReinitialize={true}
|
||||||
onSubmit={onContinue}
|
onSubmit={onContinue}
|
||||||
initialValues={R.mergeWith(
|
initialValues={initialValues}
|
||||||
chooseNotNull,
|
|
||||||
{
|
|
||||||
...nameOfReqDefaults,
|
|
||||||
...screen1InfoDefaults,
|
|
||||||
...screen2InfoDefaults,
|
|
||||||
...chooseTypeDefaults,
|
|
||||||
...typeFieldsDefaults
|
|
||||||
},
|
|
||||||
editingValues
|
|
||||||
)}
|
|
||||||
validationSchema={stepOptions.schema}>
|
validationSchema={stepOptions.schema}>
|
||||||
{({ errors }) => (
|
{({ errors }) => (
|
||||||
<Form className={classes.form} id={'custom-requirement-form'}>
|
<Form className={classes.form} id={'custom-requirement-form'}>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue