Browse Source

检测 schema 判断是否可以部署

xy 7 năm trước cách đây
mục cha
commit
ab253d715f

+ 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 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/>,
         };

+ 17 - 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,15 @@ class TencentConfig extends Component {
                 currentPath: '',
             })
         }
+
+        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 +110,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 +145,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>

+ 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
                 }
             }
         `;