all files / src/components/ StackTraceMessage.jsx

73.91% Statements 17/23
33.33% Branches 6/18
25% Functions 1/4
72.22% Lines 13/18
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                                                                                
EI/* eslint-disable react/no-danger */
import React from 'react';
import PropTypes from 'prop-types';
import { Alert, Collapse } from 'react-bootstrap';
 
const propTypes = {
  message: PropTypes.string,
  queryResponse: PropTypes.object,
  showStackTrace: PropTypes.bool,
};
const defaultProps = {
  showStackTrace: false,
};
 
class StackTraceMessage extends React.PureComponent {
  constructor(props) {
    super(props);
 
    this.state = {
      showStackTrace: props.showStackTrace,
    };
  }
 
  hasTrace() {
    return this.props.queryResponse && this.props.queryResponse.stacktrace;
  }
 
  render() {
    return (
      <div className={`stack-trace-container${this.hasTrace() ? ' has-trace' : ''}`}>
        <Alert
          bsStyle="warning"
          onClick={() => this.setState({ showStackTrace: !this.state.showStackTrace })}
        >
          {this.props.message}
        </Alert>
        {this.hasTrace() &&
          <Collapse in={this.state.showStackTrace}>
            <pre>
              {this.props.queryResponse.stacktrace}
            </pre>
          </Collapse>
        }
      </div>
    );
  }
}
 
StackTraceMessage.propTypes = propTypes;
StackTraceMessage.defaultProps = defaultProps;
 
export default StackTraceMessage;