瀏覽代碼

remote delete schema

ioobot 7 年之前
父節點
當前提交
35fac4b677
共有 3 個文件被更改,包括 59 次插入13 次删除
  1. 2 3
      src/app/index.js
  2. 45 1
      src/schema/change/index.js
  3. 12 9
      src/schema/index.js

+ 2 - 3
src/app/index.js

@@ -2,7 +2,7 @@ import React, {Component} from 'react';
 import Config from '../config';
 import Schema from '../schema';
 import Graphql from "../graphiql";
-import {Layout, Menu, Input, Button} from 'antd';
+import {Layout, Menu, Input, Button, Spin} from 'antd';
 
 import '../graphiql/index.css';
 import logo from './logo.png';
@@ -48,7 +48,7 @@ class App extends Component {
         {
           ({loading, error, data}) => {
             if (loading) {
-              return 'loading...';
+              return <Spin style={{marginLeft: 3}}/>
             }
             if (error) {
               return 'error!';
@@ -133,7 +133,6 @@ class App extends Component {
           </div>
         </Header>
         <Content style={{padding: '0 50px', height: '100%'}}>
-
           <div>
             {
               (() => {

+ 45 - 1
src/schema/change/index.js

@@ -1,6 +1,7 @@
 import React, {Component} from 'react';
 
 import {Select, Input, Icon, Button, notification} from 'antd';
+import gql from "graphql-tag";
 
 const Option = Select.Option;
 
@@ -169,4 +170,47 @@ class Change extends Component {
   }
 }
 
-export default Change;
+export default Change;
+
+class UpdateSchemaButtons extends Component {
+
+//   update_schema(
+//     createdAt: String
+//   id: ID!
+//   schemaData: String
+//   schemaName: String
+//   schemaState: String
+//   updatedAt: String
+//   user_id: String
+// ): Schema
+
+
+  render(){
+    let varobj = {
+      user_id: this.props.userID,
+      updatedAt: new Date().getTime(),
+      schemaState: 'create',
+      id: this.props.schemaID
+    };
+
+    const ADD_SCHEMA = gql`
+      mutation SCHEMA($id: ID!, $user_id: String!, $schemaName: String!, $schemaData: String!, $createdAt: String, $updatedAt: String, $schemaState: String) {
+        create_schema(
+          id: $id,
+          user_id: $user_id,
+          schemaName: $schemaName,
+          createdAt: $createdAt,
+          updatedAt: $updatedAt,
+          schemaData: $schemaData,
+          schemaState: $schemaState
+        ) {
+            id,
+            schemaName
+        }
+      }
+    `;
+    return (
+      <div>1</div>
+    )
+  }
+}

+ 12 - 9
src/schema/index.js

@@ -1,6 +1,6 @@
 import React, {Component} from 'react';
 
-import {Row, Col, Input, Icon, Button} from 'antd';
+import {Row, Col, Input, Icon, Button, Spin} from 'antd';
 import './index.css';
 import Change from './change';
 import gql from "graphql-tag";
@@ -279,7 +279,7 @@ class Schema extends Component {
                     <Col span={4}>
                       <Button onClick={() => this.setState({currentTable: 'add'})} type="primary"
                               shape="circle" icon="plus" size='small'/>
-                      <DeleteSchemaButton shcemaName={schema.name} deleteSchema={this.deleteSchema}/>
+                      <DeleteSchemaButton schemaName={schema.name} deleteSchema={this.deleteSchema}/>
                     </Col>
                   </Row>
 
@@ -347,8 +347,12 @@ class AddSchemaInput extends Component {
 
     return (
       <Mutation mutation={ADD_SCHEMA}>
-        {(create_schema, {data}) => {
+        {(create_schema, {loading, error}) => {
           // console.log(data);
+          if (loading)
+            return <Spin style={{marginLeft: 30, marginTop: 10}}/>
+          if (error)
+            return 'error';
           return (
             <div>
               <Search
@@ -386,20 +390,19 @@ class DeleteSchemaButton extends Component {
     const DELETE_SCHEMA = gql`
       mutation SCHEMA($schemaName: String) {
         delete_schema(schemaName: $schemaName) 
-        {
-            id,
-            schemaName
-        }
       }
     `;
     return (
       <Mutation mutation={DELETE_SCHEMA}>
-        {(delete_schema, {data}) => {
+        {(delete_schema, {loading, error}) => {
+          if (error)
+            return 'error';
+          if (loading)
+            return <Spin style={{marginLeft: 3}}/>;
           return (
             <Button onClick={(e) => {
               this.props.deleteSchema(e, this.props.schemaName);
               delete_schema({variables: {schemaName: this.props.schemaName}});
-              console.log(data);
             }} type="danger" shape="circle" icon="delete" size='small' style={{marginLeft: 3}}/>
           )
         }}