TencentConfig.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. import React, {Component} from 'react';
  2. import {Row, Col, Card, Button, Spin, Alert, Steps, Progress} from 'antd';
  3. import axios from 'axios';
  4. import APIGroupCardFetch from './apiGroupCard/APIGroupCardFetch';
  5. import APIPathCardFetch from './apiPathCard/APIPathCardFetch';
  6. import DeployCardFetch from './deployCard/DeployCardFetch';
  7. import NotificationCardFetch from './notificationCard/NotificationCardFetch';
  8. import {GET_PROJECT, SHOW_APIGWPATH, UPDATE_PROJECT_ONLY_STATUS} from "../../../../gql";
  9. import {deployUrl, graphqlUrl} from "../../../../config";
  10. import {FormattedMessage} from 'react-intl';
  11. import {request} from 'graphql-request'
  12. const Step = Steps.Step;
  13. class TencentConfig extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. region: '',
  18. couldDeploy: false,
  19. deployIdPassToPath: '',
  20. groupIdPassToPath: '',
  21. pathIdPassToConfig: '',
  22. currentStep: '',
  23. stepAllShow: false,
  24. deploying: '',
  25. stepUpdated: false,
  26. };
  27. }
  28. componentWillMount() {
  29. let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
  30. request(graphqlUrl, GET_PROJECT, {id: projectID}).then(
  31. data => {
  32. let dataProject = data.project_by_id;
  33. if (dataProject !== null) {
  34. this.setState({
  35. schemaState: dataProject.schema_id? dataProject.schema_id.schemaState : '',
  36. projectType: dataProject.projectType
  37. });
  38. switch (dataProject.projectStatus) {
  39. case 'deployed':
  40. this.setState({
  41. currentStep: 5,
  42. stepAllShow: true,
  43. deploying: 'finished'
  44. });
  45. break;
  46. case 'notificationed':
  47. this.setState({
  48. currentStep: 4
  49. });
  50. break;
  51. case 'pathed':
  52. this.setState({
  53. currentStep: 3
  54. });
  55. break;
  56. case 'grouped':
  57. this.setState({
  58. currentStep: 2
  59. });
  60. break;
  61. case 'functioned':
  62. this.setState({
  63. currentStep: 1
  64. });
  65. break;
  66. case 'created':
  67. this.setState({
  68. currentStep: 0
  69. });
  70. break;
  71. case 'updated':
  72. this.setState({
  73. stepUpdated: true,
  74. stepAllShow: true,
  75. });
  76. break;
  77. case 'deploying':
  78. this.setState({
  79. deploying: 'deploying'
  80. });
  81. break;
  82. default:
  83. this.setState({
  84. currentStep: 0
  85. });
  86. break;
  87. }
  88. } else {
  89. console.log('project 没存 status');
  90. }
  91. }
  92. )
  93. }
  94. componentWillReceiveProps(next) {
  95. this.setState({
  96. couldDeploy: false,
  97. region: '',
  98. deployIdPassToPath: '',
  99. groupIdPassToPath: '',
  100. currentStep: '',
  101. deploying: '',
  102. stepAllShow: false,
  103. stepUpdated: false
  104. });
  105. let projectID = next.projectID ? next.projectID : 'ecommerce_projectID';
  106. request(graphqlUrl, GET_PROJECT, {id: projectID}).then(
  107. data => {
  108. let dataProject = data.project_by_id;
  109. if (dataProject !== null) {
  110. this.setState({
  111. schemaState: dataProject.schema_id? dataProject.schema_id.schemaState : '',
  112. projectType: dataProject.projectType
  113. });
  114. switch (dataProject.projectStatus) {
  115. case 'deployed':
  116. this.setState({
  117. deploying: 'finished',
  118. currentStep: 5,
  119. stepAllShow: true
  120. });
  121. break;
  122. case 'notificationed':
  123. this.setState({
  124. currentStep: 4
  125. });
  126. break;
  127. case 'pathed':
  128. this.setState({
  129. currentStep: 3
  130. });
  131. break;
  132. case 'grouped':
  133. this.setState({
  134. currentStep: 2
  135. });
  136. break;
  137. case 'functioned':
  138. this.setState({
  139. currentStep: 1
  140. });
  141. break;
  142. case 'created':
  143. this.setState({
  144. currentStep: 0
  145. });
  146. break;
  147. case 'updated':
  148. this.setState({
  149. stepUpdated: true,
  150. stepAllShow: true,
  151. });
  152. break;
  153. case 'deploying':
  154. this.setState({
  155. deploying: 'deploying'
  156. });
  157. break;
  158. default:
  159. this.setState({
  160. currentStep: 0
  161. });
  162. break;
  163. }
  164. } else {
  165. console.log('project 没存 status');
  166. }
  167. }
  168. )
  169. }
  170. switchRegion = (e) => {
  171. this.setState({
  172. region: e.target.value
  173. });
  174. };
  175. deployFC = () => {
  176. request(graphqlUrl, GET_PROJECT, {id: this.props.projectID}).then(
  177. data => {
  178. let dataProject = data.project_by_id;
  179. if (dataProject !== null) {
  180. let schema = dataProject.schema_id.id;
  181. let deploy = dataProject.deploy_id.id;
  182. let group = dataProject.apiGWGroup_id.id;
  183. request(graphqlUrl, SHOW_APIGWPATH, {apiGWGroup_id: group}).then(
  184. data => {
  185. if(data.apiGWPath_by_props !== null) {
  186. // 给 project 加 deploying 状态
  187. request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
  188. id: this.props.projectID,
  189. updatedAt: new Date().getTime(),
  190. projectStatus: 'deploying'
  191. });
  192. console.log(data);
  193. let api = data.apiGWPath_by_props[0].id;
  194. console.log('schema', schema);
  195. console.log('deploy', deploy);
  196. console.log('api', api);
  197. console.log('group', group);
  198. if (schema && deploy && api && group) {
  199. console.log('deploying');
  200. this.setState({
  201. deploying: 'deploying'
  202. });
  203. axios.get(`${deployUrl}`,
  204. {
  205. params: {
  206. 'cloud-id': 'tencent_CloudID',
  207. 'cloud-name': 'tencent',
  208. schema,
  209. deploy,
  210. api,
  211. group
  212. }
  213. })
  214. .then((res) => {
  215. console.log('deploy res', res);
  216. this.setState({
  217. deploying: 'finished'
  218. });
  219. // 给 project 加 deployed 状态
  220. request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
  221. id: this.props.projectID,
  222. updatedAt: new Date().getTime(),
  223. projectStatus: 'deployed'
  224. })
  225. })
  226. .catch((err) => {
  227. this.setState({
  228. deploying: 'error'
  229. });
  230. // 给 project 加 error 状态
  231. request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
  232. id: this.props.projectID,
  233. updatedAt: new Date().getTime(),
  234. projectStatus: 'error'
  235. });
  236. console.log('err', err);
  237. console.log('err.response', err.response);
  238. console.log('err.response.data', err.response.data);
  239. });
  240. }
  241. } else {
  242. console.log('path 没存');
  243. }
  244. }
  245. );
  246. } else {
  247. console.log('project 没存 status');
  248. }
  249. }
  250. );
  251. };
  252. stepByStep = (stepNum) => {
  253. this.setState({
  254. currentStep: stepNum
  255. })
  256. };
  257. stepStatus = (value) => {
  258. if (this.state.currentStep === value)
  259. return '进行中';
  260. else if (this.state.currentStep > value)
  261. return '完成';
  262. else
  263. return '等待';
  264. };
  265. render() {
  266. let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
  267. return (
  268. <div>
  269. {
  270. this.state.projectType === 'graphql' ?
  271. this.state.schemaState === 'ok' ?
  272. ''
  273. :
  274. this.props.trialcase ?
  275. ''
  276. :
  277. <div style={{marginBottom: 10}}>
  278. <Alert message="数据表结构不符合规范,暂不能部署,请修改" type="warning"
  279. banner closable/>
  280. </div>
  281. :
  282. ''
  283. }
  284. {
  285. this.state.stepUpdated ?
  286. this.props.trialcase ?
  287. ''
  288. :
  289. <div style={{marginBottom: 10}}>
  290. <Alert message="进行了一次修改,未能确认是否完成" type="warning"
  291. banner closable/>
  292. </div>
  293. :
  294. ''
  295. }
  296. <div style={{padding: '30px'}}>
  297. <Row gutter={16}>
  298. <Col span={14}>
  299. {
  300. this.state.currentStep !== '' || this.state.deploying === 'deploying' || this.state.deploying === 'deployed'?
  301. <Steps current={this.state.deploying !== 'deploying' ? this.state.currentStep : 4} style={{marginBottom: 30}}>
  302. <Step title={this.stepStatus(0)} description="云函数配置"/>
  303. <Step title={this.stepStatus(1)} description="服务配置"/>
  304. <Step title={this.stepStatus(2)} description="API 配置"/>
  305. <Step title={this.stepStatus(3)} description="通知配置"/>
  306. </Steps>
  307. :
  308. ''
  309. }
  310. {
  311. this.state.currentStep === 0 || this.state.stepAllShow ?
  312. <FormattedMessage id="fc Deploy">
  313. {
  314. msg =>
  315. <Card title={msg} style={{marginBottom: 10}}>
  316. <DeployCardFetch
  317. switchRegion={this.switchRegion}
  318. region={this.state.region}
  319. trialcase={this.props.trialcase}
  320. stepByStep={this.stepByStep}
  321. userID={this.props.userID}
  322. projectID={projectID}
  323. />
  324. </Card>
  325. }
  326. </FormattedMessage>
  327. :
  328. ''
  329. }
  330. {
  331. this.state.currentStep === 1 || this.state.stepAllShow ?
  332. <FormattedMessage id="API Group">
  333. {
  334. msg =>
  335. <Card title={msg} style={{marginBottom: 10}}>
  336. <APIGroupCardFetch
  337. switchRegion={this.switchRegion}
  338. region={this.state.region}
  339. trialcase={this.props.trialcase}
  340. stepByStep={this.stepByStep}
  341. userID={this.props.userID}
  342. projectID={projectID}
  343. stepAllShow={this.state.stepAllShow}
  344. />
  345. </Card>
  346. }
  347. </FormattedMessage>
  348. :
  349. ''
  350. }
  351. {
  352. this.state.currentStep === 2 || this.state.stepAllShow ?
  353. <FormattedMessage id="API Path">
  354. {
  355. msg =>
  356. <Card title={msg} style={{marginBottom: 10}}>
  357. <APIPathCardFetch
  358. trialcase={this.props.trialcase}
  359. stepByStep={this.stepByStep}
  360. userID={this.props.userID}
  361. projectID={projectID}
  362. stepAllShow={this.state.stepAllShow}
  363. />
  364. </Card>
  365. }
  366. </FormattedMessage>
  367. :
  368. ''
  369. }
  370. {
  371. this.state.currentStep === 3 || this.state.stepAllShow ?
  372. <FormattedMessage id="Notification">
  373. {
  374. msg =>
  375. <Card title={msg}>
  376. <NotificationCardFetch
  377. userID={this.props.userID}
  378. trialcase={this.props.trialcase}
  379. stepByStep={this.stepByStep}
  380. projectID={projectID}
  381. stepAllShow={this.state.stepAllShow}
  382. />
  383. </Card>
  384. }
  385. </FormattedMessage>
  386. :
  387. ''
  388. }
  389. </Col>
  390. {
  391. this.state.currentStep === 4 || this.state.stepAllShow ?
  392. <Col offset={2} span={6}>
  393. {
  394. this.props.trialcase ?
  395. ''
  396. :
  397. this.state.projectType === 'graphql' ?
  398. this.state.schemaState === 'ok' ?
  399. this.state.deploying === '' ?
  400. <Button type='primary' onClick={this.deployFC}><FormattedMessage id="deploy"/>!</Button>
  401. :
  402. ''
  403. :
  404. <Button type='primary'
  405. disabled><FormattedMessage
  406. id="deploy"/>!</Button>
  407. :
  408. <Button type='primary' onClick={() => {
  409. }}><FormattedMessage id="deploy"/>!</Button>
  410. }
  411. </Col>
  412. :
  413. ''
  414. }
  415. {
  416. this.state.deploying === 'deploying' ?
  417. <Spin size="large"/>
  418. :
  419. this.state.deploying === 'finished' ?
  420. <Progress type="circle" percent={100}/>
  421. :
  422. this.state.deploying === 'error' ?
  423. <Progress type="circle" percent={99}
  424. status="exception"/>
  425. :
  426. ''
  427. }
  428. </Row>
  429. </div>
  430. </div>
  431. );
  432. }
  433. }
  434. export default TencentConfig;