|
|
@@ -1,8 +1,14 @@
|
|
|
import React, {Component} from 'react';
|
|
|
-import {Input, Radio, Collapse, Button} from 'antd';
|
|
|
+import {Input, Radio, Collapse, Button, Icon} from 'antd';
|
|
|
+import {request} from 'graphql-request'
|
|
|
+import {ADD_APIGWPATH, UPDATE_APIGWPATH} from "../../../gql";
|
|
|
|
|
|
const Panel = Collapse.Panel;
|
|
|
|
|
|
+const idGen = (kind) => {
|
|
|
+ return kind + '_' + Date.now() + '_' + Math.random().toString().slice(-8);
|
|
|
+};
|
|
|
+
|
|
|
class APIPathCard extends Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
@@ -10,6 +16,7 @@ class APIPathCard extends Component {
|
|
|
props.path !== '' ?
|
|
|
this.state = {
|
|
|
configs: ['apiGWName', 'apiGWDesc'],
|
|
|
+ showOK: false,
|
|
|
apiGWName,
|
|
|
apiGWDesc,
|
|
|
requestMethod: requestMethod
|
|
|
@@ -17,6 +24,7 @@ class APIPathCard extends Component {
|
|
|
:
|
|
|
this.state = {
|
|
|
configs: ['apiGWName', 'apiGWDesc'],
|
|
|
+ showOK: false,
|
|
|
apiGWName: props.schemaName,
|
|
|
apiGWDesc: '',
|
|
|
requestMethod: 'GET'
|
|
|
@@ -25,15 +33,15 @@ class APIPathCard extends Component {
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(next) {
|
|
|
- if(next.path !== '') {
|
|
|
+ if (next.path !== '') {
|
|
|
let {apiGWName, apiGWDesc, requestMethod} = next.path;
|
|
|
- this.setState( {
|
|
|
+ this.setState({
|
|
|
apiGWName,
|
|
|
apiGWDesc,
|
|
|
requestMethod
|
|
|
})
|
|
|
} else {
|
|
|
- this.setState ( {
|
|
|
+ this.setState({
|
|
|
apiGWName: next.schemaName,
|
|
|
apiGWDesc: '',
|
|
|
requestMethod: 'GET'
|
|
|
@@ -49,6 +57,63 @@ class APIPathCard extends Component {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
+ ok = () => {
|
|
|
+ let {apiGWName, apiGWDesc, requestMethod} = this.state;
|
|
|
+ let varObj = {
|
|
|
+ id: idGen('path'),
|
|
|
+ user_id: this.props.userID,
|
|
|
+ apiGWGroup_id: this.props.groupID,
|
|
|
+ deploy_id: this.props.deployID,
|
|
|
+ apiGWName,
|
|
|
+ apiGWDesc,
|
|
|
+ requestMethod,
|
|
|
+ serviceType: 'SCF',
|
|
|
+ apiGWPath: '/graphql',
|
|
|
+ timeout: 300,
|
|
|
+ apiId: '',
|
|
|
+ createdAt: new Date().getTime(),
|
|
|
+ updatedAt: ''
|
|
|
+ };
|
|
|
+ if (this.props.path === '') {
|
|
|
+ request('http://123.206.193.98:3000/graphql', ADD_APIGWPATH, varObj).then(
|
|
|
+ data => {
|
|
|
+ if (data.create_apiGWPath !== null) {
|
|
|
+ this.setState({
|
|
|
+ showOK: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setTimeout(()=>{
|
|
|
+ this.setState({
|
|
|
+ showOK: false
|
|
|
+ })
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ let {apiGWName, apiGWDesc, requestMethod} = this.state;
|
|
|
+ let varObj = {
|
|
|
+ id: this.props.path.id,
|
|
|
+ apiGWName,
|
|
|
+ apiGWDesc,
|
|
|
+ requestMethod,
|
|
|
+ updatedAt: new Date().getTime()
|
|
|
+ };
|
|
|
+ request('http://123.206.193.98:3000/graphql', UPDATE_APIGWPATH, varObj).then(
|
|
|
+ data => {
|
|
|
+ if (data.update_apiGWPath !== null) {
|
|
|
+ this.setState({
|
|
|
+ showOK: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ setTimeout(()=>{
|
|
|
+ this.setState({
|
|
|
+ showOK: false
|
|
|
+ })
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
render() {
|
|
|
const customPanelStyle = {
|
|
|
@@ -74,7 +139,8 @@ class APIPathCard extends Component {
|
|
|
}
|
|
|
<div style={{marginBottom: 10}}>
|
|
|
<span className='vice-title'>requestMethod: </span>
|
|
|
- <Radio.Group onChange={this.switchConfig('requestMethod')} defaultValue={this.state.requestMethod}
|
|
|
+ <Radio.Group onChange={this.switchConfig('requestMethod')}
|
|
|
+ defaultValue={this.state.requestMethod}
|
|
|
buttonStyle="solid">
|
|
|
<Radio.Button value="GET">get</Radio.Button>
|
|
|
<Radio.Button value="POST">post</Radio.Button>
|
|
|
@@ -82,7 +148,13 @@ class APIPathCard extends Component {
|
|
|
</div>
|
|
|
</Panel>
|
|
|
</Collapse>
|
|
|
- <Button type='primary'>ok</Button>
|
|
|
+ <Button onClick={this.ok} type='primary'>ok</Button>
|
|
|
+ {
|
|
|
+ this.state.showOK === true?
|
|
|
+ <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
|
|
|
+ :
|
|
|
+ ''
|
|
|
+ }
|
|
|
</div>
|
|
|
)
|
|
|
}
|