|
|
@@ -103,10 +103,10 @@ class Table extends Component {
|
|
|
|
|
|
render() {
|
|
|
// console.log('columns',this.state.columns);
|
|
|
- console.log('this.props',this.props);
|
|
|
+ // 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);
|
|
|
+ // console.log('schemaID',schemaID,'schemaName',schemaName);
|
|
|
let userID = this.props.userID || getCookie('user_id');
|
|
|
// console.log('schemaID',schemaID,'userID',userID);
|
|
|
|
|
|
@@ -208,16 +208,6 @@ class Table extends Component {
|
|
|
schemaID={schemaID}
|
|
|
userID={userID}
|
|
|
/>
|
|
|
- {/*{*/}
|
|
|
- {/*// undefined的时候 上层未传进来 currentTable === 'add',为的是输入框内不默认显示 add*/}
|
|
|
- {/*this.state.currentTable === '' ? '' : this.state.currentTable === undefined ? '' :*/}
|
|
|
- {/*<DeleteTableButton*/}
|
|
|
- {/*currentTable={this.state.currentTable}*/}
|
|
|
- {/*currentTableIndex={this.props.currentTableIndex}*/}
|
|
|
- {/*schemaID={schemaID}*/}
|
|
|
- {/*userID={userID}*/}
|
|
|
- {/*/>*/}
|
|
|
- {/*}*/}
|
|
|
</div>
|
|
|
</Content>
|
|
|
</Layout>
|
|
|
@@ -346,120 +336,3 @@ class UpdateTableButton extends Component {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-class DeleteTableButton extends Component {
|
|
|
- render() {
|
|
|
- let schemaID = this.props.schemaID;
|
|
|
- let userID = this.props.userID;
|
|
|
-
|
|
|
- let varobj = {
|
|
|
- id: schemaID,
|
|
|
- updatedAt: new Date().getTime(),
|
|
|
- schemaState: 'updated-delete-table',
|
|
|
- };
|
|
|
-
|
|
|
- return (
|
|
|
- <Query query={gql(SHOW_TABLE)} variables={{schema_id: schemaID}}>
|
|
|
-
|
|
|
- {
|
|
|
- ({loading, error, data}) => {
|
|
|
- if (loading)
|
|
|
- return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
|
|
|
- if (error)
|
|
|
- return 'error';
|
|
|
-
|
|
|
- let schemaData = data;
|
|
|
-
|
|
|
- return (
|
|
|
- <Mutation
|
|
|
- mutation={gql(UPDATE_SCHEMA)}
|
|
|
- update={(cache, {data: {update_schema}}) => {
|
|
|
- let data = cache.readQuery({
|
|
|
- query: gql(SHOW_TABLE),
|
|
|
- variables: {schema_id: schemaID}
|
|
|
- });
|
|
|
- data.schema_by_id = update_schema;
|
|
|
-
|
|
|
- let showSchemaData = cache.readQuery({
|
|
|
- query: gql(SHOW_SCHEMA),
|
|
|
- variables: {user_id: userID}
|
|
|
- });
|
|
|
- let schemas = showSchemaData.schema_by_props;
|
|
|
- // console.log('schemas', schemas);
|
|
|
- let targetSchema = schemas.find(obj => obj.schemaName === update_schema.schemaName);
|
|
|
- // console.log('targetSchema', targetSchema);
|
|
|
- let targetSchemaIndex = schemas.findIndex(obj => obj.schemaName === update_schema.schemaName);
|
|
|
- // console.log('targetSchemaIndex', targetSchemaIndex);
|
|
|
- let targetTables = JSON.parse(schemas[targetSchemaIndex].schemaData);
|
|
|
- // console.log('targetTables', targetTables);
|
|
|
- let targetTableIndex = targetTables.findIndex(obj => obj.name === this.props.currentTable);
|
|
|
- // console.log('targetTableIndex', targetTableIndex);
|
|
|
- targetTables.splice(targetTableIndex, 1);
|
|
|
- // console.log('targetTablesAfterDelete', targetTables);
|
|
|
- let temp = {schemaData: JSON.stringify(targetTables)};
|
|
|
- // console.log('temp', temp);
|
|
|
- let tempSchema = {...targetSchema, ...temp};
|
|
|
- // console.log('tempSchema', tempSchema);
|
|
|
- showSchemaData.schema_by_props.splice(targetSchemaIndex, 1, tempSchema);
|
|
|
-
|
|
|
- cache.writeQuery(
|
|
|
- {
|
|
|
- query: gql(SHOW_TABLE),
|
|
|
- variables: {schema_id: schemaID},
|
|
|
- data
|
|
|
- },
|
|
|
- {
|
|
|
- query: gql(SHOW_SCHEMA),
|
|
|
- variables: {user_id: userID},
|
|
|
- showSchemaData
|
|
|
- }
|
|
|
- );
|
|
|
- }}
|
|
|
- >
|
|
|
-
|
|
|
- {(update_schema, {loading, error}) => {
|
|
|
- if (loading)
|
|
|
- return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
|
|
|
- if (error)
|
|
|
- return 'error';
|
|
|
-
|
|
|
- // 先 query 再 mutation,然后删除
|
|
|
- let schemaCols;
|
|
|
- if (schemaData.schema_by_id === null) schemaCols = [];
|
|
|
- else schemaCols = JSON.parse(schemaData.schema_by_id.schemaData);
|
|
|
-
|
|
|
- const index = this.props.currentTableIndex;
|
|
|
- // 设置-2 标志为新建页面,防止通过 tablename 被修改导致每次 index 都为 -1 从而修改最后一个
|
|
|
- if (index === -2) {
|
|
|
- console.log('初始页面')
|
|
|
- } else if (index === -1) {
|
|
|
- console.log('进行了一次删除操作 或 数据库信息不匹配');
|
|
|
- } else {
|
|
|
- schemaCols.splice(index, 1);
|
|
|
- }
|
|
|
-
|
|
|
- return (
|
|
|
- <div style={{display: 'inline-block'}}>
|
|
|
- <Button type="danger"
|
|
|
- onClick={() => {
|
|
|
- update_schema({
|
|
|
- variables: {
|
|
|
- ...varobj,
|
|
|
- schemaData: JSON.stringify(schemaCols)
|
|
|
- }
|
|
|
- });
|
|
|
- }}>
|
|
|
- DELETE
|
|
|
- </Button>
|
|
|
- </div>
|
|
|
- )
|
|
|
- }}
|
|
|
- </Mutation>
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- </Query>
|
|
|
- )
|
|
|
- }
|
|
|
-}
|