Deploy.jsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import React, {Component} from 'react';
  2. import {Card, Input} from 'antd';
  3. import TencentConfig from './tencent/TencentConfig';
  4. import AliConfig from './ali/AliConfig';
  5. import AmazonConfig from './amazon/AmazonConfig';
  6. import HuaweiConfig from './huawei/HuaweiConfig';
  7. import './index.css';
  8. import {SHOW_FC, SEARCH_SCHEMA} from "../../gql";
  9. import {request} from 'graphql-request'
  10. const tabListNoTitle = [{
  11. key: 'tencent',
  12. tab: 'Tencent',
  13. }, {
  14. key: 'aliyun',
  15. tab: 'Aliyun',
  16. }, {
  17. key: 'amazon',
  18. tab: 'AWS',
  19. }];
  20. class Deploy extends Component {
  21. constructor(props) {
  22. super(props);
  23. this.state = {
  24. show: false,
  25. cloud: 'tencent',
  26. tencentCloudID: '',
  27. aliyunCloudID: '',
  28. amazonCloudID: '',
  29. // todo: 该schema应该由props传入,无论是哪一层,反正不是这一层。(路由传入吧)
  30. // 有fc的schema -- 测试数据
  31. // schemaID: 'schema_1542243424669_92094965',
  32. // 无fc的schema -- 测试数据
  33. schemaID: 'schema_1542967129456_05958413',
  34. schemaName: ''
  35. };
  36. request('http://123.206.193.98:3000/graphql', SHOW_FC, {schema_id: this.state.schemaID}).then(
  37. data => {
  38. request('http://123.206.193.98:3000/graphql', SEARCH_SCHEMA, {id: this.state.schemaID}).then(
  39. _data => {
  40. data.fc_by_props.length === 0 ?
  41. this.setState({
  42. show: true,
  43. schemaName: _data.schema_by_id.schemaName
  44. })
  45. :
  46. data.fc_by_props.forEach(cloud => {
  47. switch (cloud.cloud_id.cloudName) {
  48. case 'tencent':
  49. this.setState({
  50. tencentCloudID: cloud.cloud_id.id,
  51. show: true
  52. });
  53. break;
  54. case 'aliyun':
  55. this.setState({
  56. aliyunCloudID: cloud.cloud_id.id,
  57. show: true
  58. });
  59. break;
  60. case 'amazon':
  61. this.setState({
  62. amazonCloudID: cloud.cloud_id.id,
  63. show: true
  64. });
  65. break;
  66. default:
  67. break;
  68. }
  69. })
  70. }
  71. );
  72. }
  73. );
  74. }
  75. switchConfig = (label) => {
  76. return (e) => {
  77. this.setState({
  78. [label]: e.target.value
  79. })
  80. };
  81. };
  82. render() {
  83. const contentListNoTitle = {
  84. tencent: <TencentConfig cloudID={this.state.tencentCloudID} schemaName={this.state.schemaName}/>,
  85. aliyun: <AliConfig cloudID={this.state.aliyunCloudID} schemaName={this.state.schemaName}/>,
  86. amazon: <AmazonConfig cloudID={this.state.amazonCloudID} schemaName={this.state.schemaName}/>,
  87. };
  88. let userID = this.props.userID;
  89. return (
  90. <div>
  91. <div>
  92. <Card
  93. style={{width: '100%'}}
  94. tabList={tabListNoTitle}
  95. activeTabKey={this.state.cloud}
  96. onTabChange={(cloud) => {
  97. this.setState({
  98. cloud
  99. })
  100. }}
  101. >
  102. {
  103. this.state.show ?
  104. contentListNoTitle[this.state.cloud]
  105. :
  106. "waiting..."
  107. }
  108. </Card>
  109. </div>
  110. </div>
  111. )
  112. }
  113. }
  114. export default Deploy;