-
Notifications
You must be signed in to change notification settings - Fork 174
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
[candidate_parameters] Making the Proband Info Tab extensible #2787
Conversation
@jacobpenny Can you review the javascript in this? |
I'm getting some errors: This is because these components are no longer in the global scope. This change was made in this PR. This module should have been updated at that time but wasn't. So, you'll need to import these components where they are needed, i.e. add the following line to the rest of the import statements in Because we are now bundling the Tab components we shouldn't try to fetch it, and if we do try we just get an error. The file doesn't exist anymore: So you need to remove this line |
types = types.slice(0, -1); | ||
types = types.replace(/'/g, ''); | ||
types = types.split(','); | ||
var selectOptions = []; |
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.
SelectElement
expects an object for options, not an array:
Warning: Failed prop type: Invalid prop `options` of type `array` supplied to `SelectElement`, expected `object`.
Should be:
var selectOptions = {};
var extraParameterFields = []; | ||
var extraParameters = this.state.Data.extra_parameters; | ||
for (var key2 in extraParameters) { | ||
if (extraParameters.hasOwnProperty(key2)) { |
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.
Rather than use for ... in
and doing this hasOwnProperty
check you could use forEach
, which won't iterate inherited properties.
extraParameters.forEach(function(extraParam) { ... })
Better yet would be to use map
. It looks like you are creating a component for each extraParameter
, i.e. a 1-to-1 mapping.
I'd write it like:
var extraParameters = this.state.Data.extra_parameters;
var extraParametersFields = extraParameters.map(function(extraParam) { ... });
If you decide to use forEach
or map
, you'll need to change extraParameters[key2]
to extraParam
in the body of the function. If you use map
, instead of push
ing, just return the component.
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.
Side note: this render function is getting pretty long. I'd break this logic out into another function:
var extraParametersFields = extraParameters.map(this._convertExtraParamToInputComponent);
types = types.split(','); | ||
var selectOptions = []; | ||
for (var key3 in types) { | ||
if (types.hasOwnProperty(key3)) { |
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.
Same as above: using forEach
would be cleaner IMO.
types.forEach(function(type) {
selectOptions[type] = type;
});
value={value} | ||
onUserInput={this.setFormData} | ||
ref={name} | ||
disabled={disabled} |
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.
Alignment issue here. I'm wondering why eslint didn't catch this.
var name = 'PTID' + paramTypeID; | ||
var value = this.state.Data.parameter_values[paramTypeID]; | ||
|
||
switch (extraParameters[key2].Type.substring(0, 3)) { |
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'm not really sure what extraParameters[key2].Type.substring(0, 3)
is.
I can infer it from the case
statements but IMO it would be easier to read/understand if this were a named variable:
var extraParamType = extraParameters[key2].Type.substring(0, 3)
switch (extraParamType) { ... }
(I'm just guessing that it is the extra parameter type)
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.
Looks good!
@jacobpenny did you test it or just review it? |
@driusan Did basic testing but lack the data to fully test. |
This pull request allows the Proband tab to be extensible just like the Candidate Info tab.
The magic happens because of parameter_type_category.Name='Candidate Parameters Proband'