|
@@ -56,7 +56,7 @@ class SchemaChange extends Component {
|
|
|
handleTypeNew = (value) => {
|
|
handleTypeNew = (value) => {
|
|
|
if (this.state.newColName !== '') {
|
|
if (this.state.newColName !== '') {
|
|
|
let columns = this.state.columns;
|
|
let columns = this.state.columns;
|
|
|
- columns.push({name: this.state.newColName, type: value, desc: 'description'});
|
|
|
|
|
|
|
+ columns.push({name: this.state.newColName, type: value, description: 'description'});
|
|
|
this.setState({
|
|
this.setState({
|
|
|
columns,
|
|
columns,
|
|
|
newColName: '',
|
|
newColName: '',
|
|
@@ -73,7 +73,7 @@ class SchemaChange extends Component {
|
|
|
handleDescChange = (index) => {
|
|
handleDescChange = (index) => {
|
|
|
return (value) => {
|
|
return (value) => {
|
|
|
let columns = this.state.columns;
|
|
let columns = this.state.columns;
|
|
|
- columns[index].desc = value;
|
|
|
|
|
|
|
+ columns[index].description = value;
|
|
|
this.setState({
|
|
this.setState({
|
|
|
columns
|
|
columns
|
|
|
});
|
|
});
|
|
@@ -170,12 +170,19 @@ class SchemaChange extends Component {
|
|
|
remark={this.state.remark}
|
|
remark={this.state.remark}
|
|
|
currentTableIndex={this.props.currentTableIndex}
|
|
currentTableIndex={this.props.currentTableIndex}
|
|
|
schemaID={this.props.schemaID}
|
|
schemaID={this.props.schemaID}
|
|
|
-
|
|
|
|
|
- />
|
|
|
|
|
- <DeleteTableButton
|
|
|
|
|
- currentTableIndex={this.props.currentTableIndex}
|
|
|
|
|
- schemaID = {this.props.schemaID}
|
|
|
|
|
|
|
+ userID={this.props.userID}
|
|
|
/>
|
|
/>
|
|
|
|
|
+ {
|
|
|
|
|
+ // undefined的时候 上层未传进来 currentTable === 'add',为的是输入框内不默认显示 add
|
|
|
|
|
+ this.state.currentTable === ''? '' : this.state.currentTable === undefined ? '' :
|
|
|
|
|
+ <DeleteTableButton
|
|
|
|
|
+ currentTable={this.state.currentTable}
|
|
|
|
|
+ currentTableIndex={this.props.currentTableIndex}
|
|
|
|
|
+ schemaID={this.props.schemaID}
|
|
|
|
|
+ userID={this.props.userID}
|
|
|
|
|
+ />
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
@@ -189,6 +196,7 @@ class UpdateTableButton extends Component {
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
let schemaID = this.props.schemaID;
|
|
let schemaID = this.props.schemaID;
|
|
|
|
|
+ let userID = this.props.userID;
|
|
|
|
|
|
|
|
let varobj = {
|
|
let varobj = {
|
|
|
id: schemaID,
|
|
id: schemaID,
|
|
@@ -196,9 +204,6 @@ class UpdateTableButton extends Component {
|
|
|
schemaState: 'updated-update-table',
|
|
schemaState: 'updated-update-table',
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // console.log(this.props.currentTable);
|
|
|
|
|
- // console.log(this.props.currentSchema);
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<Query query={SHOW_TABLE} variables={{schema_id: schemaID}}>
|
|
<Query query={SHOW_TABLE} variables={{schema_id: schemaID}}>
|
|
|
|
|
|
|
@@ -219,23 +224,15 @@ class UpdateTableButton extends Component {
|
|
|
query: SHOW_TABLE,
|
|
query: SHOW_TABLE,
|
|
|
variables: {schema_id: schemaID}
|
|
variables: {schema_id: schemaID}
|
|
|
});
|
|
});
|
|
|
|
|
+ data.schema_by_id = update_schema;
|
|
|
|
|
|
|
|
let showSchemaData = cache.readQuery({
|
|
let showSchemaData = cache.readQuery({
|
|
|
query: SHOW_SCHEMA,
|
|
query: SHOW_SCHEMA,
|
|
|
- variables: {user_id: 'xy_1'}
|
|
|
|
|
|
|
+ variables: {user_id: userID}
|
|
|
});
|
|
});
|
|
|
let index = showSchemaData.schema_by_props.findIndex(obj => obj.schemaName === update_schema.schemaName);
|
|
let index = showSchemaData.schema_by_props.findIndex(obj => obj.schemaName === update_schema.schemaName);
|
|
|
- // console.log('我是',index);
|
|
|
|
|
- // console.log('test', update_schema);
|
|
|
|
|
- // console.log('testss', showSchemaData.schema_by_props);
|
|
|
|
|
-
|
|
|
|
|
showSchemaData.schema_by_props.splice(index, 1, update_schema);
|
|
showSchemaData.schema_by_props.splice(index, 1, update_schema);
|
|
|
|
|
|
|
|
- console.log('showTableData', data);
|
|
|
|
|
- // console.log('update_schema', update_schema);
|
|
|
|
|
-
|
|
|
|
|
- data.schema_by_id = update_schema;
|
|
|
|
|
-
|
|
|
|
|
cache.writeQuery(
|
|
cache.writeQuery(
|
|
|
{
|
|
{
|
|
|
query: SHOW_TABLE,
|
|
query: SHOW_TABLE,
|
|
@@ -244,7 +241,7 @@ class UpdateTableButton extends Component {
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
|
query: SHOW_SCHEMA,
|
|
query: SHOW_SCHEMA,
|
|
|
- variables: {user_id: 'xy_1'},
|
|
|
|
|
|
|
+ variables: {user_id: userID},
|
|
|
showSchemaData
|
|
showSchemaData
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
@@ -257,25 +254,26 @@ class UpdateTableButton extends Component {
|
|
|
if (error)
|
|
if (error)
|
|
|
return 'error';
|
|
return 'error';
|
|
|
|
|
|
|
|
-
|
|
|
|
|
// 更新代码
|
|
// 更新代码
|
|
|
// 先 query 再 mutation,然后替换,做一个判断
|
|
// 先 query 再 mutation,然后替换,做一个判断
|
|
|
- let schemaCols = JSON.parse(schemaData.schema_by_id.schemaData);
|
|
|
|
|
|
|
+ let schemaCols;
|
|
|
|
|
+ if (schemaData.schema_by_id === null) schemaCols = [];
|
|
|
|
|
+ else schemaCols = JSON.parse(schemaData.schema_by_id.schemaData);
|
|
|
let newTable = {
|
|
let newTable = {
|
|
|
name: this.props.currentTable,
|
|
name: this.props.currentTable,
|
|
|
remark: this.props.remark,
|
|
remark: this.props.remark,
|
|
|
cols: this.props.columns
|
|
cols: this.props.columns
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
const index = this.props.currentTableIndex;
|
|
const index = this.props.currentTableIndex;
|
|
|
if (index === -2) {
|
|
if (index === -2) {
|
|
|
schemaCols.push(newTable);
|
|
schemaCols.push(newTable);
|
|
|
} else if (index === -1) {
|
|
} else if (index === -1) {
|
|
|
- console.log('未知错误,数据库信息不匹配');
|
|
|
|
|
|
|
+ console.log('进行了一次删除操作 或 未知错误,数据库信息不匹配');
|
|
|
} else {
|
|
} else {
|
|
|
schemaCols.splice(index, 1, newTable);
|
|
schemaCols.splice(index, 1, newTable);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<div style={{display: 'inline-block'}}>
|
|
<div style={{display: 'inline-block'}}>
|
|
|
<Button type="primary" onClick={() => {
|
|
<Button type="primary" onClick={() => {
|
|
@@ -304,9 +302,10 @@ class UpdateTableButton extends Component {
|
|
|
class DeleteTableButton extends Component {
|
|
class DeleteTableButton extends Component {
|
|
|
render() {
|
|
render() {
|
|
|
let schemaID = this.props.schemaID;
|
|
let schemaID = this.props.schemaID;
|
|
|
|
|
+ let userID = this.props.userID;
|
|
|
|
|
|
|
|
let varobj = {
|
|
let varobj = {
|
|
|
- id: 'schema_1542006423662_89419168',
|
|
|
|
|
|
|
+ id: schemaID,
|
|
|
updatedAt: new Date().getTime(),
|
|
updatedAt: new Date().getTime(),
|
|
|
schemaState: 'updated-delete-table',
|
|
schemaState: 'updated-delete-table',
|
|
|
};
|
|
};
|
|
@@ -331,16 +330,42 @@ class DeleteTableButton extends Component {
|
|
|
query: SHOW_TABLE,
|
|
query: SHOW_TABLE,
|
|
|
variables: {schema_id: schemaID}
|
|
variables: {schema_id: schemaID}
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- // console.log('data', data);
|
|
|
|
|
- // console.log('update_schema', update_schema);
|
|
|
|
|
-
|
|
|
|
|
data.schema_by_id = update_schema;
|
|
data.schema_by_id = update_schema;
|
|
|
- cache.writeQuery({
|
|
|
|
|
- query: SHOW_TABLE,
|
|
|
|
|
- variables: {schema_id: schemaID},
|
|
|
|
|
- data
|
|
|
|
|
|
|
+
|
|
|
|
|
+ let showSchemaData = cache.readQuery({
|
|
|
|
|
+ query: 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: SHOW_TABLE,
|
|
|
|
|
+ variables: {schema_id: schemaID},
|
|
|
|
|
+ data
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ query: SHOW_SCHEMA,
|
|
|
|
|
+ variables: {user_id: userID},
|
|
|
|
|
+ showSchemaData
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
|
|
|
|
@@ -351,28 +376,31 @@ class DeleteTableButton extends Component {
|
|
|
return 'error';
|
|
return 'error';
|
|
|
|
|
|
|
|
// 先 query 再 mutation,然后删除
|
|
// 先 query 再 mutation,然后删除
|
|
|
- let schemaCols = JSON.parse(schemaData.schema_by_id.schemaData);
|
|
|
|
|
- console.log('删除之前的 schemaCols', schemaCols);
|
|
|
|
|
|
|
+ let schemaCols;
|
|
|
|
|
+ if (schemaData.schema_by_id === null) schemaCols = [];
|
|
|
|
|
+ else schemaCols = JSON.parse(schemaData.schema_by_id.schemaData);
|
|
|
|
|
+
|
|
|
const index = this.props.currentTableIndex;
|
|
const index = this.props.currentTableIndex;
|
|
|
|
|
+ // 设置-2 标志为新建页面,防止通过 tablename 被修改导致每次 index 都为 -1 从而修改最后一个
|
|
|
if (index === -2) {
|
|
if (index === -2) {
|
|
|
console.log('初始页面')
|
|
console.log('初始页面')
|
|
|
} else if (index === -1) {
|
|
} else if (index === -1) {
|
|
|
- console.log('未知错误,数据库信息不匹配');
|
|
|
|
|
|
|
+ console.log('进行了一次删除操作 或 未知错误,数据库信息不匹配');
|
|
|
} else {
|
|
} else {
|
|
|
schemaCols.splice(index, 1);
|
|
schemaCols.splice(index, 1);
|
|
|
}
|
|
}
|
|
|
- console.log('删除之后的 schemaCols', schemaCols);
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div style={{display: 'inline-block'}}>
|
|
<div style={{display: 'inline-block'}}>
|
|
|
- <Button type="danger" onClick={() => {
|
|
|
|
|
- update_schema({
|
|
|
|
|
- variables: {
|
|
|
|
|
- ...varobj,
|
|
|
|
|
- schemaData: JSON.stringify(schemaCols)
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }}>
|
|
|
|
|
|
|
+ <Button type="danger"
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ update_schema({
|
|
|
|
|
+ variables: {
|
|
|
|
|
+ ...varobj,
|
|
|
|
|
+ schemaData: JSON.stringify(schemaCols)
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }}>
|
|
|
DELETE
|
|
DELETE
|
|
|
</Button>
|
|
</Button>
|
|
|
</div>
|
|
</div>
|