All files / javascripts/explorev2/components Filters.jsx

85% Statements 17/20
50% Branches 1/2
33.33% Functions 1/3
85% Lines 17/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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 881x   1x 1x 1x 1x   1x                   1x                               2x 2x 2x 2x   2x 2x 2x                           2x                                     1x 1x                          
import React from 'react';
// import { Tab, Row, Col, Nav, NavItem } from 'react-bootstrap';
import Filter from './Filter';
import { Button } from 'react-bootstrap';
import { connect } from 'react-redux';
import shortid from 'shortid';
 
const propTypes = {
  actions: React.PropTypes.object.isRequired,
  datasource_type: React.PropTypes.string.isRequired,
  datasource_id: React.PropTypes.number.isRequired,
  filterColumnOpts: React.PropTypes.array,
  filters: React.PropTypes.array,
  prefix: React.PropTypes.string,
  renderFilterSelect: React.PropTypes.bool,
};
 
const defaultProps = {
  filterColumnOpts: [],
  filters: [],
  prefix: 'flt',
};
 
class Filters extends React.Component {
  addFilter() {
    this.props.actions.addFilter({
      id: shortid.generate(),
      prefix: this.props.prefix,
      col: null,
      op: null,
      value: null,
    });
  }
  render() {
    const filters = [];
    let i = 0;
    this.props.filters.forEach((filter) => {
      // only display filters with current prefix
      i++;
      Eif (filter.prefix === this.props.prefix) {
        filters.push(
          <Filter
            key={i}
            filterColumnOpts={this.props.filterColumnOpts}
            actions={this.props.actions}
            prefix={this.props.prefix}
            filter={filter}
            renderFilterSelect={this.props.renderFilterSelect}
            datasource_type={this.props.datasource_type}
            datasource_id={this.props.datasource_id}
          />
        );
      }
    });
    return (
      <div>
        {filters}
        <div className="row space-2">
          <div className="col-lg-2">
            <Button
              id="add-button"
              bsSize="sm"
              onClick={this.addFilter.bind(this)}
            >
              <i className="fa fa-plus" /> &nbsp; Add Filter
            </Button>
          </div>
        </div>
      </div>
    );
  }
}
 
Filters.propTypes = propTypes;
Filters.defaultProps = defaultProps;
 
function mapStateToProps(state) {
  return {
    datasource_type: state.datasource_type,
    filterColumnOpts: state.filterColumnOpts,
    filters: state.viz.form_data.filters,
    renderFilterSelect: state.filter_select,
  };
}
 
export { Filters };
export default connect(mapStateToProps, () => ({}))(Filters);