TencentConfig.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import React, {Component} from 'react';
  2. import {Row, Col, Card, Button} 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: 'beijing',
  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. }, this.fetch);
  39. }
  40. fetch = () => {
  41. // todo: 没做每个 deploy 和 apigroup 和 apipath 的切换
  42. // todo: 换成 apollo 会更好
  43. if (this.state.fc === true) {
  44. request(graphqlUrl, SHOW_DEPLOY, {cloud_id: this.state.cloudID}).then(
  45. data => {
  46. this.setState({
  47. deploys: data.deploy_by_props,
  48. currentDeploy: data.deploy_by_props[0]
  49. })
  50. }
  51. );
  52. request(graphqlUrl, SHOW_APIGWGROUP, {cloud_id: this.state.cloudID}).then(
  53. data => {
  54. this.setState({
  55. groups: data.apiGWGroup_by_props,
  56. currentGroup: data.apiGWGroup_by_props[0]
  57. }, () => {
  58. request(graphqlUrl, SHOW_APIGWPATH, {apiGWGroup_id: this.state.currentGroup.id}).then(
  59. data => {
  60. this.setState({
  61. paths: data.apiGWPath_by_props,
  62. currentPath: data.apiGWPath_by_props[0]
  63. });
  64. }
  65. );
  66. });
  67. }
  68. );
  69. } else {
  70. this.setState({
  71. currentDeploy: '',
  72. currentGroup: '',
  73. currentPath: '',
  74. })
  75. }
  76. if(this.props.schemaID === '' || this.props.schemaID === undefined) {
  77. this.setState({
  78. couldDeploy: true
  79. });
  80. } else {
  81. request(graphqlUrl, SEARCH_SCHEMA, {id: this.props.schemaID}).then(
  82. data => {
  83. if(data.schema_by_id.schemaState === 'ok')
  84. this.setState({
  85. couldDeploy: true
  86. });
  87. }
  88. );
  89. }
  90. };
  91. pass = (value, kind) => {
  92. if(kind === 'deploy')
  93. this.setState({
  94. deployIdPassToPath: value
  95. });
  96. else
  97. this.setState({
  98. groupIdPassToPath: value
  99. })
  100. };
  101. switchRegion = (e) => {
  102. this.setState({
  103. region: e.target.value
  104. });
  105. };
  106. deployFC = () => {
  107. let _this = this;
  108. axios.get(`${deployUrl}`,
  109. // axios.get(`http://localhost:8999/graphql/deployall`,
  110. {
  111. params: {
  112. 'cloud-name': 'tencent',
  113. schema:"ecommerce_schemaID",
  114. deploy:"deploy_1544504304478_57468453",
  115. api:"path_1544504334478_82625598",
  116. group:"group_1544504325443_46750115"
  117. }
  118. })
  119. .then((res) => {
  120. console.log('deploy res', res);
  121. })
  122. .catch((err) => {
  123. console.log('err',err);
  124. console.log('err.response',err.response);
  125. console.log('err.response.data',err.response.data);
  126. });
  127. };
  128. render() {
  129. return (
  130. <div>
  131. <div style={{padding: '30px'}}>
  132. <Row gutter={16}>
  133. <Col span={14}>
  134. <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>
  135. <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>
  136. <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>
  137. <FormattedMessage id="Notification">{msg => <Card title={msg}><NotificationCard userID={this.props.userID} trialcase={this.props.trialcase}/></Card>}</FormattedMessage>
  138. </Col>
  139. <Col offset={2} span={6}>
  140. <Button type='primary' disabled={this.state.couldDeploy? '': 'disabled'} onClick={()=>this.deployFC()}><FormattedMessage id="deploy"/>!</Button>
  141. </Col>
  142. </Row>
  143. </div>
  144. </div>
  145. )
  146. }
  147. }
  148. export default TencentConfig;