-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP [DUOS-1958][risk=no] "NIH and AnVIL use" sub-component for data submission form #1771
Conversation
…to DUOS-1958 � Conflicts: � src/pages/DataSubmissionForm.js
@@ -232,6 +255,35 @@ const formInputSelect = (config) => { | |||
]); | |||
}; | |||
|
|||
const formInputRadioButtons = (config) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added this in mine! I haven't added tests yet but mine also has the ability to have 'Other' with text fields and such. Not sure how exactly we should merge them. My code is here #1747 if you want to check it out. It's a bit more complicated but it would work here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these merges are going to be rough! I added some radio buttons too, but yall wrote way better code XD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think I'll copy over the radio buttons from #1747 to my branch to make merging easier since Connor's version can work for both of us
src/components/forms/forms.js
Outdated
} | ||
}) | ||
), | ||
error && div({ className: `error-message fadein`}, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this repeats multiple times through the code, can we pull this out into a separate function? Sorry, that was my bad!
@@ -30,6 +33,10 @@ export const FormValidators = { | |||
REQUIRED: { | |||
isValid: (value) => value !== undefined && value !== null && value !== '', | |||
msg: 'Please enter a value' | |||
}, | |||
EMAIL: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great addition!
src/components/forms/forms.js
Outdated
const clearDependentFormFields = (config) => { | ||
const {onChange, dependentFormFields = []} = config; | ||
/* | ||
* Clears fields for questions that are rendered conditionally, setting them to their default value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think of "clear" as to set it to blank, like ''
, while "reset" would return to the default value - There's a real value to having both of these functions! What would you think of adding a param to allow you to completely clear to type.defaultValue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... I don't know, the more I'm thinking about it, the more I'm wondering if this is necessary! Should handling behavior of dependent form components be a job of the global forms functions? The parent formField could handle clearing child form values through the onChange
option that's already available.
src/pages/DataSubmissionForm.js
Outdated
@@ -41,7 +42,8 @@ export const DataSubmissionForm = () => { | |||
]), | |||
|
|||
form({}, [ | |||
h(DataSubmissionStudyInformation, { onChange }) | |||
h(DataSubmissionStudyInformation, { onChange }), | |||
h(DataSubmissionNihAnvilUse, { onChange, formData }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The study information component doesn't take in any existing formData - should it? (is the purpose to set values for a saved submission form?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback!
You can ignore the formData prop for now!
I was trying to work out some bugs with my ticket and that was left over from my experimentation. I think I found a workaround, but let me know if you have ideas on a better approach (I'll comment closer to the actual code to provide context)
@@ -14,7 +15,7 @@ export const DataSubmissionForm = () => { | |||
const onChange = ({ key, value, isValid }) => { | |||
/* eslint-disable no-console */ | |||
console.log('StudyInfo OnChange:', key, value, isValid); | |||
set(key, value, formData); | |||
set(formData, key, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why, but I couldn't get the lodash/fp version of set to actually update formData (but the regular lodash function seems to be working fine). I tested by adding console.log(formData)
after the call to set, and with the lodash/fp version it always printed {}
], | ||
validators: [FormValidators.REQUIRED], | ||
onChange, | ||
setFormValueParent: setNihAnvilUse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My ticket requires different questions to be rendered based on the option selected for the nihAnvilUse
, but the formValue
state variable is contained within the FormField
itself. To address this, I'm also tracking the value of nihAnvilUse
in the DataSubmissionNihAnvilUse
component.
Past Attempts:
I tried experimenting getting the value from formData.nihAnvilUse
, but the changes didn't register in my component since the same formData object is being used. I also tried having formData be a state variable, and in onChange, I would deepClone the current contents of formData, set the given key value pair, and call setFormData with the new object. However, this caused the hook in DataSubmissionStudyInformation
to be called way too often.
Current Approach:
Currently, I am passing setNihAnvilUse
as an optional setFormValueParent
prop to FormField, which is called with the new form field value in onFormInputChange
. This ensures that when the formValue
is changed in the FormField, it is also changed in this component
{label: NO, value: NO}, | ||
], | ||
dependentFormFields: [ | ||
{id: 'submittingToAnvil', type: FormFieldTypes.RADIO, shouldClear: ({value}) => value === I_DID}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had all of the dependent form fields be cleared when nihAnvilUse
is changed, but there are two values of nihAnvilUse
where the submittingToAnvil
question appears. So, if I switched between nihAnvilUse === 'I will'
and 'nihAnvilUse' === 'No'
, submittingToAnvil
in formData is cleared but the selected radio buttons weren't. One possible solution is allowing the dependentFormFields
to have a shouldClear
condition (if not provided, assume clear on any change). Here, submittingToAnvil
is only cleared in the formData when the question is no longer rendered, so that the value in formData and the selected radio button are consistent with each other
closing this - redone in #1800 |
Addresses DUOS-1958
Have you read Terra's Contributing Guide lately? If not, do that first.