Pārlūkot izejas kodu

微信服务project 删除ok wxConfig未删除

Csy817 7 gadi atpakaļ
vecāks
revīzija
d8af3fe480

+ 26 - 14
src/app/App.jsx

@@ -21,7 +21,7 @@ import Create from "./graphqlService/component/schema/Create";
 import WxCreate from "./wechatService/wxCreate/WxCreate";
 
 
-import {SHOW_ALL_SCHEMA, SHOW_CASE_SCHEMA,SHOW_PROJECT,CASE_SCHEMA_AND_PROJECT,CASE_WXCONFIG_AND_PROJECT} from "../gql";
+import {SHOW_ALL_SCHEMA, SHOW_CASE_SCHEMA,SHOW_PROJECT,CASE_AND_PROJECT} from "../gql";
 import axios from 'axios';
 import {getCookie, setCookie} from "../cookie";
 
@@ -358,7 +358,7 @@ class GraphqlSidebar extends Component {
 
     render() {
         return (
-            <Query query={gql(CASE_SCHEMA_AND_PROJECT)} variables={{projectType:'graphql',user_id: this.state.userID}}>
+            <Query query={gql(CASE_AND_PROJECT)} variables={{projectType:'graphql',user_id: this.state.userID}}>
                 {
                     ({loading, error, data}) => {
                         if (loading) return <Spin style={{marginLeft: 3}}/>;
@@ -460,7 +460,7 @@ class WxConfigSiderbar extends Component {
 
     render() {
         return (
-            <Query query={gql(CASE_WXCONFIG_AND_PROJECT)} variables={{projectType:'wx',user_id: this.state.userID}}>
+            <Query query={gql(CASE_AND_PROJECT)} variables={{projectType:'wx',user_id: this.state.userID}}>
                 {
                     ({loading, error, data}) => {
                         console.log('CASE_WXCONFIG_AND_PROJECT data', data);
@@ -489,16 +489,26 @@ class WxConfigSiderbar extends Component {
                                     <span><FormattedMessage id="Case Show"/></span>
                                 </span>}>
                                     {
-                                        data.caseWxConfig.map((config) =>
-                                            <Menu.Item key={config.appName}>
-                                                <Link to={{
-                                                    pathname: `/wechat-service/trial-case/${config.appName}`,
-                                                    state: {
-                                                        appName: config.appName,
-                                                        configID: config.id
-                                                    }
-                                                }}>{config.appName}</Link>
-                                            </Menu.Item>)
+                                        data.caseProject.map((project) => {
+                                            if(project){
+                                                let appName = project.wxConfig_id.appName;
+                                                let configID = project.wxConfig_id.id;
+                                                let projectID = project.id;
+                                                return (
+                                                    <Menu.Item key={appName}>
+                                                        <Link to={{
+                                                            pathname: `/wechat-service/trial-case/${appName}`,
+                                                            state: {
+                                                                appName,
+                                                                configID,
+                                                                projectID
+                                                            }
+                                                        }}>{appName}</Link>
+                                                    </Menu.Item>
+                                                )
+                                            }
+                                            return false;
+                                        })
                                     }
                                 </SubMenu>
 
@@ -521,13 +531,15 @@ class WxConfigSiderbar extends Component {
                                             if(project){
                                                 let appName = project.wxConfig_id.appName;
                                                 let configID = project.wxConfig_id.id;
+                                                let projectID = project.id;
                                                 return (
                                                     <Menu.Item key={appName}>
                                                         <Link to={{
                                                             pathname: `/wechat-service/my-create/${appName}`,
                                                             state: {
                                                                 appName,
-                                                                configID
+                                                                configID,
+                                                                projectID
                                                             }
                                                         }}>{appName}</Link>
                                                     </Menu.Item>

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

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

+ 4 - 14
src/app/graphqlService/component/schema/Schema.jsx

@@ -591,13 +591,13 @@ class DeleteProjectButton extends Component {
         }
     }
 
-    showConfirm = (delete_project_and_schema, projectID, userID) => {
+    showConfirm = (delete_graphql_project, 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: {id:projectID, user_id: userID}});
+                delete_graphql_project({variables: {id:projectID, user_id: userID}});
                 _this.props.history.push({
                     pathname: '/graphql-service',
                 });
@@ -615,18 +615,8 @@ class DeleteProjectButton extends Component {
             <Mutation
                 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}});
-                //
-                //     data.project.splice(data.project.findIndex(obj => obj.projectName === schemaName), 1);
-                //     cache.writeQuery({
-                //         query: gql(SHOW_PROJECT),
-                //         variables:  {projectType:"graphql",user_id: userID},
-                //         data
-                //     });
-                // }}
             >
-                {(delete_project_and_schema, {loading, error}) => {
+                {(delete_graphql_project, {loading, error}) => {
                     if (error)
                         return 'error';
                     if (loading)
@@ -635,7 +625,7 @@ class DeleteProjectButton extends Component {
                         <Button
                             type="danger"
                             onClick={() => {
-                                this.showConfirm(delete_project_and_schema, projectID, userID);
+                                this.showConfirm(delete_graphql_project, projectID, userID);
                             }}
                         >
                             <FormattedMessage id="delete"/>

+ 1 - 1
src/app/wechatService/WxTrialCase.js

@@ -53,7 +53,7 @@ class WxTrialCase extends Component {
                         {(() => {
                             switch (this.state.menuLevel3) {
                                 case 'wechat-config':
-                                    return <WxConfig defaultAppName={'ecommerce'} defaultConfigID={'ecommerce_wxConfigID'} trialcase={true} history={this.props.history} location={this.props.location}/>;
+                                    return <WxConfig projectID={projectID} defaultAppName={'ecommerce'} defaultConfigID={'ecommerce_wxConfigID'} trialcase={true} history={this.props.history} location={this.props.location}/>;
                                 case 'wechat-deploy':
                                     return <WxDeploy trialcase={true} userID={this.state.userID} configID={configID}/>;
                                 case 'wechat-manage':

+ 2 - 1
src/app/wechatService/WxUserCreate.js

@@ -48,6 +48,7 @@ class WxUserCreate extends Component {
         let configID = this.props.location.state ? this.props.location.state.configID : "ecommerce_wxConfigID";
         let appName = this.props.location.state ? this.props.location.state.appName : "ecommerce";
         let projectID = this.props.location.state ? this.props.location.state.projectID : "";
+        // console.log('userId',this.state.userID,"projectID",projectID);
         return (
             <div>
                 <Menu
@@ -74,7 +75,7 @@ class WxUserCreate extends Component {
                         {(() => {
                             switch (this.state.menuLevel3) {
                                 case 'wechat-config':
-                                    return <WxConfig history={this.props.history} location={this.props.location}/>;
+                                    return <WxConfig projectID={projectID}  userID={this.state.userID} history={this.props.history} location={this.props.location}/>;
                                 case 'wechat-deploy':
                                     return <WxDeploy trialcase={false} userID={this.state.userID} configID={configID}/>;
                                 case 'wechat-manage':

+ 31 - 15
src/app/wechatService/wxConfig/WxConfig.jsx

@@ -1,7 +1,7 @@
 import React, {Component} from 'react';
 import {Input, Spin, Button, Icon, Modal} from 'antd';
 import './index.css';
-import {UPDATE_WXCONFIG, SHOW_WXCONTENT, DELETE_WXCONFIG, SHOW_WXCONFIG} from "../../../gql";
+import {UPDATE_WXCONFIG, SHOW_WXCONTENT, DELETE_WXCONFIG, SHOW_WXCONFIG,DELETE_PROJECT,SHOW_PROJECT} from "../../../gql";
 import gql from "graphql-tag";
 import {Mutation, Query} from "react-apollo";
 import {getCookie} from "../../../cookie";
@@ -15,13 +15,17 @@ class WxConfig extends Component {
             configs: ['appName', 'appID', 'appSecret', 'enter_url', 'token', 'welcome_words', 'pay_api_key', 'attach', 'mch_id', 'body', 'spbill_create_ip', 'notify_url'],
             configID: props.location.state === undefined ? props.defaultConfigID : props.location.state.configID,
             appName: props.location.state === undefined ? props.defaultAppName : props.location.state.appName,
+            projectID: props.location.state === undefined ? props.projectID : props.location.state.projectID,
+            userID:props.userID
         }
     }
 
     componentWillReceiveProps(next) {
         this.setState({
+            userID:next.userID,
             configID: next.location.state === undefined ? next.defaultConfigID : next.location.state.configID,
             appName: next.location.state === undefined ? next.defaultAppName : next.location.state.appName,
+            projectID: next.location.state === undefined ? next.projectID : next.location.state.projectID,
         });
     }
 
@@ -37,10 +41,12 @@ class WxConfig extends Component {
                             return 'error!';
                         }
                         let {history, location, trialcase} = this.props;
-                        let {appName, configID, configs} = this.state;
+                        let {appName, configID, configs,projectID,userID} = this.state;
                         return (
                             <Display
                                 configs={configs}
+                                userID={userID}
+                                projectID={projectID}
                                 configID={configID}
                                 appName={appName}
                                 location={location}
@@ -62,8 +68,10 @@ class Display extends Component {
     constructor(props) {
         super(props);
         this.state = {
+            userID:props.userID,
             configID: props.configID,
             appName: props.appName,
+            projectID:props.projectID,
             mch_id: props.data === null ? '' : props.data.mch_id,
             notify_url: props.data === null ? '' : props.data.notify_url,
             appSecret: props.data === null ? '' : props.data.appSecret,
@@ -80,8 +88,10 @@ class Display extends Component {
 
     componentWillReceiveProps(next) {
         this.setState({
+            userID:next.userID,
             configID: next.configID,
             appName: next.appName,
+            projectID:next.projectID,
             mch_id: next.data === null ? '' : next.data.mch_id,
             notify_url: next.data === null ? '' : next.data.notify_url,
             appSecret: next.data === null ? '' : next.data.appSecret,
@@ -107,7 +117,7 @@ class Display extends Component {
 
     render() {
         let {configs} = this.props;
-        let {configID, appName, mch_id, notify_url, appSecret, appID, token, spbill_create_ip, enter_url, pay_api_key, body, welcome_words, attach} = this.state;
+        let {userID,configID, appName,projectID, mch_id, notify_url, appSecret, appID, token, spbill_create_ip, enter_url, pay_api_key, body, welcome_words, attach} = this.state;
         return (
             <div>
                 {
@@ -139,8 +149,10 @@ class Display extends Component {
                                 welcome_words={welcome_words}
                                 attach={attach}
                             />
-                            <DeleteWXConfigButton
+                            <DeleteWXProjectButton
                                 id={configID}
+                                userID={userID}
+                                projectID={projectID}
                                 history={this.props.history}
                             />
                         </div>
@@ -194,21 +206,22 @@ class UpdateWXConfigButton extends Component {
     }
 }
 
-class DeleteWXConfigButton extends Component {
+class DeleteWXProjectButton extends Component {
     constructor(props) {
         super(props);
         this.state = {
-            userID: getCookie('user_id')
+            userID: props.userID,
+            projectID:props.projectID
         }
     }
 
-    showConfirm = (delete_wxConfig, id) => {
+    showConfirm = (delete_wx_project,  projectID, userID) => {
         let _this = this;
         confirm({
             title: 'Do you want to delete this config?',
             content: 'It cannot be found back!',
             onOk() {
-                delete_wxConfig({variables: {id}});
+                delete_wx_project({variables: {id:projectID, user_id: userID}});
                 _this.props.history.push({
                     pathname: `/wechat-service/trial-case/index`,
                 });
@@ -219,21 +232,24 @@ class DeleteWXConfigButton extends Component {
     };
 
     render() {
+        let {userID,projectID} = this.state;
+
         return (
             <Mutation
-                mutation={gql(DELETE_WXCONFIG)}
-                refetchQueries={[{query: gql(SHOW_WXCONFIG), variables: {user_id: this.state.userID}}]}
+                mutation={gql(DELETE_PROJECT)}
+                refetchQueries={[{query: gql(SHOW_PROJECT), variables: {projectType:'wx',user_id: userID}}]}
             >
-                {(delete_wxConfig, {loading, error}) => {
+                {(delete_wx_project, {loading, error}) => {
                     if (loading)
                         return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
                     if (error)
                         return 'error';
-                    let {id} = this.props;
                     return (
-                        <Button type={'danger'} onClick={() => {
-                            this.showConfirm(delete_wxConfig, id);
-                        }}>delete</Button>
+                        <Button
+                            type={'danger'}
+                            onClick={() => {
+                                this.showConfirm(delete_wx_project, projectID, userID);
+                            }}>delete</Button>
                     )
                 }}
             </Mutation>

+ 3 - 45
src/gql.js

@@ -345,8 +345,8 @@ const ADD_PROJECT_AND_WX = `
                  }
              `;
 
-const CASE_SCHEMA_AND_PROJECT = `
-            query CASE_SCHEMA_AND_PROJECT($user_id: ID, $projectType: String ) {
+const CASE_AND_PROJECT = `
+            query CASE_AND_PROJECT($user_id: ID, $projectType: String ) {
                 caseProject:project_by_props(
                     projectType: $projectType,
                     user_id: "ioobot"
@@ -395,47 +395,6 @@ const CASE_SCHEMA_AND_PROJECT = `
             }
          `;
 
-const CASE_WXCONFIG_AND_PROJECT = `
-            query CASE_WXCONFIG_AND_PROJECT($user_id: ID, $projectType: String ) {
-                caseWxConfig:wxConfig_by_props(user_id: "ioobot") {
-                    appID
-                    appName
-                    appSecret
-                    attach
-                    body
-                    enter_url
-                    id
-                    mch_id
-                    notify_url
-                    pay_api_key
-                    spbill_create_ip
-                    token
-                    welcome_words
-                }
-                
-                project:project_by_props(
-                    projectType: $projectType,
-                    user_id: $user_id
-                ) {
-                    updatedAt
-                    apiGWGroup_id {
-                        id
-                    }
-                    createdAt
-                    projectName
-                    id
-                    projectType
-                    wxConfig_id {
-                        id
-                        appName
-                    }
-                    schema_id {
-                        id
-                    }
-                }
-            }
-         `;
-
 const SHOW_PROJECT = `
              query PROJECT_BY_PROPS($projectType: String, $user_id: ID) {
                  project:project_by_props(
@@ -967,8 +926,7 @@ export {
     DELETE_PROJECT,
     SHOW_TABLE,
     ADD_PROJECT_AND_SCHEMA,
-    CASE_SCHEMA_AND_PROJECT,
-    CASE_WXCONFIG_AND_PROJECT,
+    CASE_AND_PROJECT,
     SHOW_PROJECT,
     ADD_CLOUD,
     SHOW_CLOUD,