All files / javascripts/explorev2/components FieldSetRow.jsx

90% Statements 18/20
50% Branches 1/2
66.67% Functions 2/3
90% Lines 18/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 531x 1x   1x   1x               1x   1x       8x 4x 4x 4x       4x   2x 2x 2x     4x 4x                               1x 1x  
import React, { PropTypes } from 'react';
import FieldSet from './FieldSet';
 
const NUM_COLUMNS = 12;
 
const propTypes = {
  fields: PropTypes.object.isRequired,
  fieldSets: PropTypes.array.isRequired,
  fieldOverrides: PropTypes.object,
  onChange: PropTypes.func,
  form_data: PropTypes.object.isRequired,
};
 
const defaultProps = {
  fieldOverrides: {},
  onChange: () => {},
};
 
export default class FieldSetRow extends React.Component {
  getFieldData(fs) {
    const { fields, fieldOverrides } = this.props;
    let fieldData = fields[fs];
    Iif (fieldOverrides.hasOwnProperty(fs)) {
      const overrideData = fieldOverrides[fs];
      fieldData = Object.assign({}, fieldData, overrideData);
    }
    return fieldData;
  }
  render() {
    const colSize = NUM_COLUMNS / this.props.fieldSets.length;
    return (
      <div className="row space-2">
        {this.props.fieldSets.map((fs) => {
          const fieldData = this.getFieldData(fs);
          return (
            <div className={`col-lg-${colSize} col-xs-12`} key={fs}>
              <FieldSet
                name={fs}
                onChange={this.props.onChange}
                value={this.props.form_data[fs]}
                {...fieldData}
              />
            </div>
          );
        })}
      </div>
    );
  }
}
 
FieldSetRow.propTypes = propTypes;
FieldSetRow.defaultProps = defaultProps;