feat: open/close console on single connection

This commit is contained in:
Fabio Di Stasio 2022-07-17 16:20:21 +02:00
parent 3f9e6d85ca
commit 44647f5b55
3 changed files with 31 additions and 18 deletions

View File

@ -14,7 +14,7 @@
<li <li
v-if="workspace.connectionStatus === 'connected' " v-if="workspace.connectionStatus === 'connected' "
class="footer-element footer-link" class="footer-element footer-link"
@click="toggleConsole" @click="toggleConsole()"
> >
<i class="mdi mdi-18px mdi-console-line mr-1" /> <i class="mdi mdi-18px mdi-console-line mr-1" />
<small>{{ t('word.console') }}</small> <small>{{ t('word.console') }}</small>

View File

@ -457,7 +457,7 @@
:schema="tab.schema" :schema="tab.schema"
/> />
</template> </template>
<WorkspaceQueryConsole v-if="isConsoleOpen" :uid="workspace.uid" /> <WorkspaceQueryConsole v-if="isConsoleOpen(workspace.uid)" :uid="workspace.uid" />
</div> </div>
<div v-else class="connection-panel-wrapper p-relative"> <div v-else class="connection-panel-wrapper p-relative">
<WorkspaceEditConnectionPanel :connection="connection" /> <WorkspaceEditConnectionPanel :connection="connection" />

View File

@ -1,5 +1,6 @@
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { useWorkspacesStore } from './workspaces';
const logsSize = 1000; const logsSize = 1000;
export interface ConsoleRecord { export interface ConsoleRecord {
@ -11,11 +12,16 @@ export interface ConsoleRecord {
export const useConsoleStore = defineStore('console', { export const useConsoleStore = defineStore('console', {
state: () => ({ state: () => ({
records: [] as ConsoleRecord[], records: [] as ConsoleRecord[],
consoleHeight: 0, consolesHeight: new Map<string, number>(),
isConsoleOpen: false consolesOpened: new Set([])
}), }),
getters: { getters: {
getLogsByWorkspace: state => (uid: string) => state.records.filter(r => r.cUid === uid) getLogsByWorkspace: state => (uid: string) => state.records.filter(r => r.cUid === uid),
isConsoleOpen: state => (uid: string) => state.consolesOpened.has(uid),
consoleHeight: state => {
const uid = useWorkspacesStore().getSelected;
return state.consolesHeight.get(uid) || 0;
}
}, },
actions: { actions: {
putLog (record: ConsoleRecord) { putLog (record: ConsoleRecord) {
@ -24,23 +30,30 @@ export const useConsoleStore = defineStore('console', {
if (this.records.length > logsSize) if (this.records.length > logsSize)
this.records = this.records.slice(0, logsSize); this.records = this.records.slice(0, logsSize);
}, },
openConsole () {
const uid = useWorkspacesStore().getSelected;
this.consolesOpened.add(uid);
this.consolesHeight.set(uid, 250);
},
closeConsole () {
const uid = useWorkspacesStore().getSelected;
this.consolesOpened.delete(uid);
this.consolesHeight.set(uid, 0);
},
resizeConsole (height: number) { resizeConsole (height: number) {
if (height < 30) { const uid = useWorkspacesStore().getSelected;
this.consoleHeight = 0; if (height < 30)
this.isConsoleOpen = false; this.closeConsole();
}
else else
this.consoleHeight = height; this.consolesHeight.set(uid, height);
}, },
toggleConsole () { toggleConsole () {
if (this.isConsoleOpen) { const uid = useWorkspacesStore().getSelected;
this.isConsoleOpen = false;
this.consoleHeight = 0; if (this.consolesOpened.has(uid))
} this.closeConsole();
else { else
this.isConsoleOpen = true; this.openConsole();
this.consoleHeight = 250;
}
} }
} }
}); });