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',
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];
},
};

View File

@@ -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}`),

View File

@@ -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;
},
};

View File

@@ -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;
},
};

View File

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

View File

@@ -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 => (
<FileTabItem
{...tab}
key={tab.id}
onClick={() => 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)}
<FileNameWrapper>{tab.title}</FileNameWrapper>

View File

@@ -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',

View File

@@ -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 <AppObjectList list={databases} makeAppObj={databaseAppObject} onObjectClick={handleDatabaseClick} />;
@@ -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 (
<>
<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>;
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 {JSON.stringify(db)}</div>
}