Skip to content

Commit

Permalink
[explore-v2] render columns based on length of fieldSets array (#1559)
Browse files Browse the repository at this point in the history
* render columns based on length of fieldSets array

* fix tests
  • Loading branch information
Alanna Scott authored Nov 8, 2016
1 parent bb6ab11 commit 1bf83c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class CheckboxField extends React.Component {
}
render() {
return (
<Checkbox onChange={this.onToggle.bind(this)}>
<Checkbox onChange={this.onToggle.bind(this)} inline>
<ControlLabelWithTooltip label={this.props.label} description={this.props.description} />
</Checkbox>
);
Expand Down
12 changes: 8 additions & 4 deletions caravel/assets/javascripts/explorev2/components/FieldSetRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { PropTypes } from 'react';
import FieldSet from './FieldSet';
import { fields } from '../stores/store';

const NUM_COLUMNS = 12;

const propTypes = {
fieldSets: PropTypes.array.isRequired,
fieldOverrides: PropTypes.object,
Expand All @@ -23,16 +25,18 @@ function getFieldData(fs, fieldOverrides) {
}

export default function FieldSetRow({ fieldSets, fieldOverrides, onChange }) {
const colSize = NUM_COLUMNS / fieldSets.length;
return (
<ul className="list-unstyled">
<div className="row">
{fieldSets.map((fs) => {
const fieldData = getFieldData(fs, fieldOverrides);
return (
<li key={fs}>
<div className={`col-lg-${colSize} col-xs-12`} key={fs}>
<FieldSet name={fs} onChange={onChange} {...fieldData} />
</li>);
</div>
);
})}
</ul>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import React from 'react';
import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { shallow } from 'enzyme';
import { fields } from '../../../../javascripts/explorev2/stores/store';

import FieldSetRow from '../../../../javascripts/explorev2/components/FieldSetRow';
import FieldSet from '../../../../javascripts/explorev2/components/FieldSet';

const defaultProps = {
fields,
fieldSets: ['columns', 'metrics'],
};

Expand All @@ -16,12 +19,12 @@ describe('FieldSetRow', () => {
wrapper = shallow(<FieldSetRow {...defaultProps} />);
});

it('renders a single <ul>', () => {
expect(wrapper.find('ul')).to.have.lengthOf(1);
it('renders a single row element', () => {
expect(wrapper.find('.row')).to.have.lengthOf(1);
});

it('renders a <li> for each item in fieldSets array', () => {
it('renders a FieldSet for each item in fieldSets array', () => {
const length = defaultProps.fieldSets.length;
expect(wrapper.find('li')).to.have.lengthOf(length);
expect(wrapper.find(FieldSet)).to.have.lengthOf(length);
});
});

0 comments on commit 1bf83c3

Please sign in to comment.