TencentConfig.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, {Component} from 'react';
  2. import {Row, Col, Card, Button} from 'antd';
  3. import APIGroupCard from './APIGroupCard';
  4. import APIPathCard from './APIPathCard';
  5. import DeployCard from './DeployCard';
  6. import {SHOW_DEPLOY, SHOW_APIGWGROUP, SHOW_APIGWPATH} from "../../../gql";
  7. import {request} from 'graphql-request'
  8. class TencentConfig extends Component {
  9. constructor(props) {
  10. super(props);
  11. this.state = {
  12. region: 'beijing',
  13. deploys: [],
  14. currentDeploy: '',
  15. groups: [],
  16. currentGroup: '',
  17. paths: [],
  18. currentPath: '',
  19. deployIdPassToPath: '',
  20. groupIdPassToPath: ''
  21. };
  22. // todo: 没做每个 deploy 和 apigroup 和 apipath 的切换
  23. // todo: 换成 apollo 会更好
  24. if (props.fc === true) {
  25. request('http://123.206.193.98:3000/graphql', SHOW_DEPLOY, {cloud_id: props.cloudID}).then(
  26. data => {
  27. this.setState({
  28. deploys: data.deploy_by_props,
  29. currentDeploy: data.deploy_by_props[0]
  30. })
  31. }
  32. );
  33. request('http://123.206.193.98:3000/graphql', SHOW_APIGWGROUP, {cloud_id: props.cloudID}).then(
  34. data => {
  35. this.setState({
  36. groups: data.apiGWGroup_by_props,
  37. currentGroup: data.apiGWGroup_by_props[0]
  38. }, () => {
  39. request('http://123.206.193.98:3000/graphql', SHOW_APIGWPATH, {apiGWGroup_id: this.state.currentGroup.id}).then(
  40. data => {
  41. this.setState({
  42. paths: data.apiGWPath_by_props,
  43. currentPath: data.apiGWPath_by_props[0]
  44. });
  45. }
  46. );
  47. });
  48. }
  49. );
  50. }
  51. }
  52. pass = (value, kind) => {
  53. if(kind === 'deploy')
  54. this.setState({
  55. deployIdPassToPath: value
  56. });
  57. else
  58. this.setState({
  59. groupIdPassToPath: value
  60. })
  61. };
  62. switchRegion = (e) => {
  63. this.setState({
  64. region: e.target.value
  65. });
  66. };
  67. render() {
  68. return (
  69. <div>
  70. <div style={{padding: '30px'}}>
  71. <Row gutter={16}>
  72. <Col span={14}>
  73. <Card title="Deploy" style={{marginBottom: 10}}><DeployCard deploy={this.state.currentDeploy} switchRegion={this.switchRegion} region={this.state.region} schemaName={this.props.schemaName} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass}/></Card>
  74. <Card title="API Group" 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}/></Card>
  75. <Card title="API Path"><APIPathCard path={this.state.currentPath} schemaName={this.props.schemaName} 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}/></Card>
  76. </Col>
  77. <Col offset={2} span={6}>
  78. <Button type='primary'>deploy it</Button>
  79. </Col>
  80. </Row>
  81. </div>
  82. </div>
  83. )
  84. }
  85. }
  86. export default TencentConfig;