| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- import React, {Component} from 'react';
- import {Row, Col, Card, Button, Spin, Alert, Steps, Progress} from 'antd';
- import axios from 'axios';
- import APIGroupCardFetch from './apiGroupCard/APIGroupCardFetch';
- import APIPathCardFetch from './apiPathCard/APIPathCardFetch';
- import DeployCardFetch from './deployCard/DeployCardFetch';
- import NotificationCardFetch from './notificationCard/NotificationCardFetch';
- import {GET_PROJECT, SHOW_APIGWPATH, UPDATE_PROJECT_ONLY_STATUS} from "../../../../../gql";
- import {deployUrl, graphqlUrl} from "../../../../../config";
- import {FormattedMessage} from 'react-intl';
- import {request} from 'graphql-request'
- const Step = Steps.Step;
- class TencentConfig extends Component {
- constructor(props) {
- super(props);
- this.state = {
- region: '',
- couldDeploy: false,
- deployIdPassToPath: '',
- groupIdPassToPath: '',
- pathIdPassToConfig: '',
- reachStep: '',
- currentStep: '',
- stepAllShow: false,
- deploying: '',
- stepUpdated: false,
- };
- }
- componentWillMount() {
- let projectID = this.props.projectID ? this.props.projectID : this.props.kind === 'graphql' ? 'ecommerce_projectID' : 'ecommerce_projectID_wx';
- request(graphqlUrl, GET_PROJECT, {id: projectID}).then(
- data => {
- let dataProject = data.project_by_id;
- if (dataProject !== null) {
- this.setState({
- schemaState: dataProject.schema_id ? dataProject.schema_id.schemaState : '',
- projectType: dataProject.projectType
- });
- switch (dataProject.projectStatus) {
- case 'deployed':
- this.setState({
- currentStep: 5,
- reachStep: 5,
- stepAllShow: true,
- deploying: 'deployed'
- });
- break;
- case 'notificationed':
- this.setState({
- currentStep: 4,
- reachStep: 4,
- });
- break;
- case 'pathed':
- this.setState({
- currentStep: 3,
- reachStep: 3,
- });
- break;
- case 'grouped':
- this.setState({
- currentStep: 2,
- reachStep: 2
- });
- break;
- case 'functioned':
- this.setState({
- currentStep: 1,
- reachStep: 1
- });
- break;
- case 'created':
- this.setState({
- currentStep: 0,
- reachStep: 0
- });
- break;
- case 'updated':
- this.setState({
- stepUpdated: true,
- stepAllShow: true,
- deploying: 'updated'
- });
- break;
- case 'deploying':
- this.setState({
- deploying: 'deploying'
- });
- break;
- default:
- this.setState({
- currentStep: 0,
- reachStep: 0
- });
- break;
- }
- } else {
- console.log('project 没存 status');
- }
- }
- )
- }
- componentWillReceiveProps(next) {
- this.setState({
- couldDeploy: false,
- region: '',
- deployIdPassToPath: '',
- groupIdPassToPath: '',
- currentStep: '',
- deploying: '',
- stepAllShow: false,
- stepUpdated: false
- });
- let projectID = next.projectID ? next.projectID : 'ecommerce_projectID';
- request(graphqlUrl, GET_PROJECT, {id: projectID}).then(
- data => {
- let dataProject = data.project_by_id;
- if (dataProject !== null) {
- this.setState({
- schemaState: dataProject.schema_id ? dataProject.schema_id.schemaState : '',
- projectType: dataProject.projectType
- });
- switch (dataProject.projectStatus) {
- case 'deployed':
- this.setState({
- deploying: 'deployed',
- currentStep: 5,
- reachStep: 5,
- stepAllShow: true
- });
- break;
- case 'notificationed':
- this.setState({
- currentStep: 4,
- reachStep: 4
- });
- break;
- case 'pathed':
- this.setState({
- currentStep: 3,
- reachStep: 3
- });
- break;
- case 'grouped':
- this.setState({
- currentStep: 2,
- reachStep: 2
- });
- break;
- case 'functioned':
- this.setState({
- currentStep: 1,
- reachStep: 1
- });
- break;
- case 'created':
- this.setState({
- currentStep: 0,
- reachStep: 0
- });
- break;
- case 'updated':
- this.setState({
- stepUpdated: true,
- stepAllShow: true,
- deploying: 'updated'
- });
- break;
- case 'deploying':
- this.setState({
- deploying: 'deploying'
- });
- break;
- default:
- this.setState({
- currentStep: 0,
- reachStep: 0
- });
- break;
- }
- } else {
- console.log('project 没存 status');
- }
- }
- )
- }
- switchRegion = (e) => {
- this.setState({
- region: e.target.value
- });
- };
- deployFC = () => {
- request(graphqlUrl, GET_PROJECT, {id: this.props.projectID}).then(
- data => {
- let dataProject = data.project_by_id;
- if (dataProject !== null) {
- let schema = dataProject.schema_id.id;
- let deploy = dataProject.deploy_id.id;
- let group = dataProject.apiGWGroup_id.id;
- request(graphqlUrl, SHOW_APIGWPATH, {apiGWGroup_id: group}).then(
- data => {
- if (data.apiGWPath_by_props !== null) {
- // 给 project 加 deploying 状态
- request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
- id: this.props.projectID,
- updatedAt: new Date().getTime(),
- projectStatus: 'deploying'
- });
- // console.log(data);
- let api = data.apiGWPath_by_props[0].id;
- console.log('schema', schema);
- console.log('deploy', deploy);
- console.log('api', api);
- console.log('group', group);
- if (schema && deploy && api && group) {
- console.log('deploying');
- this.setState({
- deploying: 'deploying'
- });
- axios.get(`${deployUrl}`,
- {
- params: {
- 'cloud-id': 'tencent_CloudID',
- 'cloud-name': 'tencent',
- schema,
- deploy,
- api,
- group
- }
- })
- .then((res) => {
- console.log('deploy res', res);
- this.setState({
- deploying: 'deployed'
- });
- // 给 project 加 deployed 状态
- request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
- id: this.props.projectID,
- updatedAt: new Date().getTime(),
- projectStatus: 'deployed'
- })
- })
- .catch((err) => {
- this.setState({
- deploying: 'error'
- });
- // 给 project 加 error 状态
- request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
- id: this.props.projectID,
- updatedAt: new Date().getTime(),
- projectStatus: 'error'
- });
- console.log('err', err);
- console.log('err.response', err.response);
- console.log('err.response.data', err.response.data);
- });
- }
- } else {
- console.log('path 没存');
- }
- }
- );
- } else {
- console.log('project 没存 status');
- }
- }
- );
- };
- stepByStep = (bool) => {
- return (stepNum) => {
- this.setState({
- currentStep: stepNum,
- reachStep: bool ? stepNum : this.state.reachStep
- })
- };
- };
- stepStatus = (value) => {
- if (this.state.reachStep === value)
- return '进行中';
- else if (this.state.reachStep > value)
- return '完成';
- else
- return '等待';
- };
- render() {
- let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
- return (
- <div>
- {
- this.state.projectType === 'graphql' ?
- this.state.schemaState === 'ok' ?
- ''
- :
- this.props.trialcase ?
- ''
- :
- <div style={{marginBottom: 10}}>
- <Alert message="数据表结构不符合规范,暂不能部署,请修改" type="warning"
- banner closable/>
- </div>
- :
- ''
- }
- <div style={{padding: '30px'}}>
- <Row gutter={16}>
- <Col span={14}>
- {
- this.state.currentStep !== '' || this.state.deploying === 'deploying' || this.state.deploying === 'deployed' ?
- <Steps current={this.state.deploying !== 'deploying' ? this.state.currentStep : 4}
- style={{marginBottom: 30}}>
- <Step onClick={() => {
- this.stepByStep(false)(0)
- }} title={this.stepStatus(0)} description="云函数配置"/>
- <Step onClick={() => {
- if (this.state.reachStep > 0)
- this.stepByStep(false)(1);
- }} title={this.stepStatus(1)} description="服务配置"/>
- <Step onClick={() => {
- if (this.state.reachStep > 1)
- this.stepByStep(false)(2)
- }} title={this.stepStatus(2)} description="API 配置"/>
- <Step onClick={() => {
- if (this.state.reachStep > 2)
- this.stepByStep(false)(3)
- }} title={this.stepStatus(3)} description="通知配置"/>
- </Steps>
- :
- ''
- }
- {
- this.state.currentStep === 0 || this.state.stepAllShow ?
- <FormattedMessage id="fc Deploy">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <DeployCardFetch
- switchRegion={this.switchRegion}
- region={this.state.region}
- trialcase={this.props.trialcase}
- stepByStep={this.stepByStep(true)}
- projectID={projectID}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- {
- this.state.currentStep === 1 || this.state.stepAllShow ?
- <FormattedMessage id="API Group">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <APIGroupCardFetch
- switchRegion={this.switchRegion}
- region={this.state.region}
- trialcase={this.props.trialcase}
- stepByStep={this.stepByStep(true)}
- userID={this.props.userID}
- projectID={projectID}
- stepAllShow={this.state.stepAllShow}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- {
- this.state.currentStep === 2 || this.state.stepAllShow ?
- <FormattedMessage id="API Path">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <APIPathCardFetch
- trialcase={this.props.trialcase}
- stepByStep={this.stepByStep(true)}
- userID={this.props.userID}
- projectID={projectID}
- stepAllShow={this.state.stepAllShow}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- {
- this.state.currentStep === 3 || this.state.stepAllShow ?
- <FormattedMessage id="Notification">
- {
- msg =>
- <Card title={msg}>
- <NotificationCardFetch
- userID={this.props.userID}
- trialcase={this.props.trialcase}
- stepByStep={this.stepByStep(true)}
- projectID={projectID}
- stepAllShow={this.state.stepAllShow}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- </Col>
- <Col span={8} offset={2}>
- {
- this.state.currentStep === 4 || this.state.stepAllShow ?
- this.props.trialcase ?
- ''
- :
- this.state.projectType === 'graphql' ?
- this.state.schemaState === 'ok' ?
- this.state.deploying === '' ?
- <Button type='primary' onClick={this.deployFC}><FormattedMessage
- id="deploy"/>!</Button>
- :
- ''
- :
- <Button type='primary'
- disabled><FormattedMessage
- id="deploy"/>!</Button>
- :
- <Button type='primary' onClick={() => {
- }}><FormattedMessage id="deploy"/>!</Button>
- :
- ''
- }
- {
- this.props.trialcase ?
- <Progress type="circle" percent={100}/>
- :
- this.state.deploying === 'deploying' ?
- <div>
- <Spin size="large"/>
-
- <span><b>大约需要等待 30s</b></span>
- </div>
- :
- this.state.deploying === 'deployed' ?
- <Progress type="circle" percent={100}/>
- :
- this.state.deploying === 'error' ?
- <Progress type="circle" percent={99} status="exception"/>
- :
- this.state.deploying === 'updated' ?
- <Button type='primary' onClick={this.deployFC}><FormattedMessage
- id="redeploy"/>!</Button>
- :
- ''
- }
- </Col>
- </Row>
- </div>
- </div>
- );
- }
- }
- export default TencentConfig;
|