DeployCard.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import React, {Component} from 'react';
  2. import {Input, Radio, Collapse, Button, Icon} from 'antd';
  3. import {ADD_DEPLOY, UPDATE_DEPLOY} from "../../../../../gql";
  4. import {request} from 'graphql-request'
  5. import {idGen} from "../../../../../func";
  6. const Panel = Collapse.Panel;
  7. class DeployCard extends Component {
  8. constructor(props) {
  9. super(props);
  10. let {functionName, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId, region} = props.deploy;
  11. props.deploy !== '' ?
  12. this.state = {
  13. configs: ['description', 'cosBucketName', 'cosObjectName', 'vpcId', 'subnetId'],
  14. description: '',
  15. showOK: false,
  16. functionName,
  17. region,
  18. cosBucketName,
  19. cosObjectName,
  20. cosBucketRegion,
  21. serviceName,
  22. vpcId,
  23. subnetId
  24. }
  25. :
  26. this.state = {
  27. configs: ['description', 'cosBucketName', 'cosObjectName', 'vpcId', 'subnetId'],
  28. description: '',
  29. showOK: false,
  30. functionName: props.schemaName,
  31. region: props.region,
  32. cosBucketName: 'graphqlfc',
  33. cosObjectName: props.schemaName,
  34. cosBucketRegion: props.region,
  35. serviceName: '',
  36. vpcId: '',
  37. subnetId: '',
  38. }
  39. }
  40. componentWillReceiveProps(next) {
  41. if (next.deploy !== '') {
  42. let {functionName, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId, region} = next.deploy;
  43. this.setState({
  44. functionName,
  45. region,
  46. cosBucketName,
  47. cosObjectName,
  48. cosBucketRegion,
  49. serviceName,
  50. vpcId,
  51. subnetId
  52. })
  53. } else {
  54. this.setState({
  55. functionName: next.schemaName,
  56. region: next.region,
  57. cosBucketName: 'graphqlfc',
  58. cosObjectName: next.schemaName,
  59. cosBucketRegion: next.region,
  60. serviceName: '',
  61. vpcId: '',
  62. subnetId: ''
  63. });
  64. }
  65. };
  66. switchConfig = (label) => {
  67. return (e) => {
  68. this.setState({
  69. [label]: e.target.value
  70. })
  71. };
  72. };
  73. ok = (id) => {
  74. let {description, cosBucketName, subnetId, cosObjectName, region, vpcId, cosBucketRegion, functionName} = this.state;
  75. let varObj = {
  76. id,
  77. cloud_id: this.props.cloudID,
  78. user_id: this.props.userID,
  79. description,
  80. cosBucketName,
  81. subnetId,
  82. cosObjectName,
  83. region,
  84. vpcId,
  85. cosBucketRegion,
  86. functionName,
  87. memorySize: 512,
  88. timeout: 300,
  89. handler: 'tencent_graphql.Bridge::handler',
  90. serviceName: "",
  91. fc_id: '',
  92. createdAt: new Date().getTime(),
  93. updatedAt: ''
  94. };
  95. if (this.props.deploy === '') {
  96. request('http://123.206.193.98:3000/graphql', ADD_DEPLOY, varObj).then(
  97. data => {
  98. if (data.create_deploy !== null) {
  99. this.setState({
  100. showOK: true
  101. })
  102. }
  103. setTimeout(()=>{
  104. this.setState({
  105. showOK: false
  106. })
  107. }, 1500)
  108. }
  109. )
  110. } else {
  111. let {description, cosBucketName, subnetId, cosObjectName, region, vpcId, cosBucketRegion, functionName} = this.state;
  112. let varObj = {
  113. id: this.props.deploy.id,
  114. description,
  115. subnetId,
  116. cosBucketName,
  117. cosObjectName,
  118. region,
  119. vpcId,
  120. cosBucketRegion,
  121. functionName,
  122. updatedAt: new Date().getTime()
  123. };
  124. request('http://123.206.193.98:3000/graphql', UPDATE_DEPLOY, varObj).then(
  125. data => {
  126. if (data.update_deploy !== null) {
  127. this.setState({
  128. showOK: true
  129. })
  130. }
  131. setTimeout(()=>{
  132. this.setState({
  133. showOK: false
  134. })
  135. }, 1500)
  136. }
  137. )
  138. }
  139. };
  140. render() {
  141. const customPanelStyle = {
  142. background: '#f7f7f7',
  143. borderRadius: 4,
  144. marginBottom: 24,
  145. border: 0,
  146. overflow: 'hidden',
  147. };
  148. return (
  149. <div>
  150. <div style={{marginBottom: 10}}>
  151. <span className='vice-title'>functionName: </span>
  152. <Input value={this.state.functionName} style={{width: 400}}
  153. onChange={this.switchConfig('functionName')}/>
  154. </div>
  155. <div style={{marginBottom: 10}}>
  156. <span className='vice-title'>region: </span>
  157. <Radio.Group onChange={(e) => {
  158. this.props.switchRegion(e);
  159. this.setState({
  160. region: e.target.value
  161. })
  162. }} defaultValue={this.state.region} buttonStyle="solid">
  163. <Radio.Button value="guangzhou">Guangzhou</Radio.Button>
  164. <Radio.Button value="shanghai">Shanghai</Radio.Button>
  165. <Radio.Button value="beijing">Beijing</Radio.Button>
  166. <Radio.Button value="chengdu">Chengdu</Radio.Button>
  167. </Radio.Group>
  168. </div>
  169. <Collapse bordered={false}>
  170. <Panel header="Want more options?" style={customPanelStyle}>
  171. <div style={{marginBottom: 10}}>
  172. <span className='vice-title'>cosBucketRegion: </span>
  173. <Radio.Group onChange={this.switchConfig('cosBucketRegion')}
  174. value={this.state.cosBucketRegion} buttonStyle="solid">
  175. <Radio.Button value="guangzhou">Guangzhou</Radio.Button>
  176. <Radio.Button value="shanghai">Shanghai</Radio.Button>
  177. <Radio.Button value="beijing">Beijing</Radio.Button>
  178. <Radio.Button value="chengdu">Chengdu</Radio.Button>
  179. </Radio.Group>
  180. </div>
  181. <div style={{marginBottom: 10}}>
  182. <span className='vice-title'>serviceName: </span>
  183. <Input value={this.state.serviceName} style={{width: 200}} disabled
  184. onChange={this.switchConfig('serviceName')}/>
  185. </div>
  186. {
  187. this.state.configs.map(config => (
  188. <div key={config} style={{marginBottom: 10}}>
  189. <span className='vice-title'>{config}: </span>
  190. <Input value={this.state[config]} style={{width: 200}}
  191. onChange={this.switchConfig(config)}/>
  192. </div>
  193. ))
  194. }
  195. </Panel>
  196. </Collapse>
  197. <Button onClick={()=>{
  198. const id = idGen('deploy');
  199. this.ok(id);
  200. this.props.pass(id, 'deploy');
  201. }} type='primary'>ok</Button>
  202. {
  203. this.state.showOK === true?
  204. <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
  205. :
  206. ''
  207. }
  208. </div>
  209. )
  210. }
  211. }
  212. export default DeployCard;