TencentConfig.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. };
  20. // todo: 没做每个 deploy 和 apigroup 和 apipath 的切换
  21. // todo: 换成 apollo 会更好
  22. if (props.cloudID !== '') {
  23. request('http://123.206.193.98:3000/graphql', SHOW_DEPLOY, {cloud_id: props.cloudID}).then(
  24. data => {
  25. this.setState({
  26. deploys: data.deploy_by_props,
  27. currentDeploy: data.deploy_by_props[0]
  28. })
  29. }
  30. );
  31. request('http://123.206.193.98:3000/graphql', SHOW_APIGWGROUP, {cloud_id: props.cloudID}).then(
  32. data => {
  33. this.setState({
  34. groups: data.apiGWGroup_by_props,
  35. currentGroup: data.apiGWGroup_by_props[0]
  36. }, () => {
  37. request('http://123.206.193.98:3000/graphql', SHOW_APIGWPATH, {apiGWGroup_id: this.state.currentGroup.id}).then(
  38. data => {
  39. this.setState({
  40. paths: data.apiGWPath_by_props,
  41. currentPath: data.apiGWPath_by_props[0]
  42. });
  43. }
  44. );
  45. });
  46. }
  47. );
  48. }
  49. }
  50. switchRegion = (e) => {
  51. this.setState({
  52. region: e.target.value
  53. });
  54. };
  55. render() {
  56. return (
  57. <div>
  58. <div style={{padding: '30px'}}>
  59. <Row gutter={16}>
  60. <Col span={12}>
  61. <Card title="Deploy" style={{marginBottom: 10}}><DeployCard deploy={this.state.currentDeploy} switchRegion={this.switchRegion} region={this.state.region} schemaName={this.props.schemaName}/></Card>
  62. <Card title="API Group" style={{marginBottom: 10}}><APIGroupCard group={this.state.currentGroup} switchRegion={this.switchRegion} region={this.state.region}/></Card>
  63. <Card title="API Path"><APIPathCard path={this.state.currentPath} schemaName={this.props.schemaName}/></Card>
  64. </Col>
  65. <Col offset={2} span={8}>
  66. <Button type='primary'>deploy it</Button>
  67. </Col>
  68. </Row>
  69. </div>
  70. </div>
  71. )
  72. }
  73. }
  74. export default TencentConfig;