|
@@ -23,6 +23,9 @@ class SchemaChange extends Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ // 下面的 handlexxxx 全是 state 内部方法,用于操作视图
|
|
|
|
|
+ // cache 仅在提交删除整体使用
|
|
|
|
|
+
|
|
|
handleNameChange = (index) => {
|
|
handleNameChange = (index) => {
|
|
|
return (e) => {
|
|
return (e) => {
|
|
|
let columns = this.state.columns;
|
|
let columns = this.state.columns;
|
|
@@ -161,9 +164,18 @@ class SchemaChange extends Component {
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div style={{marginTop: 20}}>
|
|
<div style={{marginTop: 20}}>
|
|
|
- <UpdateTableButton currentTable={this.state.currentTable} columns={this.state.columns}
|
|
|
|
|
- remark={this.state.remark}/>
|
|
|
|
|
- <DeleteTableButton/>
|
|
|
|
|
|
|
+ <UpdateTableButton
|
|
|
|
|
+ currentTable={this.state.currentTable}
|
|
|
|
|
+ columns={this.state.columns}
|
|
|
|
|
+ remark={this.state.remark}
|
|
|
|
|
+ currentTableIndex={this.props.currentTableIndex}
|
|
|
|
|
+ schemaID={this.props.schemaID}
|
|
|
|
|
+
|
|
|
|
|
+ />
|
|
|
|
|
+ <DeleteTableButton
|
|
|
|
|
+ currentTableIndex={this.props.currentTableIndex}
|
|
|
|
|
+ schemaID = {this.props.schemaID}
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
@@ -176,14 +188,19 @@ export default SchemaChange;
|
|
|
class UpdateTableButton extends Component {
|
|
class UpdateTableButton extends Component {
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
|
|
+ let schemaID = this.props.schemaID;
|
|
|
|
|
+
|
|
|
let varobj = {
|
|
let varobj = {
|
|
|
- id: 'schema_1542006423662_89419168',
|
|
|
|
|
|
|
+ id: schemaID,
|
|
|
updatedAt: new Date().getTime(),
|
|
updatedAt: new Date().getTime(),
|
|
|
- schemaState: 'updated',
|
|
|
|
|
|
|
+ schemaState: 'updated-update-table',
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // console.log(this.props.currentTable);
|
|
|
|
|
+ // console.log(this.props.currentSchema);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
- <Query query={SHOW_TABLE} variables={{schema_id: 'schema_1542006423662_89419168'}}>
|
|
|
|
|
|
|
+ <Query query={SHOW_TABLE} variables={{schema_id: schemaID}}>
|
|
|
|
|
|
|
|
{
|
|
{
|
|
|
({loading, error, data}) => {
|
|
({loading, error, data}) => {
|
|
@@ -200,18 +217,37 @@ class UpdateTableButton extends Component {
|
|
|
update={(cache, {data: {update_schema}}) => {
|
|
update={(cache, {data: {update_schema}}) => {
|
|
|
let data = cache.readQuery({
|
|
let data = cache.readQuery({
|
|
|
query: SHOW_TABLE,
|
|
query: SHOW_TABLE,
|
|
|
- variables: {schema_id: 'schema_1542006423662_89419168'}
|
|
|
|
|
|
|
+ variables: {schema_id: schemaID}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- console.log('data', data);
|
|
|
|
|
- console.log('update_schema', update_schema);
|
|
|
|
|
|
|
+ let showSchemaData = cache.readQuery({
|
|
|
|
|
+ query: SHOW_SCHEMA,
|
|
|
|
|
+ variables: {user_id: 'xy_1'}
|
|
|
|
|
+ });
|
|
|
|
|
+ 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);
|
|
|
|
|
+
|
|
|
|
|
+ console.log('showTableData', 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: 'schema_1542006423662_89419168'},
|
|
|
|
|
- data
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ cache.writeQuery(
|
|
|
|
|
+ {
|
|
|
|
|
+ query: SHOW_TABLE,
|
|
|
|
|
+ variables: {schema_id: schemaID},
|
|
|
|
|
+ data
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ query: SHOW_SCHEMA,
|
|
|
|
|
+ variables: {user_id: 'xy_1'},
|
|
|
|
|
+ showSchemaData
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
|
|
|
|
@@ -221,14 +257,24 @@ 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 = 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
|
|
|
};
|
|
};
|
|
|
- schemaCols.splice(schemaCols.findIndex(table=> table.name === this.props.currentTable), 1, newTable);
|
|
|
|
|
|
|
+ const index = this.props.currentTableIndex;
|
|
|
|
|
+ if (index === -2) {
|
|
|
|
|
+ schemaCols.push(newTable);
|
|
|
|
|
+ } else if (index === -1) {
|
|
|
|
|
+ console.log('未知错误,数据库信息不匹配');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ schemaCols.splice(index, 1, newTable);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div style={{display: 'inline-block'}}>
|
|
<div style={{display: 'inline-block'}}>
|
|
@@ -256,73 +302,88 @@ class UpdateTableButton extends Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class DeleteTableButton extends Component {
|
|
class DeleteTableButton extends Component {
|
|
|
- // update_schema(
|
|
|
|
|
-// createdAt: String
|
|
|
|
|
-// id: ID!
|
|
|
|
|
-// schemaData: String
|
|
|
|
|
-// schemaName: String
|
|
|
|
|
-// schemaState: String
|
|
|
|
|
-// updatedAt: String
|
|
|
|
|
-// user_id: String
|
|
|
|
|
-// ): Schema
|
|
|
|
|
-
|
|
|
|
|
render() {
|
|
render() {
|
|
|
|
|
+ let schemaID = this.props.schemaID;
|
|
|
|
|
+
|
|
|
let varobj = {
|
|
let varobj = {
|
|
|
id: 'schema_1542006423662_89419168',
|
|
id: 'schema_1542006423662_89419168',
|
|
|
updatedAt: new Date().getTime(),
|
|
updatedAt: new Date().getTime(),
|
|
|
- schemaState: 'updated',
|
|
|
|
|
|
|
+ schemaState: 'updated-delete-table',
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <Mutation
|
|
|
|
|
- mutation={UPDATE_SCHEMA}
|
|
|
|
|
- update={(cache, {data: {update_schema}}) => {
|
|
|
|
|
- let data = cache.readQuery({
|
|
|
|
|
- query: SHOW_TABLE,
|
|
|
|
|
- variables: {schema_id: 'schema_1542006423662_89419168'}
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- console.log('data', data);
|
|
|
|
|
- console.log('update_schema', update_schema);
|
|
|
|
|
-
|
|
|
|
|
- data.schema_by_id = update_schema;
|
|
|
|
|
- cache.writeQuery({
|
|
|
|
|
- query: SHOW_TABLE,
|
|
|
|
|
- variables: {schema_id: 'schema_1542006423662_89419168'},
|
|
|
|
|
- data
|
|
|
|
|
- });
|
|
|
|
|
- }}
|
|
|
|
|
- >
|
|
|
|
|
-
|
|
|
|
|
- {(update_schema, {loading, error}) => {
|
|
|
|
|
- if (loading)
|
|
|
|
|
- return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
|
|
|
|
|
- if (error)
|
|
|
|
|
- return 'error';
|
|
|
|
|
- return (
|
|
|
|
|
- <div style={{display: 'inline-block', marginLeft: 10}}>
|
|
|
|
|
-
|
|
|
|
|
- <Button type="danger" onClick={() => {
|
|
|
|
|
- update_schema({
|
|
|
|
|
- variables: {
|
|
|
|
|
- ...varobj,
|
|
|
|
|
- schemaData: JSON.stringify({
|
|
|
|
|
- name: 'dsdsddsds',
|
|
|
|
|
- remark: 'sas',
|
|
|
|
|
- cols: [
|
|
|
|
|
- {name: '1234', type: 'int', description: 'description'},
|
|
|
|
|
- {name: '5678', type: 'int', description: 'non-null'}
|
|
|
|
|
- ]
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ <Query query={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={UPDATE_SCHEMA}
|
|
|
|
|
+ update={(cache, {data: {update_schema}}) => {
|
|
|
|
|
+ let data = cache.readQuery({
|
|
|
|
|
+ query: SHOW_TABLE,
|
|
|
|
|
+ variables: {schema_id: schemaID}
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // console.log('data', data);
|
|
|
|
|
+ // console.log('update_schema', update_schema);
|
|
|
|
|
+
|
|
|
|
|
+ data.schema_by_id = update_schema;
|
|
|
|
|
+ cache.writeQuery({
|
|
|
|
|
+ query: SHOW_TABLE,
|
|
|
|
|
+ variables: {schema_id: schemaID},
|
|
|
|
|
+ data
|
|
|
|
|
+ });
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+
|
|
|
|
|
+ {(update_schema, {loading, error}) => {
|
|
|
|
|
+ if (loading)
|
|
|
|
|
+ return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
|
|
|
|
|
+ if (error)
|
|
|
|
|
+ return 'error';
|
|
|
|
|
+
|
|
|
|
|
+ // 先 query 再 mutation,然后删除
|
|
|
|
|
+ let schemaCols = JSON.parse(schemaData.schema_by_id.schemaData);
|
|
|
|
|
+ console.log('删除之前的 schemaCols', schemaCols);
|
|
|
|
|
+ const index = this.props.currentTableIndex;
|
|
|
|
|
+ if (index === -2) {
|
|
|
|
|
+ console.log('初始页面')
|
|
|
|
|
+ } else if (index === -1) {
|
|
|
|
|
+ console.log('未知错误,数据库信息不匹配');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ schemaCols.splice(index, 1);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- }}>
|
|
|
|
|
- DELETE
|
|
|
|
|
- </Button>
|
|
|
|
|
- </div>
|
|
|
|
|
- )
|
|
|
|
|
- }}
|
|
|
|
|
- </Mutation>
|
|
|
|
|
|
|
+ console.log('删除之后的 schemaCols', schemaCols);
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div style={{display: 'inline-block'}}>
|
|
|
|
|
+ <Button type="danger" onClick={() => {
|
|
|
|
|
+ update_schema({
|
|
|
|
|
+ variables: {
|
|
|
|
|
+ ...varobj,
|
|
|
|
|
+ schemaData: JSON.stringify(schemaCols)
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }}>
|
|
|
|
|
+ DELETE
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )
|
|
|
|
|
+ }}
|
|
|
|
|
+ </Mutation>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ </Query>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|