rename id=>conid, id=>tabid

This commit is contained in:
Jan Prochazka
2020-01-25 13:57:56 +01:00
parent 8646221b41
commit 2a40b05ae0
8 changed files with 44 additions and 44 deletions

View File

@@ -52,8 +52,8 @@ module.exports = {
}, },
get_meta: 'get', get_meta: 'get',
async get({ id }) { async get({ conid }) {
const res = await this.datastore.find({ _id: id }); const res = await this.datastore.find({ _id: conid });
return res[0]; return res[0];
}, },
}; };

View File

@@ -10,28 +10,28 @@ module.exports = {
opened: [], opened: [],
requests: {}, requests: {},
handle_structure(id, database, { structure }) { handle_structure(conid, database, { structure }) {
const existing = this.opened.find(x => x.id == id && x.database == database); const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (!existing) return; if (!existing) return;
existing.structure = structure; existing.structure = structure;conid
socket.emit(`database-structure-changed-${id}-${database}`); socket.emit(`database-structure-changed-${conid}-${database}`);
}, },
handle_error(id, { error }) { handle_error(conid, { error }) {
console.log(error); console.log(error);
}, },
handle_response(id, database, { msgid, ...response }) { handle_response(conid, database, { msgid, ...response }) {
const [resolve, reject] = this.requests[msgid]; const [resolve, reject] = this.requests[msgid];
resolve(response); resolve(response);
delete this.requests[msgid]; delete this.requests[msgid];
}, },
async ensureOpened(id, database) { async ensureOpened(conid, database) {
const existing = this.opened.find(x => x.id == id && x.database == database); const existing = this.opened.find(x => x.conid == conid && x.database == database);
if (existing) return existing; if (existing) return existing;
const connection = await connections.get({ id }); const connection = await connections.get({ conid });
const subprocess = fork(`${__dirname}/../proc/databaseConnectionProcess.js`); const subprocess = fork(`${__dirname}/../proc/databaseConnectionProcess.js`);
const newOpened = { const newOpened = {
id, conid,
database, database,
subprocess, subprocess,
structure: DatabaseAnalyser.createEmptyStructure(), structure: DatabaseAnalyser.createEmptyStructure(),
@@ -40,7 +40,7 @@ module.exports = {
this.opened.push(newOpened); this.opened.push(newOpened);
// @ts-ignore // @ts-ignore
subprocess.on('message', ({ msgtype, ...message }) => { subprocess.on('message', ({ msgtype, ...message }) => {
this[`handle_${msgtype}`](id, database, message); this[`handle_${msgtype}`](conid, database, message);
}); });
subprocess.send({ msgtype: 'connect', ...connection, database }); subprocess.send({ msgtype: 'connect', ...connection, database });
return newOpened; return newOpened;
@@ -57,8 +57,8 @@ module.exports = {
}, },
listObjects_meta: 'get', listObjects_meta: 'get',
async listObjects({ id, database }) { async listObjects({ conid, database }) {
const opened = await this.ensureOpened(id, database); const opened = await this.ensureOpened(conid, database);
const { tables } = opened.structure; const { tables } = opened.structure;
return { return {
tables: _.sortBy(tables, x => `${x.schemaName}.${x.pureName}`), tables: _.sortBy(tables, x => `${x.schemaName}.${x.pureName}`),

View File

@@ -6,23 +6,23 @@ const { fork } = require('child_process');
module.exports = { module.exports = {
opened: [], opened: [],
handle_databases(id, { databases }) { handle_databases(conid, { databases }) {
const existing = this.opened.find(x => x.id == id); const existing = this.opened.find(x => x.conid == conid);
if (!existing) return; if (!existing) return;
existing.databases = databases; 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); console.log(error);
}, },
async ensureOpened(id) { async ensureOpened(conid) {
const existing = this.opened.find(x => x.id == id); const existing = this.opened.find(x => x.conid == conid);
if (existing) return existing; if (existing) return existing;
const connection = await connections.get({ id }); const connection = await connections.get({ conid });
const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`); const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`);
const newOpened = { const newOpened = {
id, conid,
subprocess, subprocess,
databases: [], databases: [],
connection, connection,
@@ -30,15 +30,15 @@ module.exports = {
this.opened.push(newOpened); this.opened.push(newOpened);
// @ts-ignore // @ts-ignore
subprocess.on('message', ({ msgtype, ...message }) => { subprocess.on('message', ({ msgtype, ...message }) => {
this[`handle_${msgtype}`](id, message); this[`handle_${msgtype}`](conid, message);
}); });
subprocess.send({ msgtype: 'connect', ...connection }); subprocess.send({ msgtype: 'connect', ...connection });
return newOpened; return newOpened;
}, },
listDatabases_meta: 'get', listDatabases_meta: 'get',
async listDatabases({ id }) { async listDatabases({ conid }) {
const opened = await this.ensureOpened(id); const opened = await this.ensureOpened(conid);
return opened.databases; return opened.databases;
}, },
}; };

View File

@@ -5,7 +5,7 @@ module.exports = {
tableData_meta: 'get', tableData_meta: 'get',
async tableData({ id, database, schemaName, pureName }) { async tableData({ id, database, schemaName, pureName }) {
const opened = await databaseConnections.ensureOpened(id, database); const opened = await databaseConnections.ensureOpened(id, database);
const res = opened.sendRequest({ msgtype: 'tableData', schemaName, pureName }); // const res = opened.sendRequest({ msgtype: 'tableData', schemaName, pureName });
return res; // return res;
}, },
}; };

View File

@@ -22,7 +22,7 @@ export interface DatabaseInfo {
} }
export interface OpenedDatabaseConnection { export interface OpenedDatabaseConnection {
id: string; conid: string;
database: string; database: string;
structure: DatabaseInfo; structure: DatabaseInfo;
subprocess: ChildProcess; subprocess: ChildProcess;

View File

@@ -34,17 +34,17 @@ export default function TabsPanel() {
const tabs = useOpenedTabs(); const tabs = useOpenedTabs();
const setOpenedTabs = useSetOpenedTabs(); const setOpenedTabs = useSetOpenedTabs();
const handleTabClick = id => { const handleTabClick = tabid => {
setOpenedTabs(files => setOpenedTabs(files =>
files.map(x => ({ files.map(x => ({
...x, ...x,
selected: x.id == id, selected: x.tabid == tabid,
})) }))
); );
}; };
const handleMouseUp = (e, id) => { const handleMouseUp = (e, tabid) => {
if (e.button == 1) { if (e.button == 1) {
setOpenedTabs(files => files.filter(x => x.id != id)); setOpenedTabs(files => files.filter(x => x.tabid != tabid));
} }
}; };
return ( return (
@@ -52,9 +52,9 @@ export default function TabsPanel() {
{tabs.map(tab => ( {tabs.map(tab => (
<FileTabItem <FileTabItem
{...tab} {...tab}
key={tab.id} key={tab.tabid}
onClick={() => handleTabClick(tab.id)} onClick={() => handleTabClick(tab.tabid)}
onMouseUp={e => handleMouseUp(e, tab.id)} onMouseUp={e => handleMouseUp(e, tab.tabid)}
> >
{getIconImage(tab.icon)} {getIconImage(tab.icon)}
<FileNameWrapper>{tab.title}</FileNameWrapper> <FileNameWrapper>{tab.title}</FileNameWrapper>

View File

@@ -26,11 +26,11 @@ export default function tableAppObject({ pureName, schemaName }, { setOpenedTabs
const key = title; const key = title;
const Icon = TableIcon; const Icon = TableIcon;
const onClick = ({ schemaName, pureName }) => { const onClick = ({ schemaName, pureName }) => {
const id = uuidv1(); const tabid = uuidv1();
setOpenedTabs(files => [ setOpenedTabs(files => [
...files, ...files,
{ {
id, tabid,
title: pureName, title: pureName,
icon: 'table2.svg', icon: 'table2.svg',
tabComponent: 'TableDataTab', tabComponent: 'TableDataTab',

View File

@@ -34,7 +34,7 @@ function SubDatabaseList({ data }) {
}; };
const { _id } = data; const { _id } = data;
const databases = useFetch({ const databases = useFetch({
url: `server-connections/list-databases?id=${_id}`, url: `server-connections/list-databases?conid=${_id}`,
reloadTrigger: `database-list-changed-${_id}`, reloadTrigger: `database-list-changed-${_id}`,
}); });
return <AppObjectList list={databases} makeAppObj={databaseAppObject} onObjectClick={handleDatabaseClick} />; return <AppObjectList list={databases} makeAppObj={databaseAppObject} onObjectClick={handleDatabaseClick} />;
@@ -55,15 +55,15 @@ function ConnectionList() {
); );
} }
function SqlObjectList({ id, database }) { function SqlObjectList({ conid, database }) {
const objects = useFetch({ const objects = useFetch({
url: `database-connections/list-objects?id=${id}&database=${database}`, url: `database-connections/list-objects?conid=${conid}&database=${database}`,
reloadTrigger: `database-structure-changed-${id}-${database}`, reloadTrigger: `database-structure-changed-${conid}-${database}`,
}); });
const { tables } = objects || {}; const { tables } = objects || {};
return ( return (
<> <>
<AppObjectList list={(tables || []).map(x => ({ ...x, id, database }))} makeAppObj={tableAppObject} /> <AppObjectList list={(tables || []).map(x => ({ ...x, conid, database }))} makeAppObj={tableAppObject} />
</> </>
); );
} }
@@ -74,7 +74,7 @@ function SqlObjectListWrapper() {
if (!db) return <div>(Choose database)</div>; if (!db) return <div>(Choose database)</div>;
const { name, connection } = db; const { name, connection } = db;
return <SqlObjectList id={connection._id} database={name} />; return <SqlObjectList conid={connection._id} database={name} />;
// return <div>tables of {db && db.name}</div> // return <div>tables of {db && db.name}</div>
// return <div>tables of {JSON.stringify(db)}</div> // return <div>tables of {JSON.stringify(db)}</div>
} }