Skip to content

Commit

Permalink
feat: open/close console on single connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Jul 18, 2022
1 parent 3f9e6d8 commit 44647f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/renderer/components/TheFooter.vue
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Workspace.vue
Expand Up @@ -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" />
Expand Down
45 changes: 29 additions & 16 deletions src/renderer/stores/console.ts
@@ -1,5 +1,6 @@
import { ipcRenderer } from 'electron';
import { defineStore } from 'pinia';
import { useWorkspacesStore } from './workspaces';
const logsSize = 1000;

export interface ConsoleRecord {
Expand All @@ -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) {
Expand All @@ -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();
}
}
});
Expand Down

0 comments on commit 44647f5

Please sign in to comment.