mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 20:26:00 +00:00
single database fixes
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
database: connection.defaultDatabase,
|
||||
keepOpen: true,
|
||||
});
|
||||
openedSingleDatabaseConnections.update(x => _.uniq([...x, connection._id]));
|
||||
} else {
|
||||
openedConnections.update(x => _.uniq([...x, connection._id]));
|
||||
apiCall('server-connections/refresh', {
|
||||
@@ -41,6 +42,7 @@
|
||||
getCurrentConfig,
|
||||
getOpenedConnections,
|
||||
openedConnections,
|
||||
openedSingleDatabaseConnections,
|
||||
} from '../stores';
|
||||
import { filterName } from 'dbgate-tools';
|
||||
import { showModal } from '../modals/modalTools';
|
||||
@@ -55,6 +57,7 @@
|
||||
import { apiCall } from '../utility/api';
|
||||
import ImportDatabaseDumpModal from '../modals/ImportDatabaseDumpModal.svelte';
|
||||
import { closeMultipleTabs } from '../widgets/TabsPanel.svelte';
|
||||
import AboutModal from '../modals/AboutModal.svelte';
|
||||
|
||||
export let data;
|
||||
export let passProps;
|
||||
@@ -72,10 +75,6 @@
|
||||
};
|
||||
|
||||
const handleOpenConnectionTab = () => {
|
||||
if ($openedConnections.includes(data._id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
openNewTab({
|
||||
title: getConnectionLabel(data),
|
||||
icon: 'img connection',
|
||||
@@ -86,6 +85,18 @@
|
||||
});
|
||||
};
|
||||
|
||||
const handleClick = () => {
|
||||
if ($openedSingleDatabaseConnections.includes(data._id)) {
|
||||
currentDatabase.set({ connection: data, name: data.defaultDatabase });
|
||||
return;
|
||||
}
|
||||
if ($openedConnections.includes(data._id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleOpenConnectionTab();
|
||||
};
|
||||
|
||||
const handleSqlRestore = () => {
|
||||
showModal(ImportDatabaseDumpModal, {
|
||||
connection: data,
|
||||
@@ -198,7 +209,14 @@
|
||||
],
|
||||
data.singleDatabase && [
|
||||
{ divider: true },
|
||||
getDatabaseMenuItems(data, data.defaultDatabase, $extensions, $currentDatabase, $apps),
|
||||
getDatabaseMenuItems(
|
||||
data,
|
||||
data.defaultDatabase,
|
||||
$extensions,
|
||||
$currentDatabase,
|
||||
$apps,
|
||||
$openedSingleDatabaseConnections
|
||||
),
|
||||
],
|
||||
|
||||
driver?.databaseEngineTypes?.includes('sql') && { onClick: handleSqlRestore, text: 'Restore/import SQL dump' },
|
||||
@@ -251,7 +269,7 @@
|
||||
{extInfo}
|
||||
colorMark={passProps?.connectionColorFactory && passProps?.connectionColorFactory({ conid: data._id })}
|
||||
menu={getContextMenu}
|
||||
on:click={handleOpenConnectionTab}
|
||||
on:click={handleClick}
|
||||
on:click
|
||||
on:expand
|
||||
on:dblclick={handleConnect}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
<script lang="ts" context="module">
|
||||
export const extractKey = props => props.name;
|
||||
|
||||
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase, $apps) {
|
||||
export function getDatabaseMenuItems(
|
||||
connection,
|
||||
name,
|
||||
$extensions,
|
||||
$currentDatabase,
|
||||
$apps,
|
||||
$openedSingleDatabaseConnections
|
||||
) {
|
||||
const apps = filterAppsForDatabase(connection, name, $apps);
|
||||
const handleNewQuery = () => {
|
||||
const tooltip = `${getConnectionLabel(connection)}\n${name}`;
|
||||
@@ -132,7 +139,10 @@
|
||||
if (electron) {
|
||||
apiCall('database-connections/disconnect', { conid: connection._id, database: name });
|
||||
}
|
||||
currentDatabase.set(null);
|
||||
if (getCurrentDatabase()?.connection?._id == connection._id && getCurrentDatabase()?.name == name) {
|
||||
currentDatabase.set(null);
|
||||
}
|
||||
openedSingleDatabaseConnections.update(list => list.filter(x => x != connection._id));
|
||||
};
|
||||
|
||||
const handleExportModel = async () => {
|
||||
@@ -233,8 +243,9 @@
|
||||
|
||||
driver?.databaseEngineTypes?.includes('keyvalue') && { onClick: handleGenerateScript, text: 'Generate script' },
|
||||
|
||||
_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
||||
_.get($currentDatabase, 'name') == name && { onClick: handleDisconnect, text: 'Disconnect' },
|
||||
($openedSingleDatabaseConnections.includes(connection._id) ||
|
||||
(_.get($currentDatabase, 'connection._id') == _.get(connection, '_id') &&
|
||||
_.get($currentDatabase, 'name') == name)) && { onClick: handleDisconnect, text: 'Disconnect' },
|
||||
|
||||
commands.length > 0 && [
|
||||
{ divider: true },
|
||||
@@ -266,7 +277,10 @@
|
||||
currentArchive,
|
||||
currentDatabase,
|
||||
extensions,
|
||||
getCurrentDatabase,
|
||||
getExtensions,
|
||||
openedConnections,
|
||||
openedSingleDatabaseConnections,
|
||||
pinnedDatabases,
|
||||
selectedWidget,
|
||||
} from '../stores';
|
||||
@@ -285,13 +299,20 @@
|
||||
import newQuery from '../query/newQuery';
|
||||
import { exportSqlDump } from '../utility/exportFileTools';
|
||||
import ImportDatabaseDumpModal from '../modals/ImportDatabaseDumpModal.svelte';
|
||||
import ExportDatabaseDumpModal from '../modals/ExportDatabaseDumpModal.svelte';
|
||||
import ExportDatabaseDumpModal from '../modals/ExportDatabaseDumpModal.svelte';
|
||||
|
||||
export let data;
|
||||
export let passProps;
|
||||
|
||||
function createMenu() {
|
||||
return getDatabaseMenuItems(data.connection, data.name, $extensions, $currentDatabase, $apps);
|
||||
return getDatabaseMenuItems(
|
||||
data.connection,
|
||||
data.name,
|
||||
$extensions,
|
||||
$currentDatabase,
|
||||
$apps,
|
||||
$openedSingleDatabaseConnections
|
||||
);
|
||||
}
|
||||
|
||||
$: isPinned = !!$pinnedDatabases.find(x => x.name == data.name && x.connection?._id == data.connection?._id);
|
||||
|
||||
@@ -47,6 +47,7 @@ function subscribeCssVariable(store, transform, cssVariable) {
|
||||
|
||||
export const selectedWidget = writableWithStorage('database', 'selectedWidget');
|
||||
export const openedConnections = writable([]);
|
||||
export const openedSingleDatabaseConnections = writable([]);
|
||||
export const expandedConnections = writable([]);
|
||||
export const currentDatabase = writable(null);
|
||||
export const openedTabs = writableWithStorage<TabDefinition[]>([], 'openedTabs');
|
||||
@@ -188,8 +189,12 @@ let currentDatabaseValue = null;
|
||||
currentDatabase.subscribe(value => {
|
||||
currentDatabaseValue = value;
|
||||
if (value?.connection?._id) {
|
||||
openedConnections.update(x => _.uniq([...x, value?.connection?._id]));
|
||||
expandedConnections.update(x => _.uniq([...x, value?.connection?._id]));
|
||||
if (value?.connection?.singleDatabase) {
|
||||
openedSingleDatabaseConnections.update(x => _.uniq([...x, value?.connection?._id]));
|
||||
} else {
|
||||
openedConnections.update(x => _.uniq([...x, value?.connection?._id]));
|
||||
expandedConnections.update(x => _.uniq([...x, value?.connection?._id]));
|
||||
}
|
||||
}
|
||||
invalidateCommands();
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ let lastCurrentTab = null;
|
||||
openedTabs.subscribe(value => {
|
||||
const newCurrentTab = (value || []).find(x => x.selected);
|
||||
if (newCurrentTab == lastCurrentTab) return;
|
||||
if (lastCurrentTab?.tabComponent == 'ConnectionTab') return;
|
||||
|
||||
if (newCurrentTab) {
|
||||
const { conid, database } = newCurrentTab.props || {};
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import _ from 'lodash';
|
||||
import { openedConnections, currentDatabase } from '../stores';
|
||||
import { apiCall } from './api';
|
||||
import { getConnectionList } from './metadataLoaders';
|
||||
|
||||
// const doServerPing = async value => {
|
||||
// const connectionList = getConnectionList();
|
||||
// const connections = value.filter(id => !connectionList.find(x => x._id == id)?.singleDatabase);
|
||||
// apiCall('server-connections/ping', { connections });
|
||||
// };
|
||||
|
||||
const doServerPing = value => {
|
||||
apiCall('server-connections/ping', { connections: value });
|
||||
|
||||
Reference in New Issue
Block a user