TencentConfig.jsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React, {Component} from 'react';
  2. import {Input, Select, Button, Row, Col} from 'antd';
  3. const Option = Select.Option;
  4. class TencentConfig extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. config: props.configs.find(obj => obj.name === props.currentConfig) || {
  9. name: '',
  10. schemas: [],
  11. cloudServer: '',
  12. database: '',
  13. configLocal: {}
  14. }
  15. };
  16. }
  17. switchCS = (value) => {
  18. this.setState({
  19. config: {
  20. ...this.state.config,
  21. cloudServer: value
  22. }
  23. })
  24. };
  25. switchConfigLocal = (label) => {
  26. return (e) => {
  27. this.setState({
  28. config: {
  29. ...this.state.config,
  30. configLocal: {...this.state.config.configLocal, [label]: e.target.value}
  31. }
  32. })
  33. };
  34. };
  35. switchDataBase = (value) => {
  36. this.setState({
  37. config: {
  38. ...this.state.config,
  39. database: value
  40. }
  41. })
  42. };
  43. componentWillReceiveProps(next) {
  44. this.setState({
  45. config: next.configs.find(obj => obj.name === next.currentConfig) || {
  46. name: '',
  47. schemas: [],
  48. cloudServer: '',
  49. database: '',
  50. configLocal: {}
  51. }
  52. });
  53. };
  54. render() {
  55. return (
  56. <div style={{margin: 20}}>
  57. <div style={{marginTop: 10}}>
  58. {
  59. this.state.config.name ? '' :
  60. <div style={{marginBottom: 30}}>
  61. <p><b>how about create a new one</b></p>
  62. </div>
  63. }
  64. </div>
  65. <div>
  66. <span className='table-title'> Cloud Config</span>
  67. <div style={{marginBottom: 10}}>
  68. <p><b>Cloud Server providers</b></p>
  69. <Select defaultValue="tencent" value={this.state.config.cloudServer} style={{width: 120}}
  70. onChange={this.switchCS}>
  71. <Option value="tencent">Tencent</Option>
  72. <Option value="aliyun">Aliyun</Option>
  73. <Option value="huawei">Huawei</Option>
  74. </Select>
  75. </div>
  76. <Row>
  77. <Col span={6}>
  78. <div style={{marginBottom: 30}}>
  79. <p><b>Serverless Cloud Function</b></p>
  80. <div>
  81. <div>
  82. <span className='vice-title'>secretID: </span>
  83. <Input value={this.state.config.configLocal.SCF_secretID} style={{width: 200}}
  84. onChange={this.switchConfigLocal('SCF_secretID')}/>
  85. </div>
  86. <div style={{marginTop: 5}}>
  87. <span className='vice-title'>secretKey: </span>
  88. <Input value={this.state.config.configLocal.SCF_secretKey} style={{width: 200}}
  89. onChange={this.switchConfigLocal('SCF_secretKey')}/>
  90. </div>
  91. </div>
  92. </div>
  93. </Col>
  94. <Col span={6}>
  95. <div style={{marginBottom: 30}}>
  96. <p><b>API</b></p>
  97. <div>
  98. <div>
  99. <span className='vice-title'>secretID: </span>
  100. <Input value={this.state.config.configLocal.API_secretID} style={{width: 200}}
  101. onChange={this.switchConfigLocal('API_secretID')}/>
  102. </div>
  103. <div style={{marginTop: 5}}>
  104. <span className='vice-title'>secretKey: </span>
  105. <Input value={this.state.config.configLocal.API_secretKey} style={{width: 200}}
  106. onChange={this.switchConfigLocal('API_secretKey')}/>
  107. </div>
  108. </div>
  109. </div>
  110. </Col>
  111. </Row>
  112. </div>
  113. <div style={{marginBottom: 30}}>
  114. <span className='table-title'> Database Config</span>
  115. <Select defaultValue="mongodb" value={this.state.config.database} style={{width: 120}}
  116. onChange={this.switchDataBase}>
  117. <Option value="mongodb">MongoDB</Option>
  118. <Option value="nedb">nedb</Option>
  119. <Option value="postgres">postgres</Option>
  120. </Select>
  121. </div>
  122. <Button type="primary" onClick={() => {
  123. this.props.addConfig(this.state.config, this.state.config.name);
  124. }}>SUBMIT</Button>
  125. <Button style={{marginLeft: 10}} type="danger" onClick={() => {
  126. this.props.deleteConfig(this.state.config.name);
  127. }}>DELETE</Button>
  128. </div>
  129. )
  130. }
  131. }
  132. export default TencentConfig;