diff --git a/packages/web/src/appobj/ConnectionAppObject.svelte b/packages/web/src/appobj/ConnectionAppObject.svelte
index 907ae4952..43abce2ad 100644
--- a/packages/web/src/appobj/ConnectionAppObject.svelte
+++ b/packages/web/src/appobj/ConnectionAppObject.svelte
@@ -31,7 +31,45 @@
expandedConnections.update(x => _.uniq([...x, connection._id]));
}
}
- closeMultipleTabs(x => x.tabComponent == 'ConnectionTab' && x.props?.conid == connection._id, true);
+ // closeMultipleTabs(x => x.tabComponent == 'ConnectionTab' && x.props?.conid == connection._id, true);
+ }
+ export function disconnectServerConnection(conid, showConfirmation = true) {
+ const closeCondition = x => x.props?.conid == conid && x.tabComponent != 'ConnectionTab' && x.closedTime == null;
+
+ if (showConfirmation) {
+ const count = getOpenedTabs().filter(closeCondition).length;
+ if (count > 0) {
+ showModal(ConfirmModal, {
+ message: `Closing connection will close ${count} opened tabs, continue?`,
+ onConfirm: () => disconnectServerConnection(conid, false),
+ });
+ return;
+ }
+ }
+
+ const electron = getElectron();
+ const currentDb = getCurrentDatabase();
+ openedConnections.update(list => list.filter(x => x != conid));
+ if (electron) {
+ apiCall('server-connections/disconnect', { conid });
+ }
+ if (currentDb?.connection?._id == conid) {
+ if (electron) {
+ apiCall('database-connections/disconnect', { conid, database: currentDb.name });
+ }
+ currentDatabase.set(null);
+ }
+ closeMultipleTabs(closeCondition);
+ // if (data.unsaved) {
+ // openNewTab({
+ // title: 'New Connection',
+ // icon: 'img connection',
+ // tabComponent: 'ConnectionTab',
+ // props: {
+ // conid: data._id,
+ // },
+ // });
+ // }
}
@@ -43,7 +81,9 @@
expandedConnections,
extensions,
getCurrentConfig,
+ getCurrentDatabase,
getOpenedConnections,
+ getOpenedTabs,
openedConnections,
openedSingleDatabaseConnections,
} from '../stores';
@@ -118,27 +158,7 @@
apiCall('server-connections/refresh', { conid: data._id });
};
const handleDisconnect = () => {
- openedConnections.update(list => list.filter(x => x != data._id));
- if (electron) {
- apiCall('server-connections/disconnect', { conid: data._id });
- }
- if (_.get($currentDatabase, 'connection._id') == data._id) {
- if (electron) {
- apiCall('database-connections/disconnect', { conid: data._id, database: $currentDatabase.name });
- }
- currentDatabase.set(null);
- }
- closeMultipleTabs(x => x.props.conid == data._id);
- if (data.unsaved) {
- openNewTab({
- title: 'New Connection',
- icon: 'img connection',
- tabComponent: 'ConnectionTab',
- props: {
- conid: data._id,
- },
- });
- }
+ disconnectServerConnection(data._id);
};
const handleDelete = () => {
showModal(ConfirmModal, {
@@ -180,8 +200,8 @@
return [
config.runAsPortal == false && [
- !$openedConnections.includes(data._id) && {
- text: 'Edit',
+ {
+ text: $openedConnections.includes(data._id) ? 'View details' : 'Edit',
onClick: handleOpenConnectionTab,
},
!$openedConnections.includes(data._id) && {
diff --git a/packages/web/src/appobj/DatabaseAppObject.svelte b/packages/web/src/appobj/DatabaseAppObject.svelte
index 6f8e6a45e..f339559fd 100644
--- a/packages/web/src/appobj/DatabaseAppObject.svelte
+++ b/packages/web/src/appobj/DatabaseAppObject.svelte
@@ -1,6 +1,35 @@
{#if driver?.showConnectionField('databaseFile', $values)}
-
+
{/if}
{#if driver?.showConnectionField('useDatabaseUrl', $values)}
+
{/if}
{#if $authTypes && driver?.showConnectionField('authType', $values)}
@@ -72,6 +80,7 @@
label="Authentication"
name="authType"
isNative
+ disabled={isConnected}
defaultValue={driver?.defaultAuthTypeName}
options={$authTypes.map(auth => ({
value: auth.name,
@@ -86,7 +95,7 @@
@@ -95,7 +104,7 @@
@@ -117,7 +126,7 @@
@@ -127,7 +136,7 @@
@@ -135,10 +144,10 @@
{/if}
{#if showUser && !showPassword}
-
+
{/if}
{#if !showUser && showPassword}
-
+
{/if}
{#if !disabledFields.includes('password') && showPassword}
@@ -147,6 +156,7 @@
isNative
name="passwordMode"
defaultValue="saveEncrypted"
+ disabled={isConnected}
options={[
{ value: 'saveEncrypted', label: 'Save and encrypt' },
{ value: 'saveRaw', label: 'Save raw (UNSAFE!!)' },
@@ -155,21 +165,26 @@
{/if}
{#if driver?.showConnectionField('isReadOnly', $values)}
-
+
{/if}
{#if driver?.showConnectionField('defaultDatabase', $values)}
-
+
{/if}
{#if defaultDatabase && driver?.showConnectionField('singleDatabase', $values)}
-
+
{/if}
{#if driver}
diff --git a/packages/web/src/settings/ConnectionSshTunnelFields.svelte b/packages/web/src/settings/ConnectionSshTunnelFields.svelte
index 8c735ef38..bde6ef679 100644
--- a/packages/web/src/settings/ConnectionSshTunnelFields.svelte
+++ b/packages/web/src/settings/ConnectionSshTunnelFields.svelte
@@ -11,7 +11,7 @@
import getElectron from '../utility/getElectron';
import { usePlatformInfo } from '../utility/metadataLoaders';
import FontIcon from '../icons/FontIcon.svelte';
- import { extensions } from '../stores';
+ import { extensions, openedConnections, openedSingleDatabaseConnections } from '../stores';
const { values, setFieldValue } = getFormContext();
const electron = getElectron();
@@ -24,31 +24,38 @@
// if (!$values.sshPort) setFieldValue('sshPort', '22');
if (!$values.sshKeyfile && $platformInfo) setFieldValue('sshKeyfile', $platformInfo.defaultKeyfile);
}
+
+ $: isConnected = $openedConnections.includes($values._id) || $openedSingleDatabaseConnections.includes($values._id);
-
+
-
+
{#if $values.sshMode != 'userPassword'}
-
+
{/if}
{#if $values.sshMode == 'userPassword'}
@@ -90,7 +102,7 @@
diff --git a/packages/web/src/settings/ConnectionSslFields.svelte b/packages/web/src/settings/ConnectionSslFields.svelte
index 5b7cae504..24936f42f 100644
--- a/packages/web/src/settings/ConnectionSslFields.svelte
+++ b/packages/web/src/settings/ConnectionSslFields.svelte
@@ -6,20 +6,30 @@
import FormCheckboxField from '../forms/FormCheckboxField.svelte';
import getElectron from '../utility/getElectron';
import FormPasswordField from '../forms/FormPasswordField.svelte';
+ import { openedConnections, openedSingleDatabaseConnections } from '../stores';
const { values, setFieldValue } = getFormContext();
const electron = getElectron();
$: useSsl = $values.useSsl;
+ $: isConnected = $openedConnections.includes($values._id) || $openedSingleDatabaseConnections.includes($values._id);
-
-
-
+
+
+
-
-
+
+
diff --git a/packages/web/src/tabs/ConnectionTab.svelte b/packages/web/src/tabs/ConnectionTab.svelte
index 25f746c2a..97feb2bb2 100644
--- a/packages/web/src/tabs/ConnectionTab.svelte
+++ b/packages/web/src/tabs/ConnectionTab.svelte
@@ -17,15 +17,22 @@
import ErrorMessageModal from '../modals/ErrorMessageModal.svelte';
import { writable } from 'svelte/store';
import FormProviderCore from '../forms/FormProviderCore.svelte';
- import { extensions, getCurrentConfig, openedTabs } from '../stores';
+ import {
+ extensions,
+ getCurrentConfig,
+ openedConnections,
+ openedSingleDatabaseConnections,
+ openedTabs,
+ } from '../stores';
import _, { Dictionary } from 'lodash';
import { apiCall } from '../utility/api';
import { showSnackbarSuccess } from '../utility/snackbar';
import { changeTab } from '../utility/common';
import getConnectionLabel from '../utility/getConnectionLabel';
import { onMount } from 'svelte';
- import { openConnection } from '../appobj/ConnectionAppObject.svelte';
+ import { disconnectServerConnection, openConnection } from '../appobj/ConnectionAppObject.svelte';
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
+ import { disconnectDatabaseConnection } from '../appobj/DatabaseAppObject.svelte';
export let connection;
export let tabid;
@@ -136,7 +143,15 @@
}
const saved = await apiCall('connections/save', connection);
openConnection(saved);
- closeMultipleTabs(x => x.tabid == tabid, true);
+ // closeMultipleTabs(x => x.tabid == tabid, true);
+ }
+
+ async function handleDisconnect() {
+ if ($values.singleDatabase) {
+ disconnectDatabaseConnection($values._id, $values.defaultDatabase);
+ } else {
+ disconnectServerConnection($values._id);
+ }
}
onMount(async () => {
@@ -144,6 +159,8 @@
$values = await apiCall('connections/get', { conid });
}
});
+
+ $: isConnected = $openedConnections.includes($values._id) || $openedSingleDatabaseConnections.includes($values._id);
@@ -171,13 +188,17 @@
{#if driver}
-
- {#if isTesting}
-
+ {#if isConnected}
+
{:else}
-
+
+ {#if isTesting}
+
+ {:else}
+
+ {/if}
+
{/if}
-
{#if !isTesting && sqlConnectResult && sqlConnectResult.msgtype == 'connected'}
diff --git a/packages/web/src/utility/changeCurrentDbByTab.ts b/packages/web/src/utility/changeCurrentDbByTab.ts
index 3e4fc5714..c3b75caf3 100644
--- a/packages/web/src/utility/changeCurrentDbByTab.ts
+++ b/packages/web/src/utility/changeCurrentDbByTab.ts
@@ -11,7 +11,7 @@ openedTabs.subscribe(value => {
const lastTab = lastCurrentTab;
lastCurrentTab = newCurrentTab;
- if (lastTab?.tabComponent == 'ConnectionTab') return;
+ // if (lastTab?.tabComponent == 'ConnectionTab') return;
if (newCurrentTab) {
const { conid, database } = newCurrentTab.props || {};