Ver Fonte

delete ok

xy há 7 anos atrás
pai
commit
6f5fdfbf2c
2 ficheiros alterados com 95 adições e 10 exclusões
  1. 88 10
      src/app/common/manage/TencentResult.js
  2. 7 0
      src/gql.js

+ 88 - 10
src/app/common/manage/TencentResult.js

@@ -3,6 +3,7 @@ import {FormattedMessage} from 'react-intl';
 import {Switch, Input, Icon, Spin, Row, Col, message} from 'antd';
 import {
     DELETE_APIGWPATH,
+    DELETE_APIGROUP,
     GET_PROJECT,
     SHOW_APIGWPATH,
     UPDATE_APIGROUP,
@@ -13,7 +14,7 @@ import gql from "graphql-tag";
 import {Query, Mutation} from "react-apollo";
 import copy from 'copy-to-clipboard';
 import axios from 'axios';
-import {removeFC, removeAPI, graphqlUrl} from "../../../config";
+import {removeAPI, graphqlUrl} from "../../../config";
 
 axios.defaults.withCredentials = true;
 
@@ -80,7 +81,18 @@ class TencentResult extends Component {
                                                                 :
                                                                 <SwitchStatus group={group}/>
                                                         }
-                                                        {/*<span className={'schema-table-content name'}>删除</span>*/}
+                                                        &nbsp;
+                                                        {
+                                                            this.props.trialcase ?
+                                                                ''
+                                                                :
+                                                                <DeleteGroupSpan
+                                                                cloudID={cloudID}
+                                                                groupID={group.id}
+                                                                projectID={projectID}
+                                                                userID={this.props.userID}
+                                                            />
+                                                        }
                                                     </span>
                                                     </Col>
                                                 </Row>
@@ -94,6 +106,7 @@ class TencentResult extends Component {
                                                     cloudID={cloudID}
                                                     projectID={projectID}
                                                     userID={this.props.userID}
+                                                    trialcase={this.props.trialcase}
                                                 />
                                             </div>
                                         </div>
@@ -221,14 +234,6 @@ class APIGWPathResult extends Component {
                                                                 <span className={'schema-table-content'}>{path.apiGWDesc}</span>
                                                             </Col>
                                                             <Col span={3}>
-                                                                <DeletePathSpan
-                                                                    cloudID={this.props.cloudID}
-                                                                    groupID={id}
-                                                                    path={path}
-                                                                    projectID={this.props.projectID}
-                                                                    userID={this.props.userID}
-                                                                />
-                                                                &nbsp;
                                                                 {
                                                                     projectType === 'graphql'?
                                                                         <span className={'schema-table-content name'}
@@ -240,6 +245,19 @@ class APIGWPathResult extends Component {
                                                                         :
                                                                         ''
                                                                 }
+                                                                &nbsp;
+                                                                {
+                                                                    this.props.trialcase?
+                                                                        ''
+                                                                        :
+                                                                        <DeletePathSpan
+                                                                            cloudID={this.props.cloudID}
+                                                                            groupID={id}
+                                                                            path={path}
+                                                                            projectID={this.props.projectID}
+                                                                            userID={this.props.userID}
+                                                                        />
+                                                                }
 
                                                             </Col>
                                                         </Row>
@@ -322,4 +340,64 @@ class DeletePathSpan extends Component {
             </Mutation>
         )
     }
+}
+
+class DeleteGroupSpan extends Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+        }
+    }
+
+    render() {
+        let {projectID, cloudID, groupID, userID} = this.props;
+        return (
+            <Mutation
+                mutation={gql(DELETE_APIGROUP)}
+                refetchQueries={[{query: gql(GET_PROJECT), variables: {id: projectID}}]}
+            >
+                {(delete_apiGWGroup, {loading, error}) => {
+                    if (error)
+                        return 'error';
+                    if (loading)
+                        return <Spin style={{marginLeft: 3}}/>;
+
+                    return (
+                        <span className={'schema-table-content name'} onClick={() => {
+                            axios.get(`${removeAPI}`, {
+                                params: {
+                                    'cloud-id': `${cloudID}`,
+                                    'group-id': `${groupID}`,
+                                }
+                            })
+                                .then((res) => {
+                                    console.log('delete service');
+                                    if (res.data !== '') {
+
+                                        delete_apiGWGroup({variables: {id: groupID, user_id: userID}});
+
+                                        // 写回 project 状态
+                                        request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, {
+                                            id: projectID,
+                                            updatedAt: new Date().getTime(),
+                                            projectStatus: 'functioned'
+                                        });
+
+                                        console.log(res.data);
+                                    } else {
+                                        console.log('error');
+                                    }
+                                })
+                                .catch((err) => {
+                                    console.log(err);
+                                });
+                        }}
+                        >
+                            删除
+                        </span>
+                    )
+                }}
+            </Mutation>
+        )
+    }
 }

+ 7 - 0
src/gql.js

@@ -583,6 +583,12 @@ const UPDATE_APIGROUP = `
             }
         `;
 
+const DELETE_APIGROUP = `
+            mutation deleteapiGWGroup($id: ID, $user_id: ID) {
+                delete_apiGWGroup(id: $id user_id: $user_id)
+            }
+        `;
+
 const SHOW_APIGWPATH = `
             query PATH($apiGWGroup_id: ID!) {
                 apiGWPath_by_props(apiGWGroup_id: $apiGWGroup_id) {
@@ -1003,6 +1009,7 @@ export {
     UPDATE_DEPLOY,
     ADD_APIGROUP,
     UPDATE_APIGROUP,
+    DELETE_APIGROUP,
     SHOW_APIGWPATH,
     ADD_APIGWPATH,
     UPDATE_APIGWPATH,