node-details-health.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import React from 'react';
  2. import ShowMore from '../show-more';
  3. import NodeDetailsHealthLinkItem from './node-details-health-link-item';
  4. export default class NodeDetailsHealth extends React.Component {
  5. constructor(props, context) {
  6. super(props, context);
  7. this.state = {
  8. expanded: false
  9. };
  10. this.handleClickMore = this.handleClickMore.bind(this);
  11. }
  12. handleClickMore() {
  13. this.setState(prevState => ({
  14. expanded: !prevState.expanded
  15. }));
  16. }
  17. render() {
  18. const {
  19. metrics = [],
  20. topologyId,
  21. } = this.props;
  22. let primeMetrics = metrics.filter(m => !m.valueEmpty);
  23. let emptyMetrics = metrics.filter(m => m.valueEmpty);
  24. if (primeMetrics.length === 0 && emptyMetrics.length > 0) {
  25. primeMetrics = emptyMetrics;
  26. emptyMetrics = [];
  27. }
  28. const shownWithData = this.state.expanded ? primeMetrics : primeMetrics.slice(0, 3);
  29. const shownEmpty = this.state.expanded ? emptyMetrics : [];
  30. const notShown = metrics.length - shownWithData.length - shownEmpty.length;
  31. return (
  32. <div className="node-details-health" style={{ justifyContent: 'space-around' }}>
  33. <div className="node-details-health-wrapper">
  34. {shownWithData.map(item => (
  35. <NodeDetailsHealthLinkItem
  36. {...item}
  37. key={item.id}
  38. topologyId={topologyId}
  39. />
  40. ))}
  41. </div>
  42. <div className="node-details-health-wrapper">
  43. {shownEmpty.map(item => (
  44. <NodeDetailsHealthLinkItem
  45. {...item}
  46. key={item.id}
  47. topologyId={topologyId}
  48. />
  49. ))}
  50. </div>
  51. <ShowMore
  52. handleClick={this.handleClickMore}
  53. collection={metrics}
  54. expanded={this.state.expanded}
  55. notShown={notShown}
  56. hideNumber={this.state.expanded}
  57. />
  58. </div>
  59. );
  60. }
  61. }