xy 7 سال پیش
والد
کامیت
a22add2d19
3فایلهای تغییر یافته به همراه27 افزوده شده و 9 حذف شده
  1. 3 3
      src/components/app/App.jsx
  2. 11 3
      src/components/common/schema/Schema.jsx
  3. 13 3
      src/components/common/schema/Table.js

+ 3 - 3
src/components/app/App.jsx

@@ -360,9 +360,9 @@ class GraphqlSidebar extends Component {
                         // console.log('user schema data',data);
                         if (loading) return <Spin style={{marginLeft: 3}}/>;
                         if (error) return 'error!';
-                        localStorage.setItem('ecommerce', data.caseSchema[2].schemaData);
-                        localStorage.setItem('subscribe', data.caseSchema[0].schemaData);
-                        localStorage.setItem('bills', data.caseSchema[1].schemaData);
+                        localStorage.setItem('ecommerce', data.caseSchema.find(obj=>obj.schemaName==='ecommerce').schemaData);
+                        localStorage.setItem('subscribe', data.caseSchema.find(obj=>obj.schemaName==='subscribe').schemaData);
+                        localStorage.setItem('bills', data.caseSchema.find(obj=>obj.schemaName==='bills').schemaData);
                         return (
                             <Menu
                                 theme="dark"

+ 11 - 3
src/components/common/schema/Schema.jsx

@@ -108,10 +108,11 @@ class Schema extends Component {
             return new Promise((resolve, reject) => {
                 request('http://123.206.193.98:3000/graphql', SEARCH_SCHEMA, {id: referenceID}).then(
                     data => {
+                        console.log(data);
                         if (data.schema_by_id !== null) {
-                            localStorage.setItem('ecommerce', data.caseSchema[2].schemaData);
-                            localStorage.setItem('subscribe', data.caseSchema[0].schemaData);
-                            localStorage.setItem('bills', data.caseSchema[1].schemaData);
+                            localStorage.setItem('ecommerce', data.caseSchema.find(obj=>obj.schemaName==='ecommerce').schemaData);
+                            localStorage.setItem('subscribe', data.caseSchema.find(obj=>obj.schemaName==='subscribe').schemaData);
+                            localStorage.setItem('bills', data.caseSchema.find(obj=>obj.schemaName==='bills').schemaData);
                             resolve(data.schema_by_id.schemaData);
                         }
                     }
@@ -332,6 +333,7 @@ class Schema extends Component {
                                                                     <DeleteSchemaButton
                                                                         userID={userID}
                                                                         schemaName={this.state.schemaName}
+                                                                        history={this.props.history}
                                                                     />
                                                                 </div>
                                                         }
@@ -369,6 +371,7 @@ class Schema extends Component {
                                                 showTablePagination={this.showTablePagination}
                                                 page={this.state.page}
                                                 pageSize={this.state.pageSize}
+                                                history={this.props.history}
                                             /> :
                                             <Table
                                                 currentTable={this.state.currentTable}
@@ -384,6 +387,7 @@ class Schema extends Component {
                                                 showTablePagination={this.showTablePagination}
                                                 page={this.state.page}
                                                 pageSize={this.state.pageSize}
+                                                history={this.props.history}
                                             />
                                 }
 
@@ -467,11 +471,15 @@ class DeleteSchemaButton extends Component {
     }
 
     showConfirm = (delete_schema, schemaName, userID) => {
+        let _this = this;
         confirm({
             title: 'Do you want to delete this schema?',
             content: 'It cannot be found back!',
             onOk() {
                 delete_schema({variables: {schemaName, user_id: userID}});
+                _this.props.history.push({
+                    pathname: '/graphql-service',
+                });
             },
             onCancel() {
             },

+ 13 - 3
src/components/common/schema/Table.js

@@ -224,6 +224,8 @@ class Table extends Component {
                                         showTablePagination={this.props.showTablePagination}
                                         page={this.props.page}
                                         pageSize={this.props.pageSize}
+                                        history={this.props.history}
+                                        schemaName={schemaName}
                                     />
                                 </div>
                         }
@@ -273,7 +275,7 @@ class UpdateTableButton extends Component {
                         return (
                             <Mutation
                                 mutation={gql(UPDATE_SCHEMA)}
-                                refetchQueries={[{query: gql(SHOW_TABLE), variables: {schema_id: this.props.schemaID}}]}
+                                refetchQueries={[{query: gql(SHOW_TABLE), variables: {schema_id: schemaID}}]}
                             >
 
                                 {(update_schema, {loading, error}) => {
@@ -302,9 +304,9 @@ class UpdateTableButton extends Component {
                                         cols
                                     };
 
-                                    const index = this.state.originTableName === '' ? -2 : this.props.schemaData.findIndex(obj => obj.name === this.state.originTableName)
+                                    const index = this.state.originTableName === '' ? -2 : this.props.schemaData.findIndex(obj => obj.name === this.state.originTableName);
                                     if (index === -2) {
-                                        if(referenceID !== '') {
+                                        if(referenceID !== '' && schemaCols.length === 0) {
                                             this.props.fetchData(referenceID).then(value => {
                                                 schemaCols = JSON.parse(value);
                                                 schemaCols.push(newTable);
@@ -321,6 +323,7 @@ class UpdateTableButton extends Component {
                                             schemaCols.splice(index, 1, newTable);
                                         });
                                     } else {
+
                                         schemaCols.splice(index, 1, newTable);
                                     }
 
@@ -334,6 +337,13 @@ class UpdateTableButton extends Component {
                                                     }
                                                 });
                                                 this.props.showTablePagination(this.props.page, this.props.pageSize, schemaCols)
+                                                this.props.history.push({
+                                                    pathname: `/graphql-service/my-create/${this.props.schemaName}`,
+                                                    state:{
+                                                        schemaName:this.props.schemaName,
+                                                        schemaID:this.props.schemaID
+                                                    }
+                                                });
                                             }}>
                                                 save
                                             </Button>