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

View File

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

View File

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