APIGroupCard.js 8.4 KB

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