Kaynağa Gözat

修改project的删除,目前仅删除project,以后可增加如果schemaData为空可一并删除

Csy817 7 yıl önce
ebeveyn
işleme
7b1452eda3

+ 1 - 1
src/app/graphqlService/TrialCase.jsx

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

+ 15 - 18
src/app/graphqlService/component/schema/Schema.jsx

@@ -5,7 +5,7 @@ import './index.css';
 import {Mutation, Query} from "react-apollo";
 import gql from "graphql-tag";
 import {
-    DELETE_PROJECT_AND_SCHEMA,
+    DELETE_PROJECT,
     SHOW_SCHEMA,
     SHOW_TABLE,
     UPDATE_SCHEMA,
@@ -33,6 +33,7 @@ class Schema extends Component {
             // default schemaID and schemaName
             schemaID: props.location.state === undefined ? props.schemaID : props.location.state.schemaID,
             schemaName: props.location.state === undefined ? props.schemaName : props.location.state.schemaName,
+            projectID: props.location.state === undefined ? props.projectID : props.location.state.projectID,
             editSchemaName: '',
             allData: '',
             data: '',
@@ -391,20 +392,18 @@ class Schema extends Component {
                                                                         </div>
                                                                         <div style={{display: 'inline-block'}}
                                                                              className={'delete-schema'}>
-                                                                            <DeleteSchemaButton
+                                                                            <DeleteProjectButton
                                                                                 userID={userID}
-                                                                                schemaID={this.state.schemaID}
-                                                                                schemaName={this.state.schemaName}
+                                                                                projectID={this.state.projectID}
                                                                                 history={this.props.history}
                                                                             />
                                                                         </div>
                                                                     </div>
                                                                     :
                                                                     <div className={'delete-schema'}>
-                                                                        <DeleteSchemaButton
+                                                                        <DeleteProjectButton
                                                                             userID={userID}
-                                                                            schemaID={this.state.schemaID}
-                                                                            schemaName={this.state.schemaName}
+                                                                            projectID={this.state.projectID}
                                                                             history={this.props.history}
                                                                         />
                                                                     </div>
@@ -420,10 +419,9 @@ class Schema extends Component {
                                                                     </div>
                                                                     :
                                                                     <div className={'delete-schema'}>
-                                                                        <DeleteSchemaButton
+                                                                        <DeleteProjectButton
                                                                             userID={userID}
-                                                                            schemaID={this.state.schemaID}
-                                                                            schemaName={this.state.schemaName}
+                                                                            projectID={this.state.projectID}
                                                                             history={this.props.history}
                                                                         />
                                                                     </div>
@@ -585,22 +583,21 @@ class CopySchemaButton extends Component {
     }
 }
 
-class DeleteSchemaButton extends Component {
+class DeleteProjectButton extends Component {
     constructor(props) {
         super(props);
         this.state = {
-            schemaName: props.schemaName,
-            schemaId:props.schemaID
+            projectID:props.projectID
         }
     }
 
-    showConfirm = (delete_project_and_schema, schemaId, userID) => {
+    showConfirm = (delete_project_and_schema, projectID, userID) => {
         let _this = this;
         confirm({
             title: 'Do you want to delete this schema?',
             content: 'It cannot be found back!',
             onOk() {
-                delete_project_and_schema({variables: {schemaId, user_id: userID}});
+                delete_project_and_schema({variables: {id:projectID, user_id: userID}});
                 _this.props.history.push({
                     pathname: '/graphql-service',
                 });
@@ -612,11 +609,11 @@ class DeleteSchemaButton extends Component {
 
     render() {
         let userID = this.props.userID;
-        let {schemaName,schemaId} = this.state;
+        let {projectID} = this.state;
 
         return (
             <Mutation
-                mutation={gql(DELETE_PROJECT_AND_SCHEMA)}
+                mutation={gql(DELETE_PROJECT)}
                 refetchQueries={[{query: gql(SHOW_PROJECT), variables: {projectType:'graphql',user_id: userID}}]}
                 // update={(cache) => {
                 //     let data = cache.readQuery({query: gql(SHOW_PROJECT), variables: {projectType:"graphql",user_id: userID}});
@@ -638,7 +635,7 @@ class DeleteSchemaButton extends Component {
                         <Button
                             type="danger"
                             onClick={() => {
-                                this.showConfirm(delete_project_and_schema, schemaId, userID);
+                                this.showConfirm(delete_project_and_schema, projectID, userID);
                             }}
                         >
                             <FormattedMessage id="delete"/>

+ 4 - 5
src/gql.js

@@ -460,10 +460,9 @@ const SHOW_PROJECT = `
              }
          `;
 
-const DELETE_PROJECT_AND_SCHEMA = `
-            mutation DELETE_PROJECT_AND_SCHEMA($schemaId: ID, $user_id: ID) {
-                delete_schema(id: $schemaId, user_id: $user_id)
-                delete_project(schema_id: $schemaId, user_id: $user_id)
+const DELETE_PROJECT = `
+            mutation DELETE_PROJECT($id: ID, $user_id: ID) {
+                delete_project(id: $id, user_id: $user_id)
             }
         `;
 
@@ -965,7 +964,7 @@ export {
     UPDATE_SCHEMA,
     UPDATE_SCHEMA_PROJECT_NAME,
     DELETE_SCHEMA,
-    DELETE_PROJECT_AND_SCHEMA,
+    DELETE_PROJECT,
     SHOW_TABLE,
     ADD_PROJECT_AND_SCHEMA,
     CASE_SCHEMA_AND_PROJECT,