APIPathCardFetch.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React, {Component} from 'react';
  2. import {Collapse, Spin} from 'antd';
  3. import {GET_PROJECT, SHOW_APIGWPATH} from "../../../../../gql";
  4. import gql from "graphql-tag";
  5. import {Query} from "react-apollo";
  6. import APIPathCardRender from "./APIPathCardRender";
  7. import {removeSpace} from "../../../../../func";
  8. const Panel = Collapse.Panel;
  9. class APIPathCardFetch extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {}
  13. }
  14. render() {
  15. return (
  16. <Query query={gql(GET_PROJECT)} variables={{id: this.props.projectID}} fetchPolicy={'network-only'}>
  17. {
  18. ({loading, error, data}) => {
  19. if (loading) {
  20. return <Spin style={{marginLeft: 3}}/>
  21. }
  22. if (error) {
  23. return 'error!';
  24. }
  25. let group = '',
  26. deploy = '',
  27. path = '';
  28. let dataProject = data.project_by_id;
  29. let {cloud_id, apiGWGroup_id, deploy_id, projectName} = dataProject;
  30. if (cloud_id !== null && cloud_id.cloudName === 'tencent') {
  31. group = apiGWGroup_id;
  32. deploy = deploy_id;
  33. }
  34. return (
  35. <Query query={gql(SHOW_APIGWPATH)} variables={{apiGWGroup_id: group? group.id : ''}}>
  36. {
  37. ({loading, error, data}) => {
  38. if (loading) {
  39. return <Spin style={{marginLeft: 3}}/>
  40. }
  41. if (error) {
  42. return 'error!';
  43. }
  44. if (data.apiGWPath_by_props.length > 0)
  45. path = data.apiGWPath_by_props[0];
  46. return (
  47. <APIPathCardRender
  48. // props
  49. trialcase={this.props.trialcase}
  50. stepByStep={this.props.stepByStep}
  51. userID={this.props.userID}
  52. projectID={this.props.projectID}
  53. stepAllShow={this.props.stepAllShow}
  54. // query1
  55. deployID={deploy.id}
  56. groupID={group? group.id : ''}
  57. // query2
  58. defalutName={removeSpace(projectName)}
  59. path={path}
  60. />
  61. )
  62. }
  63. }
  64. </Query>
  65. )
  66. }
  67. }
  68. </Query>
  69. )
  70. }
  71. }
  72. export default APIPathCardFetch;