metric-selector.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { unhoverMetric } from '../actions/app-actions';
  4. import { availableMetricsSelector } from '../selectors/node-metric';
  5. import MetricSelectorItem from './metric-selector-item';
  6. class MetricSelector extends React.Component {
  7. constructor(props, context) {
  8. super(props, context);
  9. this.onMouseOut = this.onMouseOut.bind(this);
  10. }
  11. onMouseOut() {
  12. this.props.unhoverMetric();
  13. }
  14. render() {
  15. const { availableMetrics } = this.props;
  16. const hasMetrics = !availableMetrics.isEmpty();
  17. //默认选中第一个指标,Apdex 方式2
  18. // let defaultMetric;
  19. // hasMetrics && availableMetrics.map(metric => {
  20. // if (!defaultMetric) {
  21. // defaultMetric = metric.get('label')
  22. // }
  23. // })
  24. return (
  25. <div className="metric-selector">
  26. {hasMetrics
  27. && (
  28. <div className="metric-selector-wrapper" onMouseLeave={this.onMouseOut}>
  29. {availableMetrics.map(metric => (
  30. <MetricSelectorItem
  31. key={metric.get('id')}
  32. metric={metric}
  33. // defaultMetric={defaultMetric}
  34. />
  35. ))}
  36. </div>
  37. )
  38. }
  39. </div>
  40. );
  41. }
  42. }
  43. function mapStateToProps(state) {
  44. return {
  45. availableMetrics: availableMetricsSelector(state),
  46. };
  47. }
  48. export default connect(
  49. mapStateToProps,
  50. { unhoverMetric }
  51. )(MetricSelector);