DeployCard.js 8.3 KB

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