From 8e5584e90fc8a1cea16c80d9d5568958b947f573 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 19 May 2022 12:36:15 +0200 Subject: [PATCH] connection workflow --- packages/web/src/appobj/AppObjectCore.svelte | 1 + packages/web/src/appobj/ConnectionAppObject.svelte | 4 +++- packages/web/src/tabs/ConnectionTab.svelte | 2 -- packages/web/src/utility/openNewTab.ts | 11 ----------- packages/web/src/widgets/TabsPanel.svelte | 12 +++++++----- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/packages/web/src/appobj/AppObjectCore.svelte b/packages/web/src/appobj/AppObjectCore.svelte index b17909fd..7251234e 100644 --- a/packages/web/src/appobj/AppObjectCore.svelte +++ b/packages/web/src/appobj/AppObjectCore.svelte @@ -71,6 +71,7 @@ draggable={true} on:click={handleClick} on:mouseup={handleMouseUp} + on:dblclick use:contextMenu={disableContextMenu ? null : menu} on:dragstart={e => { e.dataTransfer.setData('app_object_drag_data', JSON.stringify(data)); diff --git a/packages/web/src/appobj/ConnectionAppObject.svelte b/packages/web/src/appobj/ConnectionAppObject.svelte index 7f680fb7..0acbb55b 100644 --- a/packages/web/src/appobj/ConnectionAppObject.svelte +++ b/packages/web/src/appobj/ConnectionAppObject.svelte @@ -27,6 +27,7 @@ }); expandedConnections.update(x => _.uniq([...x, connection._id])); } + closeMultipleTabs(x => x.tabComponent == 'ConnectionTab' && x.props?.conid == connection._id, true); } @@ -46,7 +47,7 @@ import ConnectionModal from '../modals/ConnectionModal.svelte'; import ConfirmModal from '../modals/ConfirmModal.svelte'; import InputTextModal from '../modals/InputTextModal.svelte'; - import openNewTab from '../utility/openNewTab'; + import openNewTab, { closeTabWithNoHistory } from '../utility/openNewTab'; import { getDatabaseMenuItems } from './DatabaseAppObject.svelte'; import getElectron from '../utility/getElectron'; import getConnectionLabel from '../utility/getConnectionLabel'; @@ -257,6 +258,7 @@ on:click={handleOpenConnectionTab} on:click on:expand + on:dblclick={handleConnect} on:middleclick={() => { _.flattenDeep(getContextMenu()) .find(x => x.isNewQuery) diff --git a/packages/web/src/tabs/ConnectionTab.svelte b/packages/web/src/tabs/ConnectionTab.svelte index 0ac205a7..24b3579c 100644 --- a/packages/web/src/tabs/ConnectionTab.svelte +++ b/packages/web/src/tabs/ConnectionTab.svelte @@ -24,7 +24,6 @@ import { changeTab } from '../utility/common'; import getConnectionLabel from '../utility/getConnectionLabel'; import { onMount } from 'svelte'; - import { closeTabWithNoHistory } from '../utility/openNewTab'; import { openConnection } from '../appobj/ConnectionAppObject.svelte'; export let connection; @@ -133,7 +132,6 @@ unsaved: true, }; const saved = await apiCall('connections/save', connection); - closeTabWithNoHistory(tabid); openConnection(saved); } diff --git a/packages/web/src/utility/openNewTab.ts b/packages/web/src/utility/openNewTab.ts index dc543dfe..c5301917 100644 --- a/packages/web/src/utility/openNewTab.ts +++ b/packages/web/src/utility/openNewTab.ts @@ -186,14 +186,3 @@ export function groupTabs(tabs: any[]) { return res; } - -export function closeTabWithNoHistory(tabid) { - openedTabs.update(tabs => { - const res = tabs.filter(x => x.tabid != tabid); - const selectedIndex = _.findLastIndex(res, x => x.closedTime == null); - return res.map((x, index) => ({ - ...x, - selected: index == selectedIndex, - })); - }); -} diff --git a/packages/web/src/widgets/TabsPanel.svelte b/packages/web/src/widgets/TabsPanel.svelte index 49c30f85..154b1ef9 100644 --- a/packages/web/src/widgets/TabsPanel.svelte +++ b/packages/web/src/widgets/TabsPanel.svelte @@ -22,12 +22,14 @@ }); }; - export const closeMultipleTabs = closeCondition => { + export const closeMultipleTabs = (closeCondition, deleteFromHistory = false) => { openedTabs.update(files => { - const newFiles = files.map(x => ({ - ...x, - closedTime: x.closedTime || (closeCondition(x) ? new Date().getTime() : undefined), - })); + const newFiles = deleteFromHistory + ? files.filter(x => !closeCondition(x)) + : files.map(x => ({ + ...x, + closedTime: x.closedTime || (closeCondition(x) ? new Date().getTime() : undefined), + })); if (newFiles.find(x => x.selected && x.closedTime == null)) { return newFiles;