TencentConfig.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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-name': 'tencent',
  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. />
  169. </Card>
  170. }
  171. </FormattedMessage>
  172. <FormattedMessage id="API Group">
  173. {
  174. msg =>
  175. <Card title={msg} style={{marginBottom: 10}}>
  176. <APIGroupCard
  177. group={group}
  178. userID={this.props.userID}
  179. switchRegion={this.switchRegion}
  180. region={this.state.region}
  181. cloudID={cloudID}
  182. trialcase={this.props.trialcase}
  183. pass={this.pass}
  184. />
  185. </Card>
  186. }
  187. </FormattedMessage>
  188. <Query query={gql(SHOW_APIGWPATH)}
  189. variables={{apiGWGroup_id: apiGWGroup_id ? apiGWGroup_id.id : ''}}>
  190. {
  191. ({loading, error, data}) => {
  192. if (loading) {
  193. return <Spin style={{marginLeft: 3}}/>
  194. }
  195. if (error) {
  196. return 'error!';
  197. }
  198. if (data.apiGWPath_by_props.length > 0)
  199. path = data.apiGWPath_by_props[0];
  200. return (
  201. <FormattedMessage id="API Path">
  202. {
  203. msg =>
  204. <Card title={msg}
  205. style={{marginBottom: 10}}>
  206. <APIPathCard
  207. path={path}
  208. defalutName={defaultName}
  209. userID={this.props.userID}
  210. trialcase={this.props.trialcase}
  211. deployID={deploy ? deploy.id : this.state.deployIdPassToPath}
  212. groupID={group ? group.id : this.state.groupIdPassToPath}
  213. pass={this.pass}
  214. />
  215. </Card>
  216. }
  217. </FormattedMessage>
  218. )
  219. }
  220. }
  221. </Query>
  222. <FormattedMessage id="Notification">
  223. {
  224. msg =>
  225. <Card title={msg}>
  226. <NotificationCard
  227. userID={this.props.userID}
  228. defalutName={defaultName}
  229. trialcase={this.props.trialcase}
  230. />
  231. </Card>
  232. }
  233. </FormattedMessage>
  234. </Col>
  235. <Col offset={2} span={6}>
  236. {
  237. this.props.trialcase ?
  238. ''
  239. :
  240. projectType === 'graphql' ?
  241. schema_id.schemaState === 'ok' ?
  242. <Button type='primary'
  243. onClick={() => this.deployFC(schemaID, deploy ? deploy.id : this.state.deployIdPassToPath, this.state.pathIdPassToConfig, group ? group.id : this.state.groupIdPassToPath)}><FormattedMessage
  244. id="deploy"/>!</Button>
  245. :
  246. <Button type='primary' disabled><FormattedMessage
  247. id="deploy"/>!</Button>
  248. :
  249. <Button type='primary' onClick={() => {
  250. }}><FormattedMessage id="deploy"/>!</Button>
  251. }
  252. </Col>
  253. </Row>
  254. </div>
  255. </div>
  256. )
  257. } else {
  258. return (
  259. <div>
  260. {
  261. projectType === 'graphql' ?
  262. schema_id.schemaState === 'ok' ?
  263. ''
  264. :
  265. this.props.trialcase ?
  266. ''
  267. :
  268. <div style={{marginBottom: 10}}>
  269. <Alert message="数据表结构不符合规范,暂不能部署,请修改" type="warning"
  270. banner closable/>
  271. </div>
  272. :
  273. ''
  274. }
  275. <div style={{padding: '30px'}}>
  276. <Row gutter={16}>
  277. <Col span={14}>
  278. <Steps current={this.state.currentStep} style={{marginBottom: 30}}>
  279. <Step title={this.stepStatus(0)} description="云函数配置"/>
  280. <Step title={this.stepStatus(1)} description="服务配置"/>
  281. <Step title={this.stepStatus(2)} description="API 配置"/>
  282. <Step title={this.stepStatus(3)} description="通知配置"/>
  283. </Steps>
  284. {
  285. this.state.currentStep === 0 ?
  286. <FormattedMessage id="fc Deploy">
  287. {
  288. msg =>
  289. <Card title={msg} style={{marginBottom: 10}}>
  290. <DeployCard
  291. deploy={deploy}
  292. switchRegion={this.switchRegion}
  293. region={this.state.region}
  294. defalutName={defaultName}
  295. userID={this.props.userID}
  296. cloudID={cloudID}
  297. trialcase={this.props.trialcase}
  298. pass={this.pass}
  299. stepByStep={this.stepByStep}
  300. />
  301. </Card>
  302. }
  303. </FormattedMessage>
  304. :
  305. ''
  306. }
  307. {
  308. this.state.currentStep === 1 ?
  309. <FormattedMessage id="API Group">
  310. {
  311. msg =>
  312. <Card title={msg} style={{marginBottom: 10}}>
  313. <APIGroupCard
  314. group={group}
  315. userID={this.props.userID}
  316. switchRegion={this.switchRegion}
  317. region={this.state.region}
  318. cloudID={cloudID}
  319. trialcase={this.props.trialcase}
  320. pass={this.pass}
  321. stepByStep={this.stepByStep}
  322. />
  323. </Card>
  324. }
  325. </FormattedMessage>
  326. :
  327. ''
  328. }
  329. {
  330. this.state.currentStep === 2 ?
  331. <Query query={gql(SHOW_APIGWPATH)}
  332. variables={{apiGWGroup_id: apiGWGroup_id ? apiGWGroup_id.id : ''}}>
  333. {
  334. ({loading, error, data}) => {
  335. if (loading) {
  336. return <Spin style={{marginLeft: 3}}/>
  337. }
  338. if (error) {
  339. return 'error!';
  340. }
  341. if (data.apiGWPath_by_props.length > 0)
  342. path = data.apiGWPath_by_props[0];
  343. return (
  344. <FormattedMessage id="API Path">
  345. {
  346. msg =>
  347. <Card title={msg}
  348. style={{marginBottom: 10}}>
  349. <APIPathCard
  350. path={path}
  351. defalutName={defaultName}
  352. userID={this.props.userID}
  353. trialcase={this.props.trialcase}
  354. deployID={deploy ? deploy.id : this.state.deployIdPassToPath}
  355. groupID={group ? group.id : this.state.groupIdPassToPath}
  356. pass={this.pass}
  357. stepByStep={this.stepByStep}
  358. />
  359. </Card>
  360. }
  361. </FormattedMessage>
  362. )
  363. }
  364. }
  365. </Query>
  366. :
  367. ''
  368. }
  369. {
  370. this.state.currentStep === 3 ?
  371. <FormattedMessage id="Notification">
  372. {
  373. msg =>
  374. <Card title={msg}>
  375. <NotificationCard
  376. userID={this.props.userID}
  377. defalutName={defaultName}
  378. trialcase={this.props.trialcase}
  379. stepByStep={this.stepByStep}
  380. />
  381. </Card>
  382. }
  383. </FormattedMessage>
  384. :
  385. ''
  386. }
  387. </Col>
  388. {
  389. this.state.currentStep === 4 ?
  390. <Col offset={2} span={6}>
  391. {
  392. this.props.trialcase ?
  393. ''
  394. :
  395. projectType === 'graphql' ?
  396. schema_id.schemaState === 'ok' ?
  397. <Button type='primary'
  398. onClick={() => this.deployFC(schemaID, deploy ? deploy.id : this.state.deployIdPassToPath, this.state.pathIdPassToConfig, group ? group.id : this.state.groupIdPassToPath)}><FormattedMessage
  399. id="deploy"/>!</Button>
  400. :
  401. <Button type='primary'
  402. disabled><FormattedMessage id="deploy"/>!</Button>
  403. :
  404. <Button type='primary' onClick={() => {
  405. }}><FormattedMessage id="deploy"/>!</Button>
  406. }
  407. </Col>
  408. :
  409. ''
  410. }
  411. </Row>
  412. </div>
  413. </div>
  414. )
  415. }
  416. }
  417. }
  418. </Query>
  419. )
  420. }
  421. }
  422. export default TencentConfig;