TencentConfig.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import React, {Component} from 'react';
  2. import {Row, Col, Card, Button, Icon} from 'antd';
  3. import axios from 'axios';
  4. import APIGroupCard from './APIGroupCard';
  5. import APIPathCard from './APIPathCard';
  6. import DeployCard from './DeployCard';
  7. import NotificationCard from './NotificationCard';
  8. import {SHOW_DEPLOY, SHOW_APIGWGROUP, SHOW_APIGWPATH, SEARCH_SCHEMA} from "../../../../gql";
  9. import {request} from 'graphql-request'
  10. import {graphqlUrl,deployUrl} from "../../../../config";
  11. import {FormattedMessage} from 'react-intl';
  12. class TencentConfig extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. region: '',
  17. deploys: [],
  18. currentDeploy: '',
  19. groups: [],
  20. currentGroup: '',
  21. paths: [],
  22. currentPath: '',
  23. deployIdPassToPath: '',
  24. groupIdPassToPath: '',
  25. cloudID: props.cloudID,
  26. fc: props.fc,
  27. couldDeploy: false
  28. };
  29. }
  30. componentDidMount() {
  31. this.fetch();
  32. }
  33. componentWillReceiveProps(next) {
  34. this.setState({
  35. fc: next.fc,
  36. cloudID: next.cloudID,
  37. couldDeploy: false,
  38. region: ''
  39. }, this.fetch);
  40. }
  41. fetch = () => {
  42. // todo: 没做每个 deploy 和 apigroup 和 apipath 的切换
  43. // todo: 换成 apollo 会更好
  44. if (this.state.fc === true) {
  45. request(graphqlUrl, SHOW_DEPLOY, {cloud_id: this.state.cloudID}).then(
  46. data => {
  47. this.setState({
  48. deploys: data.deploy_by_props,
  49. currentDeploy: data.deploy_by_props[0]
  50. })
  51. }
  52. );
  53. request(graphqlUrl, SHOW_APIGWGROUP, {cloud_id: this.state.cloudID}).then(
  54. data => {
  55. this.setState({
  56. groups: data.apiGWGroup_by_props,
  57. currentGroup: data.apiGWGroup_by_props[0]
  58. }, () => {
  59. request(graphqlUrl, SHOW_APIGWPATH, {apiGWGroup_id: this.state.currentGroup.id}).then(
  60. data => {
  61. this.setState({
  62. paths: data.apiGWPath_by_props,
  63. currentPath: data.apiGWPath_by_props[0]
  64. });
  65. }
  66. );
  67. });
  68. }
  69. );
  70. } else {
  71. this.setState({
  72. currentDeploy: '',
  73. currentGroup: '',
  74. currentPath: '',
  75. })
  76. }
  77. if(this.props.schemaID === '' || this.props.schemaID === undefined) {
  78. this.setState({
  79. couldDeploy: true
  80. });
  81. } else {
  82. request(graphqlUrl, SEARCH_SCHEMA, {id: this.props.schemaID}).then(
  83. data => {
  84. if(data.schema_by_id.schemaState === 'ok')
  85. this.setState({
  86. couldDeploy: true
  87. });
  88. }
  89. );
  90. }
  91. };
  92. pass = (value, kind) => {
  93. if(kind === 'deploy')
  94. this.setState({
  95. deployIdPassToPath: value
  96. });
  97. else
  98. this.setState({
  99. groupIdPassToPath: value
  100. })
  101. };
  102. switchRegion = (e) => {
  103. this.setState({
  104. region: e.target.value
  105. });
  106. };
  107. deployFC = () => {
  108. let _this = this;
  109. axios.get(`${deployUrl}`,
  110. // axios.get(`http://localhost:8999/graphql/deployall`,
  111. {
  112. params: {
  113. 'cloud-name': 'tencent',
  114. schema:"ecommerce_schemaID",
  115. deploy:"deploy_1544504304478_57468453",
  116. api:"path_1544504334478_82625598",
  117. group:"group_1544504325443_46750115"
  118. }
  119. })
  120. .then((res) => {
  121. console.log('deploy res', res);
  122. })
  123. .catch((err) => {
  124. console.log('err',err);
  125. console.log('err.response',err.response);
  126. console.log('err.response.data',err.response.data);
  127. });
  128. };
  129. render() {
  130. let {groupName, trialcase} = this.props;
  131. return (
  132. <div>
  133. <div className="column-menu" onClick={this.props.goBack}>
  134. <Icon type="left" style={{color: '#3187FA'}}/> {groupName}
  135. </div>
  136. <div style={{padding: '30px'}}>
  137. <Row gutter={16}>
  138. <Col span={14}>
  139. <FormattedMessage id="API Group">{msg => <Card title={msg} style={{marginBottom: 10}}><APIGroupCard group={this.state.currentGroup} switchRegion={this.switchRegion} region={this.state.region} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass} kind={this.props.kind} trialcase={this.props.trialcase}/></Card>}</FormattedMessage>
  140. <FormattedMessage id="fc Deploy">{msg => <Card title={msg} style={{marginBottom: 10}}><DeployCard deploy={this.state.currentDeploy} switchRegion={this.switchRegion} region={this.state.region} defalutName={this.props.defalutName} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass} kind={this.props.kind} trialcase={this.props.trialcase}/></Card>}</FormattedMessage>
  141. <FormattedMessage id="API Path">{msg => <Card title={msg} style={{marginBottom: 10}}><APIPathCard path={this.state.currentPath} defalutName={this.props.defalutName} userID={this.props.userID} deployID={this.state.currentDeploy? this.state.currentDeploy.id : this.state.deployIdPassToPath} groupID={this.state.currentGroup? this.state.currentGroup.id : this.state.groupIdPassToPath} trialcase={this.props.trialcase}/></Card>}</FormattedMessage>
  142. <FormattedMessage id="Notification">{msg => <Card title={msg}><NotificationCard userID={this.props.userID} trialcase={this.props.trialcase}/></Card>}</FormattedMessage>
  143. </Col>
  144. <Col offset={2} span={6}>
  145. <Button type='primary' disabled={this.state.couldDeploy? '': 'disabled'} onClick={()=>this.deployFC()}><FormattedMessage id="deploy"/>!</Button>
  146. {
  147. this.state.couldDeploy?
  148. ''
  149. :
  150. <div>
  151. <span>if button is disabled, check your schema</span>
  152. </div>
  153. }
  154. </Col>
  155. </Row>
  156. </div>
  157. </div>
  158. )
  159. }
  160. }
  161. export default TencentConfig;