import React, {Component} from 'react'; import {Row, Col, Card, Button} from 'antd'; import APIGroupCard from './APIGroupCard'; import APIPathCard from './APIPathCard'; import DeployCard from './DeployCard'; import NotificationCard from './NotificationCard'; import {SHOW_DEPLOY, SHOW_APIGWGROUP, SHOW_APIGWPATH} from "../../../gql"; import {request} from 'graphql-request' class TencentConfig extends Component { constructor(props) { super(props); this.state = { region: 'beijing', deploys: [], currentDeploy: '', groups: [], currentGroup: '', paths: [], currentPath: '', deployIdPassToPath: '', groupIdPassToPath: '', cloudID: props.cloudID, fc: props.fc }; this.fetch(); } componentWillReceiveProps(next) { this.setState({ fc: next.fc, cloudID: next.cloudID }, this.fetch); } fetch = () => { // todo: 没做每个 deploy 和 apigroup 和 apipath 的切换 // todo: 换成 apollo 会更好 if (this.state.fc === true) { request('http://123.206.193.98:3000/graphql', SHOW_DEPLOY, {cloud_id: this.state.cloudID}).then( data => { this.setState({ deploys: data.deploy_by_props, currentDeploy: data.deploy_by_props[0] }) } ); request('http://123.206.193.98:3000/graphql', SHOW_APIGWGROUP, {cloud_id: this.state.cloudID}).then( data => { this.setState({ groups: data.apiGWGroup_by_props, currentGroup: data.apiGWGroup_by_props[0] }, () => { request('http://123.206.193.98:3000/graphql', SHOW_APIGWPATH, {apiGWGroup_id: this.state.currentGroup.id}).then( data => { this.setState({ paths: data.apiGWPath_by_props, currentPath: data.apiGWPath_by_props[0] }); } ); }); } ); } else { this.setState({ currentDeploy: '', currentGroup: '', currentPath: '', }) } }; pass = (value, kind) => { if(kind === 'deploy') this.setState({ deployIdPassToPath: value }); else this.setState({ groupIdPassToPath: value }) }; switchRegion = (e) => { this.setState({ region: e.target.value }); }; render() { return (
) } } export default TencentConfig;