All files / javascripts/SqlLab/components DataPreviewModal.jsx

0% Statements 0/16
0% Branches 0/4
0% Functions 0/2
0% Lines 0/16
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                                                                                                                                   
import React from 'react';
import PropTypes from 'prop-types';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Modal } from 'react-bootstrap';
 
import * as Actions from '../actions';
import ResultSet from './ResultSet';
 
const propTypes = {
  queries: PropTypes.object,
  actions: PropTypes.object,
  showDataPreviewModal: PropTypes.bool,
  dataPreviewQueryId: PropTypes.string,
};
 
class DataPreviewModal extends React.PureComponent {
  hide() {
    this.props.actions.hideDataPreview();
  }
  render() {
    if (this.props.showDataPreviewModal && this.props.dataPreviewQueryId) {
      const query = this.props.queries[this.props.dataPreviewQueryId];
      return (
        <Modal
          show={this.props.showDataPreviewModal}
          onHide={this.hide.bind(this)}
          bsStyle="lg"
        >
          <Modal.Header closeButton>
            <Modal.Title>
              Data preview for <strong>{query.tableName}</strong>
            </Modal.Title>
          </Modal.Header>
          <Modal.Body>
            <ResultSet
              query={query}
              visualize={false}
              csv={false}
              actions={this.props.actions}
              height={400}
            />
          </Modal.Body>
        </Modal>
      );
    }
    return null;
  }
}
DataPreviewModal.propTypes = propTypes;
 
function mapStateToProps(state) {
  return {
    queries: state.queries,
    showDataPreviewModal: state.showDataPreviewModal,
    dataPreviewQueryId: state.dataPreviewQueryId,
  };
}
function mapDispatchToProps(dispatch) {
  return {
    actions: bindActionCreators(Actions, dispatch),
  };
}
 
export default connect(mapStateToProps, mapDispatchToProps)(DataPreviewModal);