TencentConfig.js 4.3 KB

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