nodes-resources.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import ZoomableCanvas from './zoomable-canvas';
  4. import NodesResourcesLayer from './nodes-resources/node-resources-layer';
  5. import { layersTopologyIdsSelector } from '../selectors/resource-view/layout';
  6. import {
  7. resourcesLimitsSelector,
  8. resourcesZoomStateSelector,
  9. } from '../selectors/resource-view/zoom';
  10. import { clickBackground } from '../actions/app-actions';
  11. import { CONTENT_COVERING } from '../constants/naming';
  12. class NodesResources extends React.Component {
  13. constructor(props, context) {
  14. super(props, context);
  15. this.handleMouseClick = this.handleMouseClick.bind(this);
  16. }
  17. handleMouseClick() {
  18. if (this.props.selectedNodeId) {
  19. this.props.clickBackground();
  20. }
  21. }
  22. renderLayers(transform) {
  23. return this.props.layersTopologyIds.map((topologyId, index) => (
  24. <NodesResourcesLayer
  25. key={topologyId}
  26. topologyId={topologyId}
  27. transform={transform}
  28. slot={index}
  29. />
  30. ));
  31. }
  32. render() {
  33. return (
  34. <div className="nodes-resources">
  35. <ZoomableCanvas
  36. onClick={this.handleMouseClick}
  37. fixVertical
  38. boundContent={CONTENT_COVERING}
  39. limitsSelector={resourcesLimitsSelector}
  40. zoomStateSelector={resourcesZoomStateSelector}>
  41. {transform => this.renderLayers(transform)}
  42. </ZoomableCanvas>
  43. </div>
  44. );
  45. }
  46. }
  47. function mapStateToProps(state) {
  48. return {
  49. layersTopologyIds: layersTopologyIdsSelector(state),
  50. selectedNodeId: state.get('selectedNodeId'),
  51. };
  52. }
  53. export default connect(
  54. mapStateToProps,
  55. { clickBackground }
  56. )(NodesResources);