MigrationFromReplicaOptions.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* eslint-disable dot-notation */
  15. import React, { PropTypes } from 'react';
  16. import Reflux from 'reflux';
  17. import withStyles from 'isomorphic-style-loader/lib/withStyles';
  18. import s from './MigrationFromReplicaOptions.scss';
  19. import Dropdown from '../NewDropdown';
  20. import Helper from "../Helper";
  21. class MigrationFromReplicaOptions extends Reflux.Component {
  22. static propTypes = {
  23. onCancel: PropTypes.func.isRequired,
  24. onMigrate: PropTypes.func.isRequired
  25. }
  26. constructor(props) {
  27. super(props)
  28. this.state = {
  29. fields: [
  30. {
  31. field: 'clone_disks',
  32. type: 'boolean'
  33. },
  34. {
  35. field: 'force',
  36. type: 'boolean'
  37. },
  38. {
  39. field: 'skip_os_morphing',
  40. type: 'boolean'
  41. }
  42. ]
  43. }
  44. }
  45. componentWillMount() {
  46. super.componentWillMount.call(this)
  47. }
  48. componentWillUnmount() {
  49. super.componentWillMount.call(this)
  50. }
  51. fieldChange(e, field) {
  52. let fields = this.state.fields.concat([]);
  53. fields.find(f => f.field === field).value = e.value === 'true'
  54. this.setState({ fields: fields })
  55. }
  56. render() {
  57. let booleanOptions = [{ label: 'Yes', value: 'true' }, { label: 'No', value: 'false' }]
  58. let fields = this.state.fields.map((f, i) => {
  59. if (f.type !== 'boolean') {
  60. return null
  61. }
  62. return (
  63. <div className="form-group" key={i}>
  64. <label>{Helper.convertCloudFieldLabel(f.field)}</label>
  65. <Dropdown
  66. options={booleanOptions}
  67. onChange={(e) => { this.fieldChange(e, f.field) }}
  68. placeholder="Choose a value"
  69. value={f.value ? booleanOptions[0] : booleanOptions[1]}
  70. />
  71. </div>
  72. )
  73. })
  74. let modalBody = (
  75. <div className={s.container}>
  76. <div className={s.formContainer}>
  77. {fields}
  78. </div>
  79. <div className={s.buttons}>
  80. <button className="gray" onClick={() => this.props.onCancel()}>Cancel</button>
  81. <button onClick={() => this.props.onMigrate(this.state.fields)}>Migrate</button>
  82. </div>
  83. </div>
  84. )
  85. return (
  86. <div className={s.root}>
  87. <div className={s.header}>
  88. <h3>Create Migration from Replica</h3>
  89. </div>
  90. <div className={s.images}>
  91. <div className={s.replicaImage} />
  92. <div className={s.arrowImage} />
  93. <div className={s.migrationImage} />
  94. </div>
  95. {modalBody}
  96. </div>
  97. )
  98. }
  99. }
  100. export default withStyles(MigrationFromReplicaOptions, s)