| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546 |
- import React, {Component} from 'react';
- import {Row, Col, Card, Button, Spin, Alert, Steps, Progress} from 'antd';
- import axios from 'axios';
- import APIGroupCard from './APIGroupCard';
- import APIPathCard from './APIPathCard';
- import DeployCard from './DeployCard';
- import NotificationCard from './NotificationCard';
- import {SHOW_APIGWPATH, GET_PROJECT} from "../../../../gql";
- import {deployUrl, graphqlUrl} from "../../../../config";
- import {FormattedMessage} from 'react-intl';
- import gql from "graphql-tag";
- import {Query} from "react-apollo";
- 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: '',
- currentStep: '',
- stepAllShow: false,
- deploying: ''
- };
- }
- componentWillMount() {
- let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
- request(graphqlUrl, GET_PROJECT, {id: projectID}).then(
- data => {
- let dataProject = data.project_by_id;
- if (dataProject !== null) {
- switch(dataProject.projectStatus) {
- case 'deployed':
- this.setState({
- currentStep: 5,
- stepAllShow: true
- });
- break;
- case 'notificationed':
- this.setState({
- currentStep: 4
- });
- break;
- case 'pathed':
- this.setState({
- currentStep: 3
- });
- break;
- case 'grouped':
- this.setState({
- currentStep: 2
- });
- break;
- case 'functioned':
- this.setState({
- currentStep: 1
- });
- break;
- case 'created':
- this.setState({
- currentStep: 0
- });
- break;
- default:
- this.setState({
- currentStep: 0
- });
- break;
- }
- console.log(dataProject.projectStatus);
- } else {
- console.log('peoject 没存 status');
- }
- }
- )
- }
- componentWillReceiveProps(next) {
- this.setState({
- couldDeploy: false,
- region: '',
- deployIdPassToPath: '',
- groupIdPassToPath: '',
- currentStep: 0,
- deploying: '',
- stepAllShow: false,
- });
- }
- switchRegion = (e) => {
- this.setState({
- region: e.target.value
- });
- };
- pass = (value, kind) => {
- if (kind === 'deploy')
- this.setState({
- deployIdPassToPath: value
- });
- else if (kind === 'group')
- this.setState({
- groupIdPassToPath: value
- });
- else {
- this.setState({
- pathIdPassToConfig: value
- })
- }
- };
- deployFC = (schema, deploy, api, group) => {
- 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: 'finished'
- })
- })
- .catch((err) => {
- this.setState({
- deploying: 'error'
- });
- console.log('err', err);
- console.log('err.response', err.response);
- console.log('err.response.data', err.response.data);
- });
- }
- };
- stepByStep = (stepNum) => {
- this.setState({
- currentStep: stepNum
- })
- };
- stepStatus = (value) => {
- if (this.state.currentStep === value)
- return '进行中';
- else if (this.state.currentStep > value)
- return '完成';
- else
- return '等待';
- };
- render() {
- let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID';
- return (
- <Query query={gql(GET_PROJECT)} variables={{id: projectID}}>
- {
- ({loading, error, data}) => {
- if (loading) {
- return <Spin style={{marginLeft: 3}}/>
- }
- if (error) {
- return 'error!';
- }
- let group = '',
- deploy = '',
- path = '',
- schemaID = '',
- configID = '',
- cloudID = 'tencent_CloudID';
- let dataProject = data.project_by_id;
- let {cloud_id, apiGWGroup_id, deploy_id, projectType, schema_id, wxConfig_id, projectName} = dataProject;
- // console.log('dataProject', dataProject);
- let defaultName = projectName;
- if (projectType === 'graphql')
- schemaID = schema_id.id;
- else
- configID = wxConfig_id.id;
- // 如果 cloud_id 没有存储,说明尚未部署,即新的 project,使用 '视图 2'
- // 旧的 project 使用 '视图 1'
- if (cloud_id !== null && cloud_id.cloudName === 'tencent') {
- group = apiGWGroup_id;
- deploy = deploy_id;
- cloudID = cloud_id.id;
- }
- return (
- <div>
- {
- projectType === 'graphql' ?
- schema_id.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 !== ''?
- <Steps current={this.state.currentStep} style={{marginBottom: 30}}>
- <Step title={this.stepStatus(0)} description="云函数配置"/>
- <Step title={this.stepStatus(1)} description="服务配置"/>
- <Step title={this.stepStatus(2)} description="API 配置"/>
- <Step title={this.stepStatus(3)} description="通知配置"/>
- </Steps>
- :
- ''
- }
- {
- this.state.currentStep === 0 || this.state.stepAllShow?
- <FormattedMessage id="fc Deploy">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <DeployCard
- deploy={deploy}
- switchRegion={this.switchRegion}
- region={this.state.region}
- defalutName={defaultName}
- userID={this.props.userID}
- cloudID={cloudID}
- trialcase={this.props.trialcase}
- pass={this.pass}
- stepByStep={this.stepByStep}
- projectID={projectID}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- {
- this.state.currentStep === 1 || this.state.stepAllShow?
- <FormattedMessage id="API Group">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <APIGroupCard
- group={group}
- userID={this.props.userID}
- switchRegion={this.switchRegion}
- region={this.state.region}
- cloudID={cloudID}
- trialcase={this.props.trialcase}
- pass={this.pass}
- stepByStep={this.stepByStep}
- projectID={projectID}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- {
- this.state.currentStep === 2 || this.state.stepAllShow?
- <Query query={gql(SHOW_APIGWPATH)}
- variables={{apiGWGroup_id: apiGWGroup_id ? apiGWGroup_id.id : ''}}>
- {
- ({loading, error, data}) => {
- if (loading) {
- return <Spin style={{marginLeft: 3}}/>
- }
- if (error) {
- return 'error!';
- }
- if (data.apiGWPath_by_props.length > 0)
- path = data.apiGWPath_by_props[0];
- return (
- <FormattedMessage id="API Path">
- {
- msg =>
- <Card title={msg}
- style={{marginBottom: 10}}>
- <APIPathCard
- path={path}
- defalutName={defaultName}
- userID={this.props.userID}
- trialcase={this.props.trialcase}
- deployID={deploy ? deploy.id : this.state.deployIdPassToPath}
- groupID={group ? group.id : this.state.groupIdPassToPath}
- pass={this.pass}
- stepByStep={this.stepByStep}
- />
- </Card>
- }
- </FormattedMessage>
- )
- }
- }
- </Query>
- :
- ''
- }
- {
- this.state.currentStep === 3 || this.state.stepAllShow?
- <FormattedMessage id="Notification">
- {
- msg =>
- <Card title={msg}>
- <NotificationCard
- userID={this.props.userID}
- defalutName={defaultName}
- trialcase={this.props.trialcase}
- stepByStep={this.stepByStep}
- projectID={projectID}
- />
- </Card>
- }
- </FormattedMessage>
- :
- ''
- }
- </Col>
- {
- this.state.currentStep === 4 || this.state.stepAllShow?
- <Col offset={2} span={6}>
- {
- this.props.trialcase ?
- ''
- :
- projectType === 'graphql' ?
- schema_id.schemaState === 'ok' ?
- this.state.deploying === '' ?
- <Button type='primary' onClick={() => this.deployFC(schemaID, deploy ? deploy.id : this.state.deployIdPassToPath, this.state.pathIdPassToConfig, group ? group.id : this.state.groupIdPassToPath)}><FormattedMessage id="deploy"/>!</Button>
- :
- ''
- :
- <Button type='primary'
- disabled><FormattedMessage
- id="deploy"/>!</Button>
- :
- <Button type='primary' onClick={() => {
- }}><FormattedMessage id="deploy"/>!</Button>
- }
- {
- this.state.deploying === 'deploying' ?
- <Spin size="large"/>
- :
- this.state.deploying === 'finished' ?
- <Progress type="circle" percent={100} />
- :
- this.state.deploying === 'error' ?
- <Progress type="circle" percent={99} status="exception" />
- :
- ''
- }
- </Col>
- :
- ''
- }
- </Row>
- </div>
- </div>
- );
- // no use, backup code
- return (
- <div>
- {
- projectType === 'graphql' ?
- schema_id.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}>
- <FormattedMessage id="fc Deploy">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <DeployCard
- deploy={deploy}
- switchRegion={this.switchRegion}
- region={this.state.region}
- defalutName={defaultName}
- userID={this.props.userID}
- cloudID={cloudID}
- trialcase={this.props.trialcase}
- pass={this.pass}
- projectID={projectID}
- stepByStep={this.stepByStep}
- />
- </Card>
- }
- </FormattedMessage>
- <FormattedMessage id="API Group">
- {
- msg =>
- <Card title={msg} style={{marginBottom: 10}}>
- <APIGroupCard
- group={group}
- userID={this.props.userID}
- switchRegion={this.switchRegion}
- region={this.state.region}
- cloudID={cloudID}
- trialcase={this.props.trialcase}
- pass={this.pass}
- projectID={projectID}
- stepByStep={this.stepByStep}
- />
- </Card>
- }
- </FormattedMessage>
- <Query query={gql(SHOW_APIGWPATH)}
- variables={{apiGWGroup_id: apiGWGroup_id ? apiGWGroup_id.id : ''}}>
- {
- ({loading, error, data}) => {
- if (loading) {
- return <Spin style={{marginLeft: 3}}/>
- }
- if (error) {
- return 'error!';
- }
- if (data.apiGWPath_by_props.length > 0)
- path = data.apiGWPath_by_props[0];
- return (
- <FormattedMessage id="API Path">
- {
- msg =>
- <Card title={msg}
- style={{marginBottom: 10}}>
- <APIPathCard
- path={path}
- defalutName={defaultName}
- userID={this.props.userID}
- trialcase={this.props.trialcase}
- deployID={deploy ? deploy.id : this.state.deployIdPassToPath}
- groupID={group ? group.id : this.state.groupIdPassToPath}
- pass={this.pass}
- stepByStep={this.stepByStep}
- />
- </Card>
- }
- </FormattedMessage>
- )
- }
- }
- </Query>
- <FormattedMessage id="Notification">
- {
- msg =>
- <Card title={msg}>
- <NotificationCard
- userID={this.props.userID}
- defalutName={defaultName}
- trialcase={this.props.trialcase}
- projectID={projectID}
- stepByStep={this.stepByStep}
- />
- </Card>
- }
- </FormattedMessage>
- </Col>
- <Col offset={2} span={6}>
- {
- this.props.trialcase ?
- ''
- :
- projectType === 'graphql' ?
- schema_id.schemaState === 'ok' ?
- <Button type='primary'
- onClick={() => this.deployFC(schemaID, deploy ? deploy.id : this.state.deployIdPassToPath, this.state.pathIdPassToConfig, group ? group.id : this.state.groupIdPassToPath)}><FormattedMessage
- id="deploy"/>!</Button>
- :
- <Button type='primary' disabled><FormattedMessage
- id="deploy"/>!</Button>
- :
- <Button type='primary' onClick={() => {
- }}><FormattedMessage id="deploy"/>!</Button>
- }
- </Col>
- </Row>
- </div>
- </div>
- )
- }
- }
- </Query>
- )
- }
- }
- export default TencentConfig;
|