From d7ed00f4a3613da9015c9fc48c4d8062d292e416 Mon Sep 17 00:00:00 2001 From: Fabio Date: Wed, 19 Aug 2020 18:20:57 +0200 Subject: [PATCH] feat: support to multiple query tabs --- src/renderer/components/Workspace.vue | 53 +++++++++++++++---- src/renderer/components/WorkspaceTableTab.vue | 4 +- src/renderer/i18n/en-US.js | 3 +- .../store/modules/workspaces.store.js | 25 ++++++++- 4 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/renderer/components/Workspace.vue b/src/renderer/components/Workspace.vue index 1d589f20..7fdea378 100644 --- a/src/renderer/components/Workspace.vue +++ b/src/renderer/components/Workspace.vue @@ -3,20 +3,22 @@
@@ -78,7 +99,7 @@ export default { return this.selectedWorkspace === this.connection.uid; }, selectedTab () { - return this.workspace.selected_tab || this.queryTabs[0].uid; + return this.queryTabs.find(tab => tab.uid === this.workspace.selected_tab) || ['data', 'prop'].includes(this.workspace.selected_tab) ? this.workspace.selected_tab : this.queryTabs[0].uid; }, queryTabs () { return this.workspace.tabs.filter(tab => tab.type === 'query'); @@ -95,8 +116,16 @@ export default { addWorkspace: 'workspaces/addWorkspace', connectWorkspace: 'workspaces/connectWorkspace', removeConnected: 'workspaces/removeConnected', - selectTab: 'workspaces/selectTab' - }) + selectTab: 'workspaces/selectTab', + newTab: 'workspaces/newTab', + removeTab: 'workspaces/removeTab' + }), + addTab () { + this.newTab(this.connection.uid); + }, + closeTab (tUid) { + this.removeTab({ uid: this.connection.uid, tab: tUid }); + } } }; @@ -132,10 +161,16 @@ export default { opacity: 1; } + &.tab-add { + padding: 0.2rem 0.4rem; + border: 0; + } + > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; + padding: 0 0.2rem; } } diff --git a/src/renderer/components/WorkspaceTableTab.vue b/src/renderer/components/WorkspaceTableTab.vue index ca7bfe71..4ea09a7b 100644 --- a/src/renderer/components/WorkspaceTableTab.vue +++ b/src/renderer/components/WorkspaceTableTab.vue @@ -69,7 +69,7 @@ export default { }, data () { return { - tabUid: 1, + tabUid: 'data', isQuering: false, results: {}, fields: [], @@ -86,7 +86,7 @@ export default { return this.getWorkspace(this.connection.uid); }, isSelected () { - return this.workspace.selected_tab === 1; + return this.workspace.selected_tab === 'data'; } }, watch: { diff --git a/src/renderer/i18n/en-US.js b/src/renderer/i18n/en-US.js index 2071f8cf..f32ace1b 100644 --- a/src/renderer/i18n/en-US.js +++ b/src/renderer/i18n/en-US.js @@ -68,7 +68,8 @@ module.exports = { notificationsTimeout: 'Notifications timeout', uploadFile: 'Upload file', addNewRow: 'Add new row', - numberOfInserts: 'Number of inserts' + numberOfInserts: 'Number of inserts', + openNewTab: 'Open a new tab' }, // Date and Time short: { diff --git a/src/renderer/store/modules/workspaces.store.js b/src/renderer/store/modules/workspaces.store.js index 4ba77fd3..d82d534b 100644 --- a/src/renderer/store/modules/workspaces.store.js +++ b/src/renderer/store/modules/workspaces.store.js @@ -81,6 +81,18 @@ export default { return workspace; }); }, + REMOVE_TAB (state, { uid, tab: tUid }) { + state.workspaces = state.workspaces.map(workspace => { + if (workspace.uid === uid) { + return { + ...workspace, + tabs: workspace.tabs.filter(tab => tab.uid !== tUid) + }; + } + else + return workspace; + }); + }, SELECT_TAB (state, { uid, tab }) { state.workspaces = state.workspaces.map(workspace => workspace.uid === uid ? { ...workspace, selected_tab: tab } : workspace); }, @@ -158,7 +170,13 @@ export default { connected: false, selected_tab: 0, tabs: [{ - uid: 1, + uid: 'data', + type: 'table', + fields: [], + keyUsage: [] + }, + { + uid: 'prop', type: 'table', fields: [], keyUsage: [] @@ -169,7 +187,7 @@ export default { commit('ADD_WORKSPACE', workspace); - if (getters.getWorkspace(uid).tabs.length < 2) + if (getters.getWorkspace(uid).tabs.length < 3) dispatch('newTab', uid); }, changeBreadcrumbs ({ commit, getters }, payload) { @@ -178,6 +196,9 @@ export default { newTab ({ commit }, uid) { commit('NEW_TAB', uid); }, + removeTab ({ commit }, payload) { + commit('REMOVE_TAB', payload); + }, selectTab ({ commit }, payload) { commit('SELECT_TAB', payload); },