| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- import React, {Component} from 'react';
- import {Input, Collapse, Button, Radio, Icon} from 'antd';
- import {ADD_APIGROUP, UPDATE_APIGROUP} from "../../../../gql";
- import {request} from 'graphql-request'
- import {idGen} from "../../../../func";
- const Panel = Collapse.Panel;
- class APIGroupCard extends Component {
- constructor(props) {
- super(props);
- let {groupName, environmentName, defaultDomain, frontType, userDomain, userStatus, region} = props.group;
- props.group !== '' ?
- this.state = {
- showOK: false,
- groupName,
- environmentName,
- defaultDomain,
- frontType,
- userDomain,
- userStatus,
- groupRegion: region
- }
- :
- this.state = {
- showOK: false,
- groupName: 'graphql-endpoint',
- environmentName: 'test',
- defaultDomain: '',
- frontType: 'http&https',
- userDomain: '',
- userStatus: 'open',
- groupRegion: props.region
- };
- }
- componentWillReceiveProps(next) {
- if(next.group !== '') {
- let {groupName, environmentName, defaultDomain, frontType, userDomain, userStatus, region} = next.group;
- this.setState( {
- groupName,
- environmentName,
- defaultDomain,
- frontType,
- userDomain,
- userStatus,
- groupRegion: region
- })
- } else {
- this.setState ( {
- groupName: 'graphql-endpoint',
- environmentName: 'test',
- defaultDomain: '',
- frontType: 'http&https',
- userDomain: '',
- userStatus: 'open',
- groupRegion: next.region
- });
- }
- };
- switchConfig = (label) => {
- return (e) => {
- this.setState({
- [label]: e.target.value
- })
- };
- };
- ok = (id) => {
- let {userStatus, userDomain, groupName, frontType, environmentName} = this.state;
- let varObj = {
- id,
- cloud_id: this.props.cloudID,
- user_id: this.props.userID,
- userStatus,
- userDomain,
- groupName,
- frontType,
- region: this.state.groupRegion,
- environmentName,
- defaultDomain: '',
- status: '',
- serviceId: '',
- createdAt: new Date().getTime(),
- updatedAt: ''
- };
- if (this.props.group === '') {
- request('http://123.206.193.98:3000/graphql', ADD_APIGROUP, varObj).then(
- data => {
- if (data.create_apiGWGroup !== null) {
- this.setState({
- showOK: true
- })
- }
- setTimeout(()=>{
- this.setState({
- showOK: false
- })
- }, 1500)
- }
- )
- } else {
- let {userStatus, userDomain, groupName, frontType, environmentName} = this.state;
- let varObj = {
- id: this.props.group.id,
- userStatus,
- userDomain,
- groupName,
- frontType,
- region: this.state.groupRegion,
- environmentName,
- updatedAt: new Date().getTime()
- };
- request('http://123.206.193.98:3000/graphql', UPDATE_APIGROUP, varObj).then(
- data => {
- if (data.update_apiGWGroup !== 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}>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>groupName: </span>
- <Input value={this.state.groupName} style={{width: 400}}
- onChange={this.switchConfig('groupName')}/>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>region: </span>
- <Radio.Group onChange={this.switchConfig('groupRegion')} value={this.state.groupRegion} buttonStyle="solid">
- <Radio.Button value="guangzhou">Guangzhou</Radio.Button>
- <Radio.Button value="shanghai">Shanghai</Radio.Button>
- <Radio.Button value="beijing">Beijing</Radio.Button>
- <Radio.Button value="chengdu">Chengdu</Radio.Button>
- </Radio.Group>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>frontType: </span>
- <Radio.Group onChange={this.switchConfig('frontType')} defaultValue={this.state.frontType}
- buttonStyle="solid">
- <Radio.Button value="http">http</Radio.Button>
- <Radio.Button value="https">https</Radio.Button>
- <Radio.Button value="http&https">http&https</Radio.Button>
- </Radio.Group>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>defaultDomain: </span>
- <Input value={this.state.defaultDomain} style={{width: 400}} disabled/>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>environmentName: </span>
- <Radio.Group onChange={this.switchConfig('environmentName')} defaultValue={this.state.environmentName}
- buttonStyle="solid">
- <Radio.Button value="test">test</Radio.Button>
- <Radio.Button value="prepub">prepub</Radio.Button>
- <Radio.Button value="release">release</Radio.Button>
- </Radio.Group>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>userDomain: </span>
- <Input value={this.state.userDomain} style={{width: 400}}
- onChange={this.switchConfig('userDomain')}/>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>userStatus: </span>
- <Radio.Group onChange={this.switchConfig('userStatus')} defaultValue={this.state.userStatus}
- buttonStyle="solid">
- <Radio.Button value="open">open</Radio.Button>
- <Radio.Button value="close">close</Radio.Button>
- </Radio.Group>
- </div>
- </Panel>
- </Collapse>
- <Button onClick={()=>{
- const id = idGen('group');
- this.ok(id);
- this.props.pass(id, 'group');
- }} type='primary'>ok</Button>
- {
- this.state.showOK === true?
- <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
- :
- ''
- }
- </div>
- )
- }
- }
- export default APIGroupCard;
|