TencentConfig.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React, {Component} from 'react';
  2. import {Row, Col, Card, Button, Spin, Alert} 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_APIGWPATH, GET_PROJECT} from "../../../../gql";
  9. import {deployUrl} from "../../../../config";
  10. import {FormattedMessage} from 'react-intl';
  11. import gql from "graphql-tag";
  12. import {Query} from "react-apollo";
  13. class TencentConfig extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. region: '',
  18. couldDeploy: false,
  19. deployIdPassToPath: '',
  20. groupIdPassToPath: ''
  21. };
  22. }
  23. componentWillReceiveProps(next) {
  24. this.setState({
  25. couldDeploy: false,
  26. region: '',
  27. deployIdPassToPath: '',
  28. groupIdPassToPath: ''
  29. });
  30. }
  31. switchRegion = (e) => {
  32. this.setState({
  33. region: e.target.value
  34. });
  35. };
  36. pass = (value, kind) => {
  37. if (kind === 'deploy')
  38. this.setState({
  39. deployIdPassToPath: value
  40. });
  41. else
  42. this.setState({
  43. groupIdPassToPath: value
  44. })
  45. };
  46. deployFC = () => {
  47. let _this = this;
  48. axios.get(`${deployUrl}`,
  49. // axios.get(`http://localhost:8999/graphql/deployall`,
  50. {
  51. params: {
  52. 'cloud-name': 'tencent',
  53. schema: "ecommerce_schemaID",
  54. deploy: "deploy_1544504304478_57468453",
  55. api: "path_1544504334478_82625598",
  56. group: "group_1544504325443_46750115"
  57. }
  58. })
  59. .then((res) => {
  60. console.log('deploy res', res);
  61. })
  62. .catch((err) => {
  63. console.log('err', err);
  64. console.log('err.response', err.response);
  65. console.log('err.response.data', err.response.data);
  66. });
  67. };
  68. render() {
  69. let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
  70. return (
  71. <Query query={gql(GET_PROJECT)} variables={{id: projectID}}>
  72. {
  73. ({loading, error, data}) => {
  74. if (loading) {
  75. return <Spin style={{marginLeft: 3}}/>
  76. }
  77. if (error) {
  78. return 'error!';
  79. }
  80. let group = '',
  81. deploy = '',
  82. path = '',
  83. cloudID = 'tencent_CloudID';
  84. if (data.project_by_id.cloud_id !== null && data.project_by_id.cloud_id.cloudName === 'tencent') {
  85. group = data.project_by_id.apiGWGroup_id;
  86. deploy = data.project_by_id.deploy_id;
  87. cloudID = data.project_by_id.cloud_id.id;
  88. }
  89. let defaultName = data.project_by_id.projectName;
  90. return (
  91. <div>
  92. {
  93. data.project_by_id.schema_id.schemaState === 'ok' ?
  94. ''
  95. :
  96. this.props.trialcase?
  97. ''
  98. :
  99. <div style={{marginBottom: 10}}>
  100. <Alert message="数据表结构不符合规范,暂不能部署,请修改" type="warning"
  101. banner closable/>
  102. </div>
  103. }
  104. <div style={{padding: '30px'}}>
  105. <Row gutter={16}>
  106. <Col span={14}>
  107. <FormattedMessage id="fc Deploy">
  108. {
  109. msg =>
  110. <Card title={msg} style={{marginBottom: 10}}>
  111. <DeployCard
  112. deploy={deploy}
  113. switchRegion={this.switchRegion}
  114. region={this.state.region}
  115. defalutName={defaultName}
  116. userID={this.props.userID}
  117. cloudID={cloudID}
  118. trialcase={this.props.trialcase}
  119. pass={this.pass}
  120. />
  121. </Card>
  122. }
  123. </FormattedMessage>
  124. <FormattedMessage id="API Group">
  125. {
  126. msg =>
  127. <Card title={msg} style={{marginBottom: 10}}>
  128. <APIGroupCard
  129. group={group}
  130. userID={this.props.userID}
  131. switchRegion={this.switchRegion}
  132. region={this.state.region}
  133. cloudID={cloudID}
  134. trialcase={this.props.trialcase}
  135. pass={this.pass}
  136. />
  137. </Card>
  138. }
  139. </FormattedMessage>
  140. <Query query={gql(SHOW_APIGWPATH)}
  141. variables={{apiGWGroup_id: data.project_by_id.apiGWGroup_id ? data.project_by_id.apiGWGroup_id.id : ''}}>
  142. {
  143. ({loading, error, data}) => {
  144. if (loading) {
  145. return <Spin style={{marginLeft: 3}}/>
  146. }
  147. if (error) {
  148. return 'error!';
  149. }
  150. if (data.apiGWPath_by_props.length > 0)
  151. path = data.apiGWPath_by_props[0];
  152. return (
  153. <FormattedMessage id="API Path">
  154. {
  155. msg =>
  156. <Card title={msg} style={{marginBottom: 10}}>
  157. <APIPathCard
  158. path={path}
  159. defalutName={defaultName}
  160. userID={this.props.userID}
  161. trialcase={this.props.trialcase}
  162. deployID={deploy ? deploy.id : this.state.deployIdPassToPath}
  163. groupID={group ? group.id : this.state.groupIdPassToPath}
  164. />
  165. </Card>
  166. }
  167. </FormattedMessage>
  168. )
  169. }
  170. }
  171. </Query>
  172. <FormattedMessage id="Notification">
  173. {
  174. msg =>
  175. <Card title={msg}>
  176. <NotificationCard
  177. userID={this.props.userID}
  178. trialcase={this.props.trialcase}
  179. />
  180. </Card>
  181. }
  182. </FormattedMessage>
  183. </Col>
  184. <Col offset={2} span={6}>
  185. <Button type='primary'
  186. disabled={data.project_by_id.schema_id.schemaState === 'ok' ? '' : 'disabled'}
  187. onClick={() => this.deployFC()}><FormattedMessage
  188. id="deploy"/>!</Button>
  189. </Col>
  190. </Row>
  191. </div>
  192. </div>
  193. )
  194. }
  195. }
  196. </Query>
  197. )
  198. }
  199. }
  200. export default TencentConfig;