CloudConnectionAuth.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, { Component, PropTypes } from 'react';
  15. import withStyles from 'isomorphic-style-loader/lib/withStyles';
  16. import s from './CloudConnectionAuth.scss';
  17. import Helper from '../Helper';
  18. import LoadingIcon from "../LoadingIcon/LoadingIcon";
  19. const title = 'connection details';
  20. class CloudConnectionAuth extends Component {
  21. static propTypes = {
  22. connection: PropTypes.object
  23. }
  24. static contextTypes = {
  25. onSetTitle: PropTypes.func.isRequired,
  26. };
  27. constructor(props) {
  28. super(props)
  29. let fields = this.processProps(props)
  30. this.state = { fields: fields }
  31. }
  32. componentWillMount() {
  33. this.context.onSetTitle(title);
  34. }
  35. processProps(props) {
  36. let fields = []
  37. if (props.connection.credentials) {
  38. for (let fieldName in props.connection.credentials) {
  39. let value = props.connection.credentials[fieldName]
  40. if (value.value) { // if dropdown
  41. value = value.value
  42. }
  43. if (value === true) value = "Yes"
  44. if (value === false) value = "No"
  45. fields.push({
  46. fieldName: Helper.convertCloudFieldLabel(fieldName),
  47. fieldValue: value
  48. })
  49. }
  50. }
  51. return fields
  52. }
  53. renderFields() {
  54. if (this.state.fields.length) {
  55. return this.state.fields.map((field, index) => (
  56. <div className={s.formGroup} key={"formGroup_" + index}>
  57. <div className={s.title}>
  58. {field.fieldName}
  59. </div>
  60. <div className={s.value}>
  61. {field.fieldValue ? field.fieldValue : "-"}
  62. </div>
  63. </div>
  64. )
  65. )
  66. } else {
  67. return <LoadingIcon />
  68. }
  69. }
  70. render() {
  71. return (
  72. <div className={s.root}>
  73. <div className={s.container}>
  74. {this.renderFields()}
  75. </div>
  76. <button className="wire">Change Authentication</button>
  77. </div>
  78. );
  79. }
  80. }
  81. export default withStyles(CloudConnectionAuth, s);