node-details-table-node-link.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { clickRelative } from '../../actions/request-actions';
  4. import { trackAnalyticsEvent } from '../../utils/tracking-utils';
  5. import { dismissRowClickProps } from '../../utils/dom-utils';
  6. class NodeDetailsTableNodeLink extends React.Component {
  7. constructor(props, context) {
  8. super(props, context);
  9. this.handleClick = this.handleClick.bind(this);
  10. this.saveNodeRef = this.saveNodeRef.bind(this);
  11. }
  12. handleClick(ev) {
  13. ev.preventDefault();
  14. trackAnalyticsEvent('scope.node.relative.click', {
  15. topologyId: this.props.topologyId,
  16. });
  17. this.props.dispatch(clickRelative(
  18. this.props.nodeId,
  19. this.props.topologyId,
  20. this.props.label,
  21. this.node.getBoundingClientRect()
  22. ));
  23. }
  24. saveNodeRef(ref) {
  25. this.node = ref;
  26. }
  27. render() {
  28. const { label, labelMinor } = this.props;
  29. const title = !labelMinor ? label : `${label} (${labelMinor})`;
  30. return (
  31. <span
  32. className="node-details-table-node-link"
  33. title={title}
  34. ref={this.saveNodeRef}
  35. onClick={this.handleClick}
  36. {...dismissRowClickProps}
  37. >
  38. {label}
  39. </span>
  40. );
  41. }
  42. }
  43. // Using this instead of PureComponent because of props.dispatch
  44. export default connect()(NodeDetailsTableNodeLink);