| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import React, {Component} from 'react';
- import {Input, Radio, Collapse, Button, Icon} from 'antd';
- import {request} from 'graphql-request'
- import {ADD_APIGWPATH, UPDATE_APIGWPATH} from "../../../../gql";
- import {idGen} from "../../../../func";
- import {graphqlUrl} from "../../../../config";
- import {manageUsers} from "../../../../config";
- const Panel = Collapse.Panel;
- // 如需改变显示,请在此处 value 处更改
- // 如需添加中文,请在此处 value 处添加
- // eg: 'xxxx': <F.. id='xxx'/>
- const valueToKey = {
- 'apiGWName': 'Name',
- 'apiGWDesc': 'Description',
- 'requestMethod': 'Method'
- };
- class APIPathCard extends Component {
- constructor(props) {
- super(props);
- let {apiGWName, apiGWDesc, requestMethod} = props.path;
- props.path !== '' ?
- this.state = {
- configs: ['apiGWName', 'apiGWDesc'],
- showOK: false,
- apiGWName,
- apiGWDesc,
- requestMethod: requestMethod
- }
- :
- this.state = {
- configs: ['apiGWName', 'apiGWDesc'],
- showOK: false,
- apiGWName: props.defalutName,
- apiGWDesc: '',
- requestMethod: 'GET'
- };
- }
- componentWillReceiveProps(next) {
- if (next.path !== '') {
- let {apiGWName, apiGWDesc, requestMethod} = next.path;
- this.setState({
- apiGWName,
- apiGWDesc,
- requestMethod
- })
- } else {
- this.setState({
- apiGWName: next.defalutName,
- apiGWDesc: '',
- requestMethod: 'GET'
- });
- }
- };
- switchConfig = (label) => {
- return (e) => {
- this.setState({
- [label]: e.target.value
- })
- };
- };
- 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 === '') {
- if(this.props.deployID !== '' && this.props.groupID!=='') {
- request(graphqlUrl, 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(graphqlUrl, UPDATE_APIGWPATH, varObj).then(
- data => {
- if (data.update_apiGWPath !== null) {
- this.setState({
- showOK: true
- })
- }
- setTimeout(()=>{
- this.setState({
- showOK: false
- })
- }, 1500)
- }
- )
- }
- };
- render() {
- const customPanelStyle = {
- background: '#f7f7f7',
- borderRadius: 4,
- marginBottom: 24,
- border: 0,
- overflow: 'hidden',
- };
- return (
- <div>
- <Collapse bordered={false}>
- <Panel header="Want more options?" style={customPanelStyle}>
- {
- this.state.configs.map(config => (
- <div key={config} style={{marginBottom: 10}}>
- <span className='vice-title'>{valueToKey[config]}: </span>
- <Input value={this.state[config]} style={{width: 200}}
- onChange={this.switchConfig(config)}/>
- </div>
- ))
- }
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>{valueToKey['requestMethod']}: </span>
- <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>
- </Radio.Group>
- </div>
- </Panel>
- </Collapse>
- {
- manageUsers.includes(this.props.userID) ?
- <div>
- <Button onClick={this.ok} type='primary'>save</Button>
- {
- this.state.showOK === true?
- <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
- :
- ''
- }
- </div>
- :
- this.props.trialcase?
- ''
- :
- <div>
- <Button onClick={this.ok} type='primary'>save</Button>
- {
- this.state.showOK === true?
- <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
- :
- ''
- }
- </div>
- }
- </div>
- )
- }
- }
- export default APIPathCard;
|