All files / javascripts/SqlLab/components App.jsx

45.45% Statements 10/22
0% Branches 0/4
0% Functions 0/3
45.45% Lines 10/22
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 791x 1x   1x 1x 1x 1x 1x   1x 1x                                                                                                   1x                                    
import * as Actions from '../actions';
import React from 'react';
 
import TabbedSqlEditors from './TabbedSqlEditors';
import QueryAutoRefresh from './QueryAutoRefresh';
import QuerySearch from './QuerySearch';
import Alerts from './Alerts';
import DataPreviewModal from './DataPreviewModal';
 
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
 
class App extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      hash: window.location.hash,
    };
  }
  componentDidMount() {
    window.addEventListener('hashchange', this.onHashChanged.bind(this));
  }
  componentWillUnmount() {
    window.removeEventListener('hashchange', this.onHashChanged.bind(this));
  }
  onHashChanged() {
    this.setState({ hash: window.location.hash });
  }
  render() {
    let content;
    if (this.state.hash) {
      content = (
        <div className="container-fluid">
          <div className="row">
            <div className="col-md-12">
              <QuerySearch />
            </div>
          </div>
        </div>
      );
    } else {
      content = (
        <div>
          <QueryAutoRefresh />
          <TabbedSqlEditors />
        </div>
      );
    }
    return (
      <div className="App SqlLab">
        <Alerts alerts={this.props.alerts} actions={this.props.actions} />
        <DataPreviewModal />
        <div className="container-fluid">
          {content}
        </div>
      </div>
    );
  }
}
 
App.propTypes = {
  alerts: React.PropTypes.array,
  actions: React.PropTypes.object,
};
 
function mapStateToProps(state) {
  return {
    alerts: state.alerts,
  };
}
function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(Actions, dispatch),
  };
}
 
export { App };
export default connect(mapStateToProps, mapDispatchToProps)(App);