TencentConfig.js 28 KB

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