diff --git a/api/src/controllers/connections.js b/api/src/controllers/connections.js index b7c8b2087..c09d15aea 100644 --- a/api/src/controllers/connections.js +++ b/api/src/controllers/connections.js @@ -52,8 +52,8 @@ module.exports = { }, get_meta: 'get', - async get({ id }) { - const res = await this.datastore.find({ _id: id }); + async get({ conid }) { + const res = await this.datastore.find({ _id: conid }); return res[0]; }, }; diff --git a/api/src/controllers/databaseConnections.js b/api/src/controllers/databaseConnections.js index 6be6b2d07..875e193bb 100644 --- a/api/src/controllers/databaseConnections.js +++ b/api/src/controllers/databaseConnections.js @@ -10,28 +10,28 @@ module.exports = { opened: [], requests: {}, - handle_structure(id, database, { structure }) { - const existing = this.opened.find(x => x.id == id && x.database == database); + handle_structure(conid, database, { structure }) { + const existing = this.opened.find(x => x.conid == conid && x.database == database); if (!existing) return; - existing.structure = structure; - socket.emit(`database-structure-changed-${id}-${database}`); + existing.structure = structure;conid + socket.emit(`database-structure-changed-${conid}-${database}`); }, - handle_error(id, { error }) { + handle_error(conid, { error }) { console.log(error); }, - handle_response(id, database, { msgid, ...response }) { + handle_response(conid, database, { msgid, ...response }) { const [resolve, reject] = this.requests[msgid]; resolve(response); delete this.requests[msgid]; }, - async ensureOpened(id, database) { - const existing = this.opened.find(x => x.id == id && x.database == database); + async ensureOpened(conid, database) { + const existing = this.opened.find(x => x.conid == conid && x.database == database); if (existing) return existing; - const connection = await connections.get({ id }); + const connection = await connections.get({ conid }); const subprocess = fork(`${__dirname}/../proc/databaseConnectionProcess.js`); const newOpened = { - id, + conid, database, subprocess, structure: DatabaseAnalyser.createEmptyStructure(), @@ -40,7 +40,7 @@ module.exports = { this.opened.push(newOpened); // @ts-ignore subprocess.on('message', ({ msgtype, ...message }) => { - this[`handle_${msgtype}`](id, database, message); + this[`handle_${msgtype}`](conid, database, message); }); subprocess.send({ msgtype: 'connect', ...connection, database }); return newOpened; @@ -57,8 +57,8 @@ module.exports = { }, listObjects_meta: 'get', - async listObjects({ id, database }) { - const opened = await this.ensureOpened(id, database); + async listObjects({ conid, database }) { + const opened = await this.ensureOpened(conid, database); const { tables } = opened.structure; return { tables: _.sortBy(tables, x => `${x.schemaName}.${x.pureName}`), diff --git a/api/src/controllers/serverConnections.js b/api/src/controllers/serverConnections.js index 02133c17d..6b7c64439 100644 --- a/api/src/controllers/serverConnections.js +++ b/api/src/controllers/serverConnections.js @@ -6,23 +6,23 @@ const { fork } = require('child_process'); module.exports = { opened: [], - handle_databases(id, { databases }) { - const existing = this.opened.find(x => x.id == id); + handle_databases(conid, { databases }) { + const existing = this.opened.find(x => x.conid == conid); if (!existing) return; existing.databases = databases; - socket.emit(`database-list-changed-${id}`); + socket.emit(`database-list-changed-${conid}`); }, - handle_error(id, { error }) { + handle_error(conid, { error }) { console.log(error); }, - async ensureOpened(id) { - const existing = this.opened.find(x => x.id == id); + async ensureOpened(conid) { + const existing = this.opened.find(x => x.conid == conid); if (existing) return existing; - const connection = await connections.get({ id }); + const connection = await connections.get({ conid }); const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`); const newOpened = { - id, + conid, subprocess, databases: [], connection, @@ -30,15 +30,15 @@ module.exports = { this.opened.push(newOpened); // @ts-ignore subprocess.on('message', ({ msgtype, ...message }) => { - this[`handle_${msgtype}`](id, message); + this[`handle_${msgtype}`](conid, message); }); subprocess.send({ msgtype: 'connect', ...connection }); return newOpened; }, listDatabases_meta: 'get', - async listDatabases({ id }) { - const opened = await this.ensureOpened(id); + async listDatabases({ conid }) { + const opened = await this.ensureOpened(conid); return opened.databases; }, }; diff --git a/api/src/controllers/tables.js b/api/src/controllers/tables.js index 729c12827..6bf939eab 100644 --- a/api/src/controllers/tables.js +++ b/api/src/controllers/tables.js @@ -5,7 +5,7 @@ module.exports = { tableData_meta: 'get', async tableData({ id, database, schemaName, pureName }) { const opened = await databaseConnections.ensureOpened(id, database); - const res = opened.sendRequest({ msgtype: 'tableData', schemaName, pureName }); - return res; + // const res = opened.sendRequest({ msgtype: 'tableData', schemaName, pureName }); + // return res; }, }; diff --git a/api/src/types.ts b/api/src/types.ts index 12b24a932..436fc4474 100644 --- a/api/src/types.ts +++ b/api/src/types.ts @@ -22,7 +22,7 @@ export interface DatabaseInfo { } export interface OpenedDatabaseConnection { - id: string; + conid: string; database: string; structure: DatabaseInfo; subprocess: ChildProcess; diff --git a/web/src/TabsPanel.js b/web/src/TabsPanel.js index 9f1c7debc..963f90c88 100644 --- a/web/src/TabsPanel.js +++ b/web/src/TabsPanel.js @@ -34,17 +34,17 @@ export default function TabsPanel() { const tabs = useOpenedTabs(); const setOpenedTabs = useSetOpenedTabs(); - const handleTabClick = id => { + const handleTabClick = tabid => { setOpenedTabs(files => files.map(x => ({ ...x, - selected: x.id == id, + selected: x.tabid == tabid, })) ); }; - const handleMouseUp = (e, id) => { + const handleMouseUp = (e, tabid) => { if (e.button == 1) { - setOpenedTabs(files => files.filter(x => x.id != id)); + setOpenedTabs(files => files.filter(x => x.tabid != tabid)); } }; return ( @@ -52,9 +52,9 @@ export default function TabsPanel() { {tabs.map(tab => ( handleTabClick(tab.id)} - onMouseUp={e => handleMouseUp(e, tab.id)} + key={tab.tabid} + onClick={() => handleTabClick(tab.tabid)} + onMouseUp={e => handleMouseUp(e, tab.tabid)} > {getIconImage(tab.icon)} {tab.title} diff --git a/web/src/appobj/tableAppObject.js b/web/src/appobj/tableAppObject.js index 182135d07..5531e877d 100644 --- a/web/src/appobj/tableAppObject.js +++ b/web/src/appobj/tableAppObject.js @@ -26,11 +26,11 @@ export default function tableAppObject({ pureName, schemaName }, { setOpenedTabs const key = title; const Icon = TableIcon; const onClick = ({ schemaName, pureName }) => { - const id = uuidv1(); + const tabid = uuidv1(); setOpenedTabs(files => [ ...files, { - id, + tabid, title: pureName, icon: 'table2.svg', tabComponent: 'TableDataTab', diff --git a/web/src/widgets/DatabaseWidget.js b/web/src/widgets/DatabaseWidget.js index b7c7342ae..78c028ed8 100644 --- a/web/src/widgets/DatabaseWidget.js +++ b/web/src/widgets/DatabaseWidget.js @@ -34,7 +34,7 @@ function SubDatabaseList({ data }) { }; const { _id } = data; const databases = useFetch({ - url: `server-connections/list-databases?id=${_id}`, + url: `server-connections/list-databases?conid=${_id}`, reloadTrigger: `database-list-changed-${_id}`, }); return ; @@ -55,15 +55,15 @@ function ConnectionList() { ); } -function SqlObjectList({ id, database }) { +function SqlObjectList({ conid, database }) { const objects = useFetch({ - url: `database-connections/list-objects?id=${id}&database=${database}`, - reloadTrigger: `database-structure-changed-${id}-${database}`, + url: `database-connections/list-objects?conid=${conid}&database=${database}`, + reloadTrigger: `database-structure-changed-${conid}-${database}`, }); const { tables } = objects || {}; return ( <> - ({ ...x, id, database }))} makeAppObj={tableAppObject} /> + ({ ...x, conid, database }))} makeAppObj={tableAppObject} /> ); } @@ -74,7 +74,7 @@ function SqlObjectListWrapper() { if (!db) return
(Choose database)
; const { name, connection } = db; - return ; + return ; // return
tables of {db && db.name}
// return
tables of {JSON.stringify(db)}
}