All files / publisher/builds/components triggerBuild.js

100% Statements 5/5
83.33% Branches 5/6
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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              3x       1x                       3x   3x                                         1x                
import React, { Fragment } from "react";
import PropTypes from "prop-types";
 
import Notification from "@canonical/react-components/dist/components/Notification";
 
class TriggerBuild extends React.Component {
  constructor(props) {
    super(props);
  }
 
  renderError(errorMessage) {
    return (
      <div className="u-fixed-width">
        <Notification type="negative" title="Error:">
          {errorMessage
            ? errorMessage
            : "There was an error triggering a new build. Please try again."}
        </Notification>
      </div>
    );
  }
 
  render() {
    const { hasError, errorMessage, isLoading, onClick } = this.props;
 
    return (
      <Fragment>
        <div className="u-fixed-width u-clearfix">
          <h4 className="u-float-left">Latest builds</h4>
          {isLoading ? (
            <button className="p-button u-float-right has-icon" disabled>
              <i className="p-icon--spinner u-animation--spin" />
              <span>Requesting</span>
            </button>
          ) : (
            <button className="p-button u-float-right" onClick={onClick}>
              Trigger new build
            </button>
          )}
        </div>
        {hasError && this.renderError(errorMessage)}
      </Fragment>
    );
  }
}
 
TriggerBuild.propTypes = {
  hasError: PropTypes.bool,
  errorMessage: PropTypes.string,
  isLoading: PropTypes.bool,
  onClick: PropTypes.func,
};
 
export { TriggerBuild as default };