EndpointUsage.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React, { PropTypes } from 'react';
  15. import Reflux from 'reflux';
  16. import MigrationStore from '../../stores/MigrationStore';
  17. class EndpointUsage extends Reflux.Component {
  18. static propTypes = {
  19. connectionId: PropTypes.string
  20. };
  21. constructor(props) {
  22. super(props)
  23. this.store = MigrationStore;
  24. this.state = {
  25. connectionId: props.connectionId,
  26. migrationCount: 0,
  27. replicaCount: 0
  28. }
  29. }
  30. componentWillMount() {
  31. super.componentWillMount.call(this)
  32. this.componentWillReceiveProps(this.props)
  33. }
  34. componentWillReceiveProps(props) {
  35. if (props.connectionId && this.state.migrations) {
  36. let migrationCount = 0
  37. let replicaCount = 0
  38. this.state.migrations.forEach(migration => {
  39. if (migration.destination_endpoint_id === this.state.connectionId ||
  40. migration.origin_endpoint_id === this.state.connectionId) {
  41. migrationCount++
  42. }
  43. })
  44. this.state.replicas.forEach(replica => {
  45. if (replica.destination_endpoint_id === this.state.connectionId ||
  46. replica.origin_endpoint_id === this.state.connectionId) {
  47. replicaCount++
  48. }
  49. })
  50. this.setState({ migrationCount: migrationCount, replicaCount: replicaCount })
  51. }
  52. }
  53. render() {
  54. if (this.state && this.state.connectionId) {
  55. return <div>{this.state.migrationCount} migrations, {this.state.replicaCount} replicas</div>;
  56. } else {
  57. return null
  58. }
  59. }
  60. }
  61. export default EndpointUsage;