import React, {Component} from 'react'; import {Row, Col, Input, Icon, Button} from 'antd'; import './index.css'; import Change from './change'; const Search = Input.Search; class Schema extends Component { constructor(props) { super(props); this.state = { currentSchema: 'magazine', currentTable: 'user', switch: true } } changeSchema = (schema) => { return () => { this.setState({ currentSchema: schema }) } }; changeTable = (table) => { return () => { this.setState({ currentTable: table }) } }; findColumns = () => { let schema = this.props.schemas.find(schema => schema.name === this.state.currentSchema); if(schema === undefined) return []; // if user insert a new schema, after merge to schemas with a {name: 'xx', tables: []} // you can find the following table is undefined. // so give a state here if you want add a tip! else { let table = schema.tables.find(table => table.name === this.state.currentTable); if(table === undefined) return []; else return table.cols; } }; render() { return (
{this.state.currentSchema}
{ this.state.switch? : { this.setState({ switch: true, currentSchema: value, currentTable: '' }); this.props.addSchema(value); }} disabled={this.state.switch} /> }
console.log(value)} style={{marginTop: 10}} /> { this.props.schemas.map((schema) => { return
Schemas: ({schema.name}) ({schema.tables.length})
}) } { this.state.currentTable === 'add' ? : }
) } } export default Schema; class AddTable extends Component { constructor(props) { super(props); this.state = { columns: [] } } render() { return (
Add a new table to {this.props.currentSchema}
) } } class ShowTable extends Component { render() { return (
{this.props.currentSchema} > {this.props.currentTable}
) } }