Răsfoiți Sursa

找到 copy 一定几率不显示的 问题原因,异步导致的未存先取,已解决

xy 7 ani în urmă
părinte
comite
ff02fbbdbc

+ 16 - 5
src/components/common/schema/Schema.jsx

@@ -30,8 +30,8 @@ class Schema extends Component {
         this.state = {
             currentTable: props.location.state === undefined ? '' : props.location.state.create ? 'add' : '',
             // default schemaID and schemaName
-            schemaID: props.schemaID || props.location.state.schemaID,
-            schemaName: props.schemaName || props.location.state.schemaName,
+            schemaID: props.location.state === undefined ? props.schemaID : props.location.state.schemaID,
+            schemaName: props.location.state === undefined ? props.schemaName : props.location.state.schemaName,
             editSchemaName: '',
             allData: '',
             data: '',
@@ -41,6 +41,10 @@ class Schema extends Component {
         };
     }
 
+    shouldComponentUpdate(nextProps,nextState) {
+        return true;
+    }
+
     switchTable = (table) => {
         this.setState({
             currentTable: table
@@ -155,10 +159,15 @@ class Schema extends Component {
 
                         // let schemaName = data.schema_by_id.schemaName;
 
-                        if (data.schema_by_id === null) data = [];
+                        let copy;
+                        if(this.props.location.state)
+                            copy = this.props.location.state.copy;
+
+                        // 找到 copy 一定几率不显示的 问题原因,异步导致的未存先取
+                        if (data.schema_by_id === null && copy!==true) data = [];
                         else {
-                            let reference = data.schema_by_id.reference;
-                            data = JSON.parse(data.schema_by_id.schemaData);
+                            let reference = data.schema_by_id ? data.schema_by_id.reference : this.props.location.state.reference;
+                            data = data.schema_by_id ? JSON.parse(data.schema_by_id.schemaData) : [];
                             if (data.length === 0 && reference !== '' && this.state.once === 0) {
                                 this.fetchData(reference).then((data) => {
                                     // 会执行好多好多次
@@ -451,6 +460,8 @@ class CopySchemaButton extends Component {
                                         state: {
                                             schemaName: varObj.schemaName,
                                             schemaID: varObj.id,
+                                            copy: true,
+                                            reference: varObj.reference
                                         }
                                     });
                                 }}

+ 1 - 1
src/components/userCreate/UserCreate.jsx

@@ -70,7 +70,7 @@ class UserCreate extends Component {
                             (() => {
                                 switch (this.state.menuLevel2) {
                                     case 'schema':
-                                        return <Schema userID={this.state.userID} schemaName={schemaName} schemaID={schemaID} history={this.props.history} location={this.props.location}/>;
+                                        return <Schema trialcase={false} userID={this.state.userID} schemaName={schemaName} schemaID={schemaID} history={this.props.history} location={this.props.location}/>;
                                     case 'deploy':
                                         return <Deploy userID={this.state.userID} schemaID={schemaID} schemaName={schemaName}/>;
                                     case 'graphiql':