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; const valueToKey = { 'functionName': '', 'cosBucketName': '', 'cosObjectName': '', 'cosBucketRegion': '', 'serviceName': '', 'subnetId': '', 'vpcId': '', 'region': '', '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: props.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 (
functionName:
region: { this.props.switchRegion(e); this.setState({ region: e.target.value }) }} defaultValue={this.state.region} buttonStyle="solid"> Guangzhou Shanghai Beijing Chengdu
cosBucketRegion: Guangzhou Shanghai Beijing Chengdu
serviceName:
{ this.state.configs.map(config => (
{config}:
)) }
{ manageUsers.includes(this.props.userID) ?
{ this.state.showOK === true ? : '' }
: this.props.trialcase ? '' :
{ this.state.showOK === true ? : '' }
}
) } } export default DeployCard;