import React, {Component} from 'react'; import {Layout, Select, Input, Icon, Button, notification, Spin} from 'antd'; import {UPDATE_SCHEMA, SHOW_SCHEMA, SHOW_TABLE} from "../../gql"; import gql from "graphql-tag"; import {Mutation, Query} from "react-apollo"; import {getCookie} from "../../cookie"; const Option = Select.Option; const {Content} = Layout; class Table extends Component { constructor(props) { super(props); this.state = { currentTable: props.currentTable, remark: props.remark, columns: props.columns, newColName: '', newColType: 'type', types: ['ID', 'String', 'Int', 'Float', 'Boolean', 'DateTime'], descriptions: ['description', 'key', 'non-null', 'non-null-list', 'list'], characterTips: false } } // 下面的 handlexxxx 全是 state 内部方法,用于操作视图 // cache 仅在提交删除整体使用 handleNameChange = (index) => { return (e) => { let columns = this.state.columns; columns[index].name = e.target.value; this.setState({ columns }) }; }; handleNameNew = (e) => { let r = /^[^\u4e00-\u9fa5]*$/; if(r.test(e.target.value)){ this.setState({ newColName: e.target.value, }) } else { this.setState({ characterTips: true }); setTimeout(()=>{ this.setState({ characterTips: false }) }, 2000) } }; handleTypeChange = (index) => { return (value) => { let columns = this.state.columns; columns[index].type = value; this.setState({ columns }); } }; handleTypeNew = (value) => { if (this.state.newColName !== '') { let columns = this.state.columns; columns.push({name: this.state.newColName, type: value, description: 'description'}); this.setState({ columns, newColName: '', newColType: 'type' }) } else { notification['warning']({ message: 'Notification', description: 'Input a field name first.', }); } }; handleDescChange = (index) => { return (value) => { let columns = this.state.columns; columns[index].description = value; this.setState({ columns }); }; }; handleColDelete = (index) => { return () => { let columns = this.state.columns; columns.splice(index, 1); this.setState({ columns }); } }; componentWillReceiveProps(next) { this.setState({ currentTable: next.currentTable, columns: next.columns, remark: next.remark }); }; render() { // console.log('columns',this.state.columns); // console.log('this.props',this.props); let schemaID = this.props.schemaID || this.props.history.location.state.schemaID; let schemaName = this.props.schemaName || this.props.history.location.state.schemaName; // console.log('schemaID',schemaID,'schemaName',schemaName); let userID = this.props.userID || getCookie('user_id'); // console.log('schemaID',schemaID,'userID',userID); let trialcase = this.props.trialcase; return (