Skip to content
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

Merged
merged 11 commits into from
Jun 27, 2017

Conversation

gluneau
Copy link
Contributor

@gluneau gluneau commented May 8, 2017

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'

@gluneau gluneau added the Feature PR or issue introducing/requiring at least one new feature label May 8, 2017
@gluneau gluneau added this to the 17.1 milestone May 8, 2017
@driusan driusan requested a review from jacobpenny May 16, 2017 18:13
@driusan
Copy link
Collaborator

driusan commented May 16, 2017

@jacobpenny Can you review the javascript in this?

@jacobpenny
Copy link
Contributor

jacobpenny commented May 17, 2017

I'm getting some errors:
Uncaught ReferenceError: Tabs is not defined
Uncaught ReferenceError: TabPane is not defined

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 CandidateParameters.js and recompile:
import {Tabs, TabPane} from 'Tabs';

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:
GET http://localhost/js/components/Tabs.js 404 (Not Found)

So you need to remove this line

types = types.slice(0, -1);
types = types.replace(/'/g, '');
types = types.split(',');
var selectOptions = [];
Copy link
Contributor

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)) {
Copy link
Contributor

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 pushing, just return the component.

Copy link
Contributor

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)) {
Copy link
Contributor

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}
Copy link
Contributor

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)) {
Copy link
Contributor

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)

@jstirling91 jstirling91 added the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label May 24, 2017
@gluneau gluneau removed the Needs Work PR awaiting additional changes by the author or contains issues that the author needs to fix label Jun 16, 2017
Copy link
Contributor

@jacobpenny jacobpenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@driusan
Copy link
Collaborator

driusan commented Jun 21, 2017

@jacobpenny did you test it or just review it?

@jacobpenny
Copy link
Contributor

@driusan Did basic testing but lack the data to fully test.

@driusan driusan merged commit b0018df into aces:17.1-dev Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature PR or issue introducing/requiring at least one new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants