| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- import React, {Component} from 'react';
- import {FormattedMessage} from 'react-intl';
- import {Input, Radio, Collapse, Button, Icon, Tooltip} from 'antd';
- import {idGen} from "../../../../../../func";
- import {graphqlUrl, manageUsers} from "../../../../../../config";
- import {
- ADD_DEPLOY,
- UPDATE_DEPLOY,
- UPDATE_PROJECT_DEPLOY_AND_CLOUD,
- UPDATE_PROJECT_ONLY_STATUS
- } from "../../../../../../gql";
- import {request} from 'graphql-request'
- import {removePrefix, shiftPrefix, pushPostfix} from "../../../../../../func";
- const Panel = Collapse.Panel;
- // 如需改变显示,请在此处 value 处更改
- // 如需添加中文,请在此处 value 处添加
- // eg: 'xxxx': <F.. id='xxx'/>
- const valueToKey = {
- 'functionName': 'functionName',
- '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 youMustFill = {
- 'functionName': true,
- 'cosBucketName': true,
- 'cosObjectName': true,
- 'cosBucketRegion': true,
- 'serviceName': true,
- 'subnetId': false,
- 'vpcId': false,
- 'region': true,
- 'description': false,
- };
- class DeployCardRender extends Component {
- constructor(props) {
- super(props);
- if(props.deploy !== '' && props.deploy !== null) {
- let {functionName, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId, region, description} = props.deploy;
- this.state = {
- configs: ['description', 'vpcId', 'subnetId'],
- description,
- showOK: false,
- functionName,
- region,
- cosBucketName,
- cosObjectName: removePrefix('.jar', cosObjectName),
- cosBucketRegion,
- serviceName,
- vpcId,
- subnetId
- }
- } else {
- this.state = {
- configs: ['description', 'vpcId', 'subnetId'],
- description: '',
- showOK: false,
- functionName: props.defalutName,
- region: props.region === '' ? 'ap-beijing' : props.region,
- cosBucketName: 'graphqlfc',
- cosObjectName: props.defalutName,
- cosBucketRegion: props.region === '' ? 'ap-beijing' : props.region,
- serviceName: '',
- vpcId: '',
- subnetId: '',
- };
- }
- }
- componentWillReceiveProps(next) {
- if (next.deploy !== '' && next.deploy !== null) {
- let {functionName, cosBucketName, cosObjectName, cosBucketRegion, serviceName, vpcId, subnetId, region, description} = next.deploy;
- this.setState({
- description,
- functionName,
- region: next.region === '' ? region : next.region,
- cosBucketName,
- cosObjectName: removePrefix('.jar', 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, userID, projectID, cloudID, deploy, projectStatus) => {
- let {description, cosBucketName, subnetId, cosObjectName, region, vpcId, cosBucketRegion, functionName} = this.state;
- let varObj = {
- id,
- cloud_id: cloudID,
- user_id: userID,
- cosObjectName: pushPostfix('.jar', cosObjectName),
- region: shiftPrefix('ap-', region),
- cosBucketRegion: shiftPrefix('ap-', cosBucketRegion),
- description,
- cosBucketName,
- vpcId,
- subnetId,
- functionName,
- memorySize: 512,
- timeout: 300,
- handler: 'tencent_graphql.Bridge::handler',
- serviceName: "",
- fc_id: '',
- createdAt: new Date().getTime(),
- updatedAt: ''
- };
- if (deploy === '' || deploy === null) {
- request(graphqlUrl, ADD_DEPLOY, varObj).then(
- data => {
- if (data.create_deploy !== null) {
- this.setState({
- showOK: true
- });
- // 写回 project
- request(graphqlUrl, UPDATE_PROJECT_DEPLOY_AND_CLOUD, {
- id: projectID,
- updatedAt: new Date().getTime(),
- deploy_id: id,
- cloud_id: cloudID,
- projectStatus: 'functioned'
- }).then(data => {
- if(data.update_project !== null)
- this.props.stepByStep(1);
- })
- }
- setTimeout(() => {
- this.setState({
- showOK: false
- })
- }, 1500)
- }
- )
- } else {
- let {description, cosBucketName, subnetId, cosObjectName, region, vpcId, cosBucketRegion, functionName} = this.state;
- let varObj = {
- id: deploy.id,
- cosObjectName: pushPostfix('.jar', cosObjectName),
- region: shiftPrefix('ap-', region),
- cosBucketRegion: shiftPrefix('ap-', cosBucketRegion),
- description,
- subnetId,
- cosBucketName,
- vpcId,
- functionName,
- updatedAt: new Date().getTime()
- };
- request(graphqlUrl, UPDATE_DEPLOY, varObj).then(
- data => {
- if (data.update_deploy !== null) {
- this.setState({
- showOK: true
- });
- request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
- id: projectID,
- updatedAt: new Date().getTime(),
- projectStatus: projectStatus === 'deployed' ? 'updated': 'functioned'
- }).then(data => {
- if(data.update_project !== null)
- this.props.stepByStep(1);
- })
- }
- 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 (
- <div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>
- {
- youMustFill['functionName']?
- <span style={{color: 'red', display: 'inline', marginRight: 10}}>*</span>
- :
- ''
- }
- <FormattedMessage id={valueToKey['functionName']}/>
-
- <Tooltip placement="top" title={toolTipTitle['functionName']}>
- <Icon type="question-circle"/>
- </Tooltip>
- </span>
- <Input value={this.state.functionName} style={{width: 400}}
- onChange={this.switchConfig('functionName')}/>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>
- {
- youMustFill['region']?
- <span style={{color: 'red', display: 'inline', marginRight: 10}}>*</span>
- :
- ''
- }
- <FormattedMessage id={valueToKey['region']}/>
-
- <Tooltip placement="top" title={toolTipTitle['region']}>
- <Icon type="question-circle"/>
- </Tooltip>
- </span>
- <Radio.Group onChange={(e) => {
- this.props.switchRegion(e);
- }} defaultValue={this.state.region} value={removePrefix('ap-', this.state.region)}
- buttonStyle="solid">
- <Radio.Button value="guangzhou"><FormattedMessage id="Guangzhou"/></Radio.Button>
- <Radio.Button value="shanghai"><FormattedMessage id="Shanghai"/></Radio.Button>
- <Radio.Button value="beijing"><FormattedMessage id="Beijing"/></Radio.Button>
- <Radio.Button value="chengdu"><FormattedMessage id="Chengdu"/></Radio.Button>
- </Radio.Group>
- </div>
- <div style={{marginBottom: 10}}>
- <span className='vice-title'>
- {
- youMustFill['cosBucketRegion']?
- <span style={{color: 'red', display: 'inline', marginRight: 10}}>*</span>
- :
- ''
- }
- <FormattedMessage id={valueToKey['cosBucketRegion']}/>
-
- <Tooltip placement="top" title={toolTipTitle['cosBucketRegion']}>
- <Icon type="question-circle"/>
- </Tooltip>
- </span>
- <Radio.Group onChange={(e) => {
- // 如果不想一变所有都变,就将 onchange 改成
- // onChange={this.switchConfig('cosBucketRegion')}
- this.props.switchRegion(e);
- }} defaultValue={this.state.region}
- value={removePrefix('ap-', this.state.cosBucketRegion)} buttonStyle="solid">
- <Radio.Button value="guangzhou"><FormattedMessage id="Guangzhou"/></Radio.Button>
- <Radio.Button value="shanghai"><FormattedMessage id="Shanghai"/></Radio.Button>
- <Radio.Button value="beijing"><FormattedMessage id="Beijing"/></Radio.Button>
- <Radio.Button value="chengdu"><FormattedMessage id="Chengdu"/></Radio.Button>
- </Radio.Group>
- </div>
- <div key={'cosBucketName'} style={{marginBottom: 10}}>
- <span className='vice-title'>
- {
- youMustFill['cosBucketName']?
- <span style={{color: 'red', display: 'inline', marginRight: 10}}>*</span>
- :
- ''
- }
- <FormattedMessage id={valueToKey['cosBucketName']}/>
-
- <Tooltip placement="top" title={toolTipTitle['cosBucketName']}>
- <Icon type="question-circle"/>
- </Tooltip>
- </span>
- <Input value={this.state.cosBucketName} style={{width: 400}}
- disabled={disable['cosBucketName'] === true}
- onChange={this.switchConfig('cosBucketName')}/>
- </div>
- <div key={'cosObjectName'} style={{marginBottom: 10}}>
- <span className='vice-title'>
- {
- youMustFill['cosObjectName']?
- <span style={{color: 'red', display: 'inline', marginRight: 10}}>*</span>
- :
- ''
- }
- <FormattedMessage id={valueToKey['cosObjectName']}/>
-
- <Tooltip placement="top" title={toolTipTitle['cosObjectName']}>
- <Icon type="question-circle"/>
- </Tooltip>
- </span>
- <Input value={this.state.cosObjectName} style={{width: 400}}
- disabled={disable['cosObjectName'] === true} addonAfter=".jar"
- onChange={this.switchConfig('cosObjectName')}/>
- </div>
- <Collapse bordered={false}>
- <Panel header={<FormattedMessage id="Want more options?"/>} style={customPanelStyle}>
- {/*腾讯云为空字符串,不显示,这里未作区分*/}
- {/*<div style={{marginBottom: 10}}>*/}
- {/*<span className='vice-title'>{valueToKey['serviceName']}*/}
- {/*<span> </span>*/}
- {/*<Tooltip placement="top" title={toolTipTitle['serviceName']}>*/}
- {/*<Icon type="question-circle"/>*/}
- {/*</Tooltip>*/}
- {/*</span>*/}
- {/*<Input value={this.state.serviceName} style={{width: 400}} disabled*/}
- {/*onChange={this.switchConfig('serviceName')}/>*/}
- {/*</div>*/}
- {
- this.state.configs.map(config => (
- <div key={config} style={{marginBottom: 10}}>
- <span className='vice-title'>
- {
- youMustFill[config]?
- <span style={{color: 'red', display: 'inline', marginRight: 10}}>*</span>
- :
- ''
- }
- <FormattedMessage id={valueToKey[config]}/>
-
- <Tooltip placement="top" title={toolTipTitle[config]}>
- <Icon type="question-circle"/>
- </Tooltip>
- </span>
- <Input value={this.state[config]} style={{width: 400}}
- disabled={disable[config] === true}
- onChange={this.switchConfig(config)}/>
- </div>
- ))
- }
- </Panel>
- </Collapse>
- <div>
- {
- manageUsers.includes(this.props.userID) ?
- <div>
- <Button onClick={() => {
- const id = idGen('deploy');
- this.ok(id, this.props.userID, this.props.projectID, this.props.cloudID, this.props.deploy, this.props.projectStatus);
- }} type='primary'><FormattedMessage id="save"/></Button>
- {
- this.state.showOK === true ?
- <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
- :
- ''
- }
- </div>
- :
- this.props.trialcase ?
- ''
- :
- <div>
- <Button onClick={() => {
- const id = idGen('deploy');
- this.ok(id, this.props.userID, this.props.projectID, this.props.cloudID, this.props.deploy, this.props.projectStatus);
- }} type='primary'><FormattedMessage id="save"/></Button>
- {
- this.state.showOK === true ?
- <Icon type="check-circle" theme="twoTone" twoToneColor="#52c41a"/>
- :
- ''
- }
- </div>
- }
- </div>
- </div>
- )
- }
- }
- export default DeployCardRender;
|