import React, {Component} from 'react';
import {Input, Radio, Collapse, Button, Icon} from 'antd';
import {ADD_DEPLOY, UPDATE_DEPLOY} from "../../../../gql";
import {request} from 'graphql-request'
import {idGen} from "../../../../func";
import {graphqlUrl} from "../../../../config";
import {manageUsers} from "../../../../config";
const Panel = Collapse.Panel;
// 如需改变显示,请在此处 value 处更改
// 如需添加中文,请在此处 value 处添加
// eg: 'xxxx':
const valueToKey = {
'functionName': 'Name',
'cosBucketName': 'cosBucketName',
'cosObjectName': 'cosObjectName',
'cosBucketRegion': 'cosBucketRegion',
'serviceName': 'serviceName',
'subnetId': 'subnetId',
'vpcId': 'vpcId',
'region': 'region',
'description': 'description',
};
class DeployCard extends Component {
constructor(props) {
super(props);
let {functionName, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId, region, description} = props.deploy;
props.deploy !== '' ?
this.state = {
configs: ['description', 'cosBucketName', 'cosObjectName', 'vpcId', 'subnetId'],
description,
showOK: false,
functionName,
region,
cosBucketName,
cosObjectName,
cosBucketRegion,
serviceName,
vpcId,
subnetId
}
:
this.state = {
configs: ['description', 'cosBucketName', 'cosObjectName', 'vpcId', 'subnetId'],
description: '',
showOK: false,
functionName: props.defalutName,
region: props.region,
cosBucketName: 'graphqlfc',
cosObjectName: props.defalutName,
cosBucketRegion: props.region,
serviceName: '',
vpcId: '',
subnetId: '',
}
}
componentWillReceiveProps(next) {
if (next.deploy !== '') {
let {functionName, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId, region, description} = next.deploy;
this.setState({
description,
functionName,
region,
cosBucketName,
cosObjectName,
cosBucketRegion,
serviceName,
vpcId,
subnetId
})
} else {
this.setState({
functionName: next.defalutName,
region: next.region,
cosBucketName: 'graphqlfc',
cosObjectName: next.defalutName,
cosBucketRegion: next.region,
serviceName: '',
vpcId: '',
subnetId: ''
});
}
};
switchConfig = (label) => {
return (e) => {
this.setState({
[label]: e.target.value
})
};
};
ok = (id) => {
let {description, cosBucketName, subnetId, cosObjectName, region, vpcId, cosBucketRegion, functionName} = this.state;
let varObj = {
id,
cloud_id: this.props.cloudID,
user_id: this.props.userID,
description,
cosBucketName,
subnetId,
cosObjectName,
region,
vpcId,
cosBucketRegion,
functionName,
memorySize: 512,
timeout: 300,
handler: 'tencent_graphql.Bridge::handler',
serviceName: "",
fc_id: '',
createdAt: new Date().getTime(),
updatedAt: ''
};
if (this.props.deploy === '') {
request(graphqlUrl, ADD_DEPLOY, varObj).then(
data => {
if (data.create_deploy !== null) {
this.setState({
showOK: true
})
}
setTimeout(() => {
this.setState({
showOK: false
})
}, 1500)
}
)
} else {
let {description, cosBucketName, subnetId, cosObjectName, region, vpcId, cosBucketRegion, functionName} = this.state;
let varObj = {
id: this.props.deploy.id,
description,
subnetId,
cosBucketName,
cosObjectName,
region,
vpcId,
cosBucketRegion,
functionName,
updatedAt: new Date().getTime()
};
request(graphqlUrl, UPDATE_DEPLOY, varObj).then(
data => {
if (data.update_deploy !== 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 (
{valueToKey['functionName']}:
{valueToKey['region']}:
{
this.props.switchRegion(e);
this.setState({
region: e.target.value
})
}} defaultValue={this.state.region} buttonStyle="solid">
Guangzhou
Shanghai
Beijing
Chengdu
{valueToKey['cosBucketRegion']}:
Guangzhou
Shanghai
Beijing
Chengdu
{valueToKey['serviceName']}:
{
this.state.configs.map(config => (
{valueToKey[config]}:
))
}
{
manageUsers.includes(this.props.userID) ?
{
this.state.showOK === true ?
:
''
}
:
this.props.trialcase ?
''
:
{
this.state.showOK === true ?
:
''
}
}
)
}
}
export default DeployCard;