node-details-relatives-link.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 MatchedText from '../matched-text';
  6. class NodeDetailsRelativesLink 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.id,
  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 title = `View in ${this.props.topologyId}: ${this.props.label}`;
  29. return (
  30. <span
  31. className="node-details-relatives-link"
  32. title={title}
  33. onClick={this.handleClick}
  34. ref={this.saveNodeRef}>
  35. <MatchedText text={this.props.label} match={this.props.match} />
  36. </span>
  37. );
  38. }
  39. }
  40. // Using this instead of PureComponent because of props.dispatch
  41. export default connect()(NodeDetailsRelativesLink);