node-details-control-button.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { isEmpty } from 'lodash';
  4. import classNames from 'classnames';
  5. import { trackAnalyticsEvent } from '../../utils/tracking-utils';
  6. import { doControl } from '../../actions/request-actions';
  7. class NodeDetailsControlButton extends React.Component {
  8. constructor(props, context) {
  9. super(props, context);
  10. this.handleClick = this.handleClick.bind(this);
  11. }
  12. render() {
  13. const { icon, id, human } = this.props.control;
  14. const className = classNames('tour-step-anchor node-control-button', icon, {
  15. // Old Agent / plugins don't include the 'fa ' prefix, so provide it if they don't.
  16. fa: icon.startsWith('fa-'),
  17. 'node-control-button-pending': this.props.pending
  18. });
  19. return (
  20. <i className={className} data-id={id} title={human} onClick={this.handleClick} />
  21. );
  22. }
  23. handleClick(ev) {
  24. ev.preventDefault();
  25. const { id, human, confirmation } = this.props.control;
  26. trackAnalyticsEvent('scope.node.control.click', { id, title: human });
  27. if (isEmpty(confirmation) || window.confirm(confirmation)) { // eslint-disable-line no-alert
  28. this.props.dispatch(doControl(this.props.nodeId, this.props.control));
  29. }
  30. }
  31. }
  32. // Using this instead of PureComponent because of props.dispatch
  33. export default connect()(NodeDetailsControlButton);