import React, {Component} from 'react'; import {Input, Radio, Collapse, Button, Icon, Tooltip} 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', }; const toolTipTitle = { 'functionName': 'its funcname', 'cosBucketName': 'its cosBucketName', 'cosObjectName': 'its cosObjectName', 'cosBucketRegion': 'its cosBucketRegion', 'serviceName': 'its serviceName', 'subnetId': 'its subnetId', 'vpcId': 'its vpcId', 'region': 'its region', 'description': 'its description', }; const removePrefix = (prefix, value) => { let r = new RegExp(prefix); return value.replace(r, ''); }; const shiftPrefix = (prefix, value) => { value = removePrefix(prefix, value); return prefix + value; }; 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: ['cosBucketName', 'cosObjectName', 'description', 'vpcId', 'subnetId'], description, showOK: false, functionName, region, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId } : this.state = { configs: ['cosBucketName', 'cosObjectName', 'description', '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: next.region === '' ? region : next.region, cosBucketName, cosObjectName, cosBucketRegion: next.region === '' ? cosBucketRegion : next.region, serviceName, vpcId, subnetId }) } else { this.setState({ functionName: next.defalutName, region: next.region === '' ? 'ap-beijing' : next.region, cosBucketName: 'graphqlfc', cosObjectName: next.defalutName, cosBucketRegion: next.region === '' ? 'ap-beijing' : 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; region = shiftPrefix('ap-', region); cosBucketRegion = shiftPrefix('ap-', cosBucketRegion); 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; region = shiftPrefix('ap-', region); cosBucketRegion = shiftPrefix('ap-', cosBucketRegion); 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', }; const ioobotCloudID = ['tencent_CloudID', 'aliyun_CloudID']; const disable = { 'subnetId': ioobotCloudID.includes(this.props.cloudID) ? true : '', 'vpcId': ioobotCloudID.includes(this.props.cloudID) ? true : '', }; return (
{valueToKey['functionName']}
{valueToKey['region']} { this.props.switchRegion(e); }} defaultValue={this.state.region} value={removePrefix('ap-', this.state.region)} buttonStyle="solid"> Guangzhou Shanghai Beijing Chengdu
{valueToKey['cosBucketRegion']} { // 如果不想一变所有都变,就将 onchange 改成 // onChange={this.switchConfig('cosBucketRegion')} this.props.switchRegion(e); }} defaultValue={this.state.region} value={removePrefix('ap-', this.state.cosBucketRegion)} buttonStyle="solid"> 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;