|
|
@@ -4,8 +4,8 @@ import {Row, Col, Input, Icon, Button, Spin} from 'antd';
|
|
|
import './index.css';
|
|
|
import {Mutation, Query} from "react-apollo";
|
|
|
import gql from "graphql-tag";
|
|
|
-import {SHOW_SCHEMA, ADD_SCHEMA, DELETE_SCHEMA, SHOW_TABLE} from '../../gql'
|
|
|
-import Table from './Table';
|
|
|
+import {SHOW_SCHEMA, DELETE_SCHEMA, SHOW_TABLE} from '../../gql'
|
|
|
+
|
|
|
|
|
|
const Search = Input.Search;
|
|
|
|
|
|
@@ -19,7 +19,7 @@ class Schema extends Component {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
currentTable: '',
|
|
|
- // 下面这两个参数跟 props 拿
|
|
|
+ // default schemaID and schemaName
|
|
|
schemaID: 'schema_1542243424669_92094965',
|
|
|
schemaName: 'ecommerce'
|
|
|
};
|
|
|
@@ -35,59 +35,83 @@ class Schema extends Component {
|
|
|
render() {
|
|
|
let userID = this.props.userID;
|
|
|
return (
|
|
|
- <div>
|
|
|
- <div>
|
|
|
- {this.state.schemaName}
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- <Row>
|
|
|
- <Col span={8}><span>Name</span></Col>
|
|
|
- <Col span={8}><span>Remark</span></Col>
|
|
|
- <Col span={8}><span><Icon type="plus"/></span></Col>
|
|
|
- </Row>
|
|
|
- <Table schemaID={this.state.schemaID}/>
|
|
|
- </div>
|
|
|
-
|
|
|
- {/*<Row>*/}
|
|
|
- {/*<Col span={17} offset={1}>*/}
|
|
|
- {/*{*/}
|
|
|
- {/*this.state.currentTable === 'add' ?*/}
|
|
|
- {/*<Column*/}
|
|
|
- {/*currentSchema={this.state.currentSchema}*/}
|
|
|
- {/*currentTableIndex={-2}*/}
|
|
|
- {/*columns={[]}*/}
|
|
|
- {/*remark=''*/}
|
|
|
- {/*userID={userID}*/}
|
|
|
- {/*schemaID={this.state.schemaID}*/}
|
|
|
- {/*/> :*/}
|
|
|
- {/*<Query query={gql(SHOW_TABLE)}*/}
|
|
|
- {/*variables={{schema_id: this.state.schemaID}}>*/}
|
|
|
- {/*{*/}
|
|
|
- {/*({loading, error, data}) => {*/}
|
|
|
- {/*if (loading)*/}
|
|
|
- {/*return <Spin style={{marginLeft: 30, marginTop: 10}}/>;*/}
|
|
|
- {/*if (error)*/}
|
|
|
- {/*return 'error';*/}
|
|
|
- {/*if (data.schema_by_id === null) data = [];*/}
|
|
|
- {/*else data = JSON.parse(data.schema_by_id.schemaData);*/}
|
|
|
- {/*return (*/}
|
|
|
- {/*<Column*/}
|
|
|
- {/*currentSchema={this.state.currentSchema}*/}
|
|
|
- {/*currentTable={this.state.currentTable}*/}
|
|
|
- {/*currentTableIndex={this.state.currentTable === '' ? -2 : data.findIndex(obj => obj.name === this.state.currentTable)}*/}
|
|
|
- {/*columns={this.findColumns(data)}*/}
|
|
|
- {/*remark={this.findRemark(data)}*/}
|
|
|
- {/*schemaID={this.state.schemaID}*/}
|
|
|
- {/*userID={userID}*/}
|
|
|
- {/*/>*/}
|
|
|
- {/*)*/}
|
|
|
- {/*}*/}
|
|
|
- {/*}*/}
|
|
|
- {/*</Query>*/}
|
|
|
- {/*}*/}
|
|
|
- {/*</Col>*/}
|
|
|
- {/*</Row>*/}
|
|
|
- </div>
|
|
|
+ <Query query={gql(SHOW_TABLE)} variables={{schema_id: this.props.schemaID || this.state.schemaID}}>
|
|
|
+
|
|
|
+ {
|
|
|
+ ({loading, error, data}) => {
|
|
|
+ if (loading) {
|
|
|
+ return <Spin style={{marginLeft: 3}}/>
|
|
|
+ }
|
|
|
+ if (error) {
|
|
|
+ return 'error!';
|
|
|
+ }
|
|
|
+ console.log(data);
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <div>
|
|
|
+ {data.schema_by_id.schemaName || this.state.schemaName}
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <Row>
|
|
|
+ <Col span={8}><span>Name</span></Col>
|
|
|
+ <Col span={8}><span>Remark</span></Col>
|
|
|
+ <Col span={8}><span><Icon type="plus"/></span></Col>
|
|
|
+ </Row>
|
|
|
+ </div>
|
|
|
+ {
|
|
|
+ JSON.parse(data.schema_by_id.schemaData).map(table => (
|
|
|
+ <Row key={table.name} className='show'>
|
|
|
+ <Col span={8}><span>{table.name}</span></Col>
|
|
|
+ <Col span={8}><span>{table.remark}</span></Col>
|
|
|
+ <Col span={8}><Icon type="delete"/></Col>
|
|
|
+ </Row>
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {/*<Row>*/}
|
|
|
+ {/*<Col span={17} offset={1}>*/}
|
|
|
+ {/*{*/}
|
|
|
+ {/*this.state.currentTable === 'add' ?*/}
|
|
|
+ {/*<Column*/}
|
|
|
+ {/*currentSchema={this.state.currentSchema}*/}
|
|
|
+ {/*currentTableIndex={-2}*/}
|
|
|
+ {/*columns={[]}*/}
|
|
|
+ {/*remark=''*/}
|
|
|
+ {/*userID={userID}*/}
|
|
|
+ {/*schemaID={this.state.schemaID}*/}
|
|
|
+ {/*/> :*/}
|
|
|
+ {/*<Query query={gql(SHOW_TABLE)}*/}
|
|
|
+ {/*variables={{schema_id: this.state.schemaID}}>*/}
|
|
|
+ {/*{*/}
|
|
|
+ {/*({loading, error, data}) => {*/}
|
|
|
+ {/*if (loading)*/}
|
|
|
+ {/*return <Spin style={{marginLeft: 30, marginTop: 10}}/>;*/}
|
|
|
+ {/*if (error)*/}
|
|
|
+ {/*return 'error';*/}
|
|
|
+ {/*if (data.schema_by_id === null) data = [];*/}
|
|
|
+ {/*else data = JSON.parse(data.schema_by_id.schemaData);*/}
|
|
|
+ {/*return (*/}
|
|
|
+ {/*<Column*/}
|
|
|
+ {/*currentSchema={this.state.currentSchema}*/}
|
|
|
+ {/*currentTable={this.state.currentTable}*/}
|
|
|
+ {/*currentTableIndex={this.state.currentTable === '' ? -2 : data.findIndex(obj => obj.name === this.state.currentTable)}*/}
|
|
|
+ {/*columns={this.findColumns(data)}*/}
|
|
|
+ {/*remark={this.findRemark(data)}*/}
|
|
|
+ {/*schemaID={this.state.schemaID}*/}
|
|
|
+ {/*userID={userID}*/}
|
|
|
+ {/*/>*/}
|
|
|
+ {/*)*/}
|
|
|
+ {/*}*/}
|
|
|
+ {/*}*/}
|
|
|
+ {/*</Query>*/}
|
|
|
+ {/*}*/}
|
|
|
+ {/*</Col>*/}
|
|
|
+ {/*</Row>*/}
|
|
|
+ </Query>
|
|
|
+
|
|
|
)
|
|
|
}
|
|
|
}
|