view-mode-button.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import classNames from 'classnames';
  4. import { trackAnalyticsEvent } from '../utils/tracking-utils';
  5. class ViewModeButton extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this.handleClick = this.handleClick.bind(this);
  9. }
  10. handleClick() {
  11. trackAnalyticsEvent('scope.layout.selector.click', {
  12. layout: this.props.viewMode,
  13. parentTopologyId: this.props.currentTopology.get('parentId'),
  14. topologyId: this.props.currentTopology.get('id'),
  15. });
  16. this.props.onClick();
  17. }
  18. render() {
  19. const { label, viewMode, disabled } = this.props;
  20. const isSelected = (this.props.topologyViewMode === viewMode);
  21. const className = classNames(`tour-step-anchor view-mode-selector-action view-${label}-action`, {
  22. 'view-mode-selector-action-selected': isSelected,
  23. });
  24. return (
  25. <div
  26. className={className}
  27. disabled={disabled}
  28. onClick={!disabled ? this.handleClick : undefined}
  29. title={`View ${label.toLowerCase()}`}>
  30. <i className={this.props.icons} />
  31. <span className="label">{label}</span>
  32. </div>
  33. );
  34. }
  35. }
  36. function mapStateToProps(state) {
  37. return {
  38. currentTopology: state.get('currentTopology'),
  39. topologyViewMode: state.get('topologyViewMode'),
  40. };
  41. }
  42. export default connect(mapStateToProps)(ViewModeButton);