Browse Source

Merge remote-tracking branch 'origin/master'

Csy817 7 năm trước cách đây
mục cha
commit
4beec8e619

+ 1 - 1
src/app/common/deploy/Deploy.jsx

@@ -253,7 +253,7 @@ class Deploy extends Component {
 
     render() {
         const contentListNoTitle = {
-            tencent: <TencentConfig cloudID={this.state.tencentCloudID} fc={this.state.tencentFC} defalutName={this.state.defalutName} userID={this.props.userID} kind={this.state.kind} trialcase={this.props.trialcase}/>,
+            tencent: <TencentConfig configID={this.state.configID} schemaID={this.state.schemaID} cloudID={this.state.tencentCloudID} fc={this.state.tencentFC} defalutName={this.state.defalutName} userID={this.props.userID} kind={this.state.kind} trialcase={this.props.trialcase}/>,
             aliyun: <AliConfig/>,
             amazon: <AmazonConfig/>,
         };

+ 19 - 8
src/app/common/deploy/tencent/APIGroupCard.js

@@ -8,7 +8,18 @@ import {manageUsers} from "../../../../config";
 import {FormattedMessage} from 'react-intl';
 const Panel = Collapse.Panel;
 
-
+// 如需改变显示,请在此处 value 处更改
+// 如需添加中文,请在此处 value 处添加
+// eg: 'xxxx': <F..  id='xxx'/>
+const valueToKey = {
+    'groupName': 'Name',
+    'environmentName': 'environmentName',
+    'defaultDomain': 'defaultDomain',
+    'frontType': 'frontType',
+    'userDomain': 'userDomain',
+    'userStatus': 'userStatus',
+    'region': 'region',
+};
 
 class APIGroupCard extends Component {
     constructor(props) {
@@ -147,12 +158,12 @@ class APIGroupCard extends Component {
                 <Collapse bordered={false}>
                     <Panel header="Want more options?" style={customPanelStyle}>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>groupName: </span>
+                            <span className='vice-title'>{valueToKey['groupName']}: </span>
                             <Input value={this.state.groupName} style={{width: 400}}
                                    onChange={this.switchConfig('groupName')}/>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>region: </span>
+                            <span className='vice-title'>{valueToKey['region']}: </span>
                             <Radio.Group onChange={this.switchConfig('groupRegion')} value={this.state.groupRegion} buttonStyle="solid">
                                 <Radio.Button value="guangzhou">Guangzhou</Radio.Button>
                                 <Radio.Button value="shanghai">Shanghai</Radio.Button>
@@ -161,7 +172,7 @@ class APIGroupCard extends Component {
                             </Radio.Group>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>frontType: </span>
+                            <span className='vice-title'>{valueToKey['frontType']}: </span>
                             <Radio.Group onChange={this.switchConfig('frontType')} defaultValue={this.state.frontType}
                                          buttonStyle="solid">
                                 <Radio.Button value="http">http</Radio.Button>
@@ -170,11 +181,11 @@ class APIGroupCard extends Component {
                             </Radio.Group>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>defaultDomain: </span>
+                            <span className='vice-title'>{valueToKey['defaultDomain']}: </span>
                             <Input value={this.state.defaultDomain} style={{width: 400}} disabled/>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>environmentName: </span>
+                            <span className='vice-title'>{valueToKey['environmentName']}: </span>
                             <Radio.Group onChange={this.switchConfig('environmentName')} defaultValue={this.state.environmentName}
                                          buttonStyle="solid">
                                 <Radio.Button value="test">test</Radio.Button>
@@ -183,12 +194,12 @@ class APIGroupCard extends Component {
                             </Radio.Group>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>userDomain: </span>
+                            <span className='vice-title'>{valueToKey['userDomain']}: </span>
                             <Input value={this.state.userDomain} style={{width: 400}}
                                    onChange={this.switchConfig('userDomain')}/>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>userStatus: </span>
+                            <span className='vice-title'>{valueToKey['userStatus']}: </span>
                             <Radio.Group onChange={this.switchConfig('userStatus')} defaultValue={this.state.userStatus}
                                          buttonStyle="solid">
                                 <Radio.Button value="open">open</Radio.Button>

+ 10 - 3
src/app/common/deploy/tencent/APIPathCard.js

@@ -8,7 +8,14 @@ import {manageUsers} from "../../../../config";
 
 const Panel = Collapse.Panel;
 
-
+// 如需改变显示,请在此处 value 处更改
+// 如需添加中文,请在此处 value 处添加
+// eg: 'xxxx': <F..  id='xxx'/>
+const valueToKey = {
+    'apiGWName': 'Name',
+    'apiGWDesc': 'Description',
+    'requestMethod': 'Method'
+};
 
 class APIPathCard extends Component {
     constructor(props) {
@@ -134,14 +141,14 @@ class APIPathCard extends Component {
                         {
                             this.state.configs.map(config => (
                                 <div key={config} style={{marginBottom: 10}}>
-                                    <span className='vice-title'>{config}: </span>
+                                    <span className='vice-title'>{valueToKey[config]}: </span>
                                     <Input value={this.state[config]} style={{width: 200}}
                                            onChange={this.switchConfig(config)}/>
                                 </div>
                             ))
                         }
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>requestMethod: </span>
+                            <span className='vice-title'>{valueToKey['requestMethod']}: </span>
                             <Radio.Group onChange={this.switchConfig('requestMethod')}
                                          defaultValue={this.state.requestMethod}
                                          buttonStyle="solid">

+ 18 - 15
src/app/common/deploy/tencent/DeployCard.js

@@ -8,16 +8,19 @@ import {manageUsers} from "../../../../config";
 
 const Panel = Collapse.Panel;
 
+// 如需改变显示,请在此处 value 处更改
+// 如需添加中文,请在此处 value 处添加
+// eg: 'xxxx': <F..  id='xxx'/>
 const valueToKey = {
-    'functionName': '',
-    'cosBucketName': '',
-    'cosObjectName': '',
-    'cosBucketRegion': '',
-    'serviceName': '',
-    'subnetId': '',
-    'vpcId': '',
-    'region': '',
-    'description': '',
+    'functionName': 'Name',
+    'cosBucketName': 'cosBucketName',
+    'cosObjectName': 'cosObjectName',
+    'cosBucketRegion': 'cosBucketRegion',
+    'serviceName': 'serviceName',
+    'subnetId': 'subnetId',
+    'vpcId': 'vpcId',
+    'region': 'region',
+    'description': 'description',
 };
 
 class DeployCard extends Component {
@@ -41,7 +44,7 @@ class DeployCard extends Component {
             :
             this.state = {
                 configs: ['description', 'cosBucketName', 'cosObjectName', 'vpcId', 'subnetId'],
-                description: props.description,
+                description: '',
                 showOK: false,
                 functionName: props.defalutName,
                 region: props.region,
@@ -170,12 +173,12 @@ class DeployCard extends Component {
         return (
             <div>
                 <div style={{marginBottom: 10}}>
-                    <span className='vice-title'>functionName: </span>
+                    <span className='vice-title'>{valueToKey['functionName']}: </span>
                     <Input value={this.state.functionName} style={{width: 400}}
                            onChange={this.switchConfig('functionName')}/>
                 </div>
                 <div style={{marginBottom: 10}}>
-                    <span className='vice-title'>region: </span>
+                    <span className='vice-title'>{valueToKey['region']}: </span>
                     <Radio.Group onChange={(e) => {
                         this.props.switchRegion(e);
                         this.setState({
@@ -191,7 +194,7 @@ class DeployCard extends Component {
                 <Collapse bordered={false}>
                     <Panel header="Want more options?" style={customPanelStyle}>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>cosBucketRegion: </span>
+                            <span className='vice-title'>{valueToKey['cosBucketRegion']}: </span>
                             <Radio.Group onChange={this.switchConfig('cosBucketRegion')}
                                          value={this.state.cosBucketRegion} buttonStyle="solid">
                                 <Radio.Button value="guangzhou">Guangzhou</Radio.Button>
@@ -201,14 +204,14 @@ class DeployCard extends Component {
                             </Radio.Group>
                         </div>
                         <div style={{marginBottom: 10}}>
-                            <span className='vice-title'>serviceName: </span>
+                            <span className='vice-title'>{valueToKey['serviceName']}: </span>
                             <Input value={this.state.serviceName} style={{width: 200}} disabled
                                    onChange={this.switchConfig('serviceName')}/>
                         </div>
                         {
                             this.state.configs.map(config => (
                                 <div key={config} style={{marginBottom: 10}}>
-                                    <span className='vice-title'>{config}: </span>
+                                    <span className='vice-title'>{valueToKey[config]}: </span>
                                     <Input value={this.state[config]} style={{width: 200}}
                                            onChange={this.switchConfig(config)}/>
                                 </div>

+ 24 - 6
src/app/common/deploy/tencent/TencentConfig.js

@@ -6,7 +6,7 @@ import APIPathCard from './APIPathCard';
 import DeployCard from './DeployCard';
 import NotificationCard from './NotificationCard';
 
-import {SHOW_DEPLOY, SHOW_APIGWGROUP, SHOW_APIGWPATH} from "../../../../gql";
+import {SHOW_DEPLOY, SHOW_APIGWGROUP, SHOW_APIGWPATH, SEARCH_SCHEMA} from "../../../../gql";
 import {request} from 'graphql-request'
 import {graphqlUrl,deployUrl} from "../../../../config";
 import {FormattedMessage} from 'react-intl';
@@ -26,7 +26,8 @@ class TencentConfig extends Component {
             deployIdPassToPath: '',
             groupIdPassToPath: '',
             cloudID: props.cloudID,
-            fc: props.fc
+            fc: props.fc,
+            couldDeploy: false
         };
     }
 
@@ -37,7 +38,8 @@ class TencentConfig extends Component {
     componentWillReceiveProps(next) {
         this.setState({
             fc: next.fc,
-            cloudID: next.cloudID
+            cloudID: next.cloudID,
+            couldDeploy: false
         }, this.fetch);
     }
 
@@ -77,6 +79,22 @@ class TencentConfig extends Component {
                 currentPath: '',
             })
         }
+
+        if(this.props.schemaID === '' || this.props.schemaID === undefined) {
+            this.setState({
+                couldDeploy: true
+            });
+        } else {
+            request(graphqlUrl, SEARCH_SCHEMA, {id: this.props.schemaID}).then(
+                data => {
+                    if(data.schema_by_id.schemaState === 'ok')
+                        this.setState({
+                            couldDeploy: true
+                        });
+                }
+            );
+        }
+
     };
 
     pass = (value, kind) => {
@@ -99,8 +117,8 @@ class TencentConfig extends Component {
     deployFC = () => {
         let _this = this;
 
-        // axios.get(`${deployUrl}`,
-        axios.get(`http://localhost:8999/graphql/deployall`,
+        axios.get(`${deployUrl}`,
+        // axios.get(`http://localhost:8999/graphql/deployall`,
             {
                 params: {
                     'cloud-name': 'tencent',
@@ -134,7 +152,7 @@ class TencentConfig extends Component {
 
                         </Col>
                         <Col offset={2} span={6}>
-                            <Button type='primary' onClick={()=>this.deployFC()}><FormattedMessage id="deploy"/>!</Button>
+                            <Button type='primary' disabled={this.state.couldDeploy? '': 'disabled'} onClick={()=>this.deployFC()}><FormattedMessage id="deploy"/>!</Button>
                         </Col>
                     </Row>
                 </div>

+ 43 - 24
src/app/graphqlService/component/schema/Table.js

@@ -26,7 +26,7 @@ class Table extends Component {
             newColType: 'type',
             types: ['ID', 'String', 'Int', 'Float', 'Boolean', 'DateTime'],
             descriptions: ['description', 'key', 'non-null', 'non-null-list', 'list'],
-            characterTips: false
+            characterTips: false,
         }
     }
 
@@ -288,22 +288,22 @@ class UpdateTableButton extends Component {
         super(props);
         this.state = {
             originTableName: props.currentTable,
-            schemaCheck:false
+            schemaCheck: ''
         }
-
     }
 
-    showConfirm = (schemaName, schemaID) => {
+    showConfirm = (schemaName, schemaID, data) => {
         let _this = this;
 
         if (this.props.add !== 'add') {
-            this.props.history.push({
-                pathname: `/graphql-service/my-create/${schemaName}`,
-                state: {
-                    schemaName,
-                    schemaID
-                }
-            });
+            if(data.update_schema.schemaState === 'ok')
+                this.props.history.push({
+                    pathname: `/graphql-service/my-create/${schemaName}`,
+                    state: {
+                        schemaName,
+                        schemaID
+                    }
+                });
         } else {
             confirm({
                 title: '添加成功',
@@ -324,7 +324,7 @@ class UpdateTableButton extends Component {
         }
     };
 
-    checkSchema = (update_schema,schemaID,varobj,schemaCols) => {
+    checkSchema = (update_schema, schemaID, varobj, schemaCols) => {
         update_schema({
             variables: {
                 ...varobj,
@@ -337,15 +337,25 @@ class UpdateTableButton extends Component {
             .then((res) => {
                 console.log('check schema res', res);
                 if (res.data !== '') {
+                    update_schema({
+                        variables: {
+                            ...varobj,
+                            schemaData: JSON.stringify(schemaCols),
+                            schemaState: 'ok',
+                        }
+                    });
                     _this.setState({
-                        schemaCheck:"checked-success",
+                        schemaCheck: '',
                     });
                 }
             })
             .catch((err) => {
-                console.log('err',err);
-                console.log('err.response',err.response);
-                console.log('err.response.data',err.response.data);
+                // console.log('err',err);
+                // console.log('err.response',err.response);
+                _this.setState({
+                    schemaCheck: err.response.data,
+                });
+                console.log('err.response.data', err.response.data);
             });
     };
 
@@ -378,7 +388,7 @@ class UpdateTableButton extends Component {
                         return (
                             <Mutation
                                 mutation={gql(UPDATE_SCHEMA)}
-                                onCompleted={() => this.showConfirm(schemaName, schemaID)}
+                                onCompleted={(data) => this.showConfirm(schemaName, schemaID, data)}
                                 refetchQueries={[{query: gql(SHOW_TABLE), variables: {schema_id: schemaID}}]}
                             >
 
@@ -432,14 +442,23 @@ class UpdateTableButton extends Component {
                                     }
 
                                     return (
-                                        <div style={{display: 'inline-block'}}>
-                                            <Button type="primary" onClick={() => {
-                                                this.checkSchema(update_schema,schemaID,varobj,schemaCols);
-                                                this.props.showTablePagination(this.props.page, this.props.pageSize, schemaCols);
-                                            }}>
-                                                <FormattedMessage id="save"/>
-                                            </Button>
+                                        <div>
+                                            <div style={{display: 'inline-block'}}>
+                                                <Button type="primary" onClick={() => {
+                                                    this.checkSchema(update_schema, schemaID, varobj, schemaCols);
+                                                    this.props.showTablePagination(this.props.page, this.props.pageSize, schemaCols);
+                                                }}>
+                                                    <FormattedMessage id="save"/>
+                                                </Button>
+                                            </div>
+                                            {
+                                                this.state.schemaCheck !== '' ?
+                                                    <span>  failed, cause '{this.state.schemaCheck}'</span>
+                                                    :
+                                                    ''
+                                            }
                                         </div>
+
                                     )
                                 }}
                             </Mutation>

+ 9 - 5
src/config.js

@@ -8,14 +8,18 @@ const backend = serverIP + ':' + backendPort;
 const graphqlUrl = serverIP + ':' + graphqlPort + '/graphql';
 
 // api 配置
-const genJsUrl = backend + '/graphql/genjs';
-const checkSchemaUrl = backend + '/graphql/compile';
-const deployUrl = backend + '/graphql/deployall';
 const getIdUrl = backend + '/getuserid';
-const loginUrl = backend +  '/login';
+const loginUrl = backend + '/login';
 const registerUrl = backend + '/resetpassword';
 
+// graphql 部署配置
+const backendGQ = backend + '/graphql';
+const genJsUrl = backendGQ + '/genjs';
+const checkSchemaUrl = backendGQ + '/compile';
+const deployUrl = backendGQ + '/deployall';
+
 // 管理员配置
+// 通过在该数组中添加 userID,可以管理 trialcase 的增删改查
 const manageUsers = ['xy_1_je9{d\'\'_32sD+'];
 
-export {genJsUrl, getIdUrl, loginUrl, registerUrl,checkSchemaUrl,deployUrl, graphqlUrl, manageUsers}
+export {getIdUrl, loginUrl, registerUrl, checkSchemaUrl, deployUrl, genJsUrl, graphqlUrl, manageUsers}

+ 8 - 0
src/gql.js

@@ -57,6 +57,7 @@ const SHOW_SCHEMA = `
                     schemaName
                     id
                     reference
+                    schemaState
                 }
             }
         `;
@@ -68,12 +69,14 @@ const SHOW_ALL_SCHEMA = `
                     schemaName
                     id
                     reference
+                    schemaState
                 }
                 caseSchema:schema_by_props(user_id: "ioobot") {
                     schemaData
                     schemaName
                     id
                     reference
+                    schemaState
                 }
             }
         `;
@@ -85,6 +88,7 @@ const SEARCH_SCHEMA = `
                     schemaData
                     id
                     reference
+                    schemaState
                 }
             }
         `;
@@ -105,6 +109,7 @@ const ADD_SCHEMA = `
                     schemaData
                     id
                     reference
+                    schemaState
                 }
             }
         `;
@@ -126,6 +131,7 @@ const UPDATE_SCHEMA = `
                     schemaName,
                     schemaData
                     id
+                    schemaState
                 }
             }
         `;
@@ -139,6 +145,7 @@ const UPDATE_SCHEMA_NAME = `
                 ) {
                     schemaName,
                     id
+                    schemaState
                 }
             }
         `;
@@ -150,6 +157,7 @@ const SHOW_TABLE = `
                     schemaData
                     schemaName
                     reference
+                    schemaState
                 }
             }
         `;