TencentConfig.js 5.6 KB

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