mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 21:56:00 +00:00
extracted getConnectionLabel functionality
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
|
import { getDatabaseMenuItems } from './DatabaseAppObject.svelte';
|
||||||
import getElectron from '../utility/getElectron';
|
import getElectron from '../utility/getElectron';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
};
|
};
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
showModal(ConfirmModal, {
|
showModal(ConfirmModal, {
|
||||||
message: `Really delete connection ${data.displayName || data.server}?`,
|
message: `Really delete connection ${getConnectionLabel(data)}?`,
|
||||||
onConfirm: () => axiosInstance.post('connections/delete', data),
|
onConfirm: () => axiosInstance.post('connections/delete', data),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -74,7 +75,7 @@
|
|||||||
axiosInstance.post('connections/save', {
|
axiosInstance.post('connections/save', {
|
||||||
...data,
|
...data,
|
||||||
_id: undefined,
|
_id: undefined,
|
||||||
displayName: `${data.displayName || data.server} - copy`,
|
displayName: `${getConnectionLabel(data)} - copy`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const handleCreateDatabase = () => {
|
const handleCreateDatabase = () => {
|
||||||
@@ -90,7 +91,7 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const handleNewQuery = () => {
|
const handleNewQuery = () => {
|
||||||
const tooltip = `${data.displayName || data.server}`;
|
const tooltip = `${getConnectionLabel(data)}`;
|
||||||
openNewTab({
|
openNewTab({
|
||||||
title: 'Query #',
|
title: 'Query #',
|
||||||
icon: 'img sql-file',
|
icon: 'img sql-file',
|
||||||
@@ -172,30 +173,12 @@
|
|||||||
statusTitle = null;
|
statusTitle = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// const handleEdit = () => {
|
|
||||||
// showModal(modalState => <ConnectionModal modalState={modalState} connection={data} />);
|
|
||||||
// };
|
|
||||||
// const handleDelete = () => {
|
|
||||||
// showModal(modalState => (
|
|
||||||
// <ConfirmModal
|
|
||||||
// modalState={modalState}
|
|
||||||
// message={`Really delete connection ${data.displayName || data.server}?`}
|
|
||||||
// onConfirm={() => axios.post('connections/delete', data)}
|
|
||||||
// />
|
|
||||||
// ));
|
|
||||||
// };
|
|
||||||
// const handleCreateDatabase = () => {
|
|
||||||
// showModal(modalState => <CreateDatabaseModal modalState={modalState} conid={data._id} />);
|
|
||||||
// };
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AppObjectCore
|
<AppObjectCore
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
{data}
|
{data}
|
||||||
title={data.singleDatabase
|
title={getConnectionLabel(data)}
|
||||||
? data.displayName || `${data.defaultDatabase} on ${data.server}`
|
|
||||||
: data.displayName || data.server}
|
|
||||||
icon={data.singleDatabase ? 'img database' : 'img server'}
|
icon={data.singleDatabase ? 'img database' : 'img server'}
|
||||||
isBold={data.singleDatabase
|
isBold={data.singleDatabase
|
||||||
? _.get($currentDatabase, 'connection._id') == data._id && _.get($currentDatabase, 'name') == data.defaultDatabase
|
? _.get($currentDatabase, 'connection._id') == data._id && _.get($currentDatabase, 'name') == data.defaultDatabase
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase) {
|
export function getDatabaseMenuItems(connection, name, $extensions, $currentDatabase) {
|
||||||
const handleNewQuery = () => {
|
const handleNewQuery = () => {
|
||||||
const tooltip = `${connection.displayName || connection.server}\n${name}`;
|
const tooltip = `${getConnectionLabel(connection)}\n${name}`;
|
||||||
openNewTab({
|
openNewTab({
|
||||||
title: 'Query #',
|
title: 'Query #',
|
||||||
icon: 'img sql-file',
|
icon: 'img sql-file',
|
||||||
@@ -66,6 +66,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||||
import { showModal } from '../modals/modalTools';
|
import { showModal } from '../modals/modalTools';
|
||||||
|
|||||||
@@ -228,7 +228,7 @@
|
|||||||
initialData
|
initialData
|
||||||
) {
|
) {
|
||||||
const connection = await getConnectionInfo({ conid });
|
const connection = await getConnectionInfo({ conid });
|
||||||
const tooltip = `${connection.displayName || connection.server}\n${database}\n${fullDisplayName({
|
const tooltip = `${getConnectionLabel(connection)}\n${database}\n${fullDisplayName({
|
||||||
schemaName,
|
schemaName,
|
||||||
pureName,
|
pureName,
|
||||||
})}`;
|
})}`;
|
||||||
@@ -267,6 +267,7 @@
|
|||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import uuidv1 from 'uuid/v1';
|
import uuidv1 from 'uuid/v1';
|
||||||
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
import SqlGeneratorModal from '../modals/SqlGeneratorModal.svelte';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
import { currentDatabase } from '../stores';
|
import { currentDatabase } from '../stores';
|
||||||
|
|
||||||
import axiosInstance from '../utility/axiosInstance';
|
import axiosInstance from '../utility/axiosInstance';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import hasPermission from '../utility/hasPermission';
|
import hasPermission from '../utility/hasPermission';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
|
|
||||||
@@ -130,7 +131,7 @@
|
|||||||
const database = _.get($currentDatabase, 'name');
|
const database = _.get($currentDatabase, 'name');
|
||||||
connProps.conid = connection._id;
|
connProps.conid = connection._id;
|
||||||
connProps.database = database;
|
connProps.database = database;
|
||||||
tooltip = `${connection.displayName || connection.server}\n${database}`;
|
tooltip = `${getConnectionLabel(connection)}\n${database}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
openNewTab(
|
openNewTab(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { recentDatabases, currentDatabase, getRecentDatabases } from '../stores';
|
import { recentDatabases, currentDatabase, getRecentDatabases } from '../stores';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import registerCommand from './registerCommand';
|
import registerCommand from './registerCommand';
|
||||||
|
|
||||||
currentDatabase.subscribe(value => {
|
currentDatabase.subscribe(value => {
|
||||||
@@ -15,7 +16,7 @@ currentDatabase.subscribe(value => {
|
|||||||
|
|
||||||
function switchDatabaseCommand(db) {
|
function switchDatabaseCommand(db) {
|
||||||
return {
|
return {
|
||||||
text: `${db.name} on ${db?.connection?.displayName || db?.connection?.server}`,
|
text: `${db.name} on ${getConnectionLabel(db?.connection, { allowExplicitDatabase: false })}`,
|
||||||
onClick: () => currentDatabase.set(db),
|
onClick: () => currentDatabase.set(db),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import FormSelectField from '../forms/FormSelectField.svelte';
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import { useConnectionList } from '../utility/metadataLoaders';
|
import { useConnectionList } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
$: connections = useConnectionList();
|
$: connections = useConnectionList();
|
||||||
$: connectionOptions = _.sortBy(
|
$: connectionOptions = _.sortBy(
|
||||||
($connections || []).map(conn => ({
|
($connections || []).map(conn => ({
|
||||||
value: conn._id,
|
value: conn._id,
|
||||||
label: conn.displayName || conn.server,
|
label: getConnectionLabel(conn),
|
||||||
})),
|
})),
|
||||||
'label'
|
'label'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { currentDatabase } from '../stores';
|
import { currentDatabase } from '../stores';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import openNewTab from '../utility/openNewTab';
|
import openNewTab from '../utility/openNewTab';
|
||||||
|
|
||||||
export default function newQuery({
|
export default function newQuery({
|
||||||
@@ -14,7 +15,7 @@ export default function newQuery({
|
|||||||
const connection = _.get($currentDatabase, 'connection') || {};
|
const connection = _.get($currentDatabase, 'connection') || {};
|
||||||
const database = _.get($currentDatabase, 'name');
|
const database = _.get($currentDatabase, 'name');
|
||||||
|
|
||||||
const tooltip = `${connection.displayName || connection.server}\n${database}`;
|
const tooltip = `${getConnectionLabel(connection)}\n${database}`;
|
||||||
|
|
||||||
openNewTab(
|
openNewTab(
|
||||||
{
|
{
|
||||||
|
|||||||
20
packages/web/src/utility/getConnectionLabel.ts
Normal file
20
packages/web/src/utility/getConnectionLabel.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
export default function getConnectionLabel(connection, { allowExplicitDatabase = true } = {}) {
|
||||||
|
if (!connection) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (connection.displayName) {
|
||||||
|
return connection.displayName;
|
||||||
|
}
|
||||||
|
if (connection.singleDatabase && connection.server && allowExplicitDatabase && connection.defaultDatabase) {
|
||||||
|
return `${connection.defaultDatabase} on ${connection.server}`;
|
||||||
|
}
|
||||||
|
if (connection.databaseFile) {
|
||||||
|
const m = connection.databaseFile.match(/[\/]([^\/]+)$/);
|
||||||
|
if (m) return m[1];
|
||||||
|
return connection.databaseFile;
|
||||||
|
}
|
||||||
|
if (connection.server) {
|
||||||
|
return connection.server;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
|
||||||
import { activeTabId, currentDatabase } from '../stores';
|
import { activeTabId, currentDatabase } from '../stores';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import { useDatabaseServerVersion, useDatabaseStatus } from '../utility/metadataLoaders';
|
import { useDatabaseServerVersion, useDatabaseStatus } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
$: databaseName = $currentDatabase && $currentDatabase.name;
|
$: databaseName = $currentDatabase && $currentDatabase.name;
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
$: serverVersion = useDatabaseServerVersion(connection ? { conid: connection._id, database: databaseName } : {});
|
$: serverVersion = useDatabaseServerVersion(connection ? { conid: connection._id, database: databaseName } : {});
|
||||||
|
|
||||||
$: contextItems = $statusBarTabInfo[$activeTabId] as any[];
|
$: contextItems = $statusBarTabInfo[$activeTabId] as any[];
|
||||||
|
$: connectionLabel = getConnectionLabel(connection, { allowExplicitDatabase: false });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="main">
|
<div class="main">
|
||||||
@@ -33,10 +35,10 @@
|
|||||||
{databaseName}
|
{databaseName}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if connection && (connection.displayName || connection.server)}
|
{#if connectionLabel}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<FontIcon icon="icon server" />
|
<FontIcon icon="icon server" />
|
||||||
{connection.displayName || connection.server}
|
{connectionLabel}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if connection && connection.user}
|
{#if connection && connection.user}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
if (tab.props && tab.props.conid && tab.props.database) return tab.props.database;
|
if (tab.props && tab.props.conid && tab.props.database) return tab.props.database;
|
||||||
if (tab.props && tab.props.conid) {
|
if (tab.props && tab.props.conid) {
|
||||||
const connection = connectionList?.find(x => x._id == tab.props.conid);
|
const connection = connectionList?.find(x => x._id == tab.props.conid);
|
||||||
if (connection) return connection.displayName || connection.server;
|
if (connection) return getConnectionLabel(connection.displayName, { allowExplicitDatabase: false });
|
||||||
return '???';
|
return '???';
|
||||||
}
|
}
|
||||||
if (tab.props && tab.props.archiveFolder) return tab.props.archiveFolder;
|
if (tab.props && tab.props.archiveFolder) return tab.props.archiveFolder;
|
||||||
@@ -124,6 +124,7 @@
|
|||||||
import tabs from '../tabs';
|
import tabs from '../tabs';
|
||||||
import { setSelectedTab } from '../utility/common';
|
import { setSelectedTab } from '../utility/common';
|
||||||
import contextMenu from '../utility/contextMenu';
|
import contextMenu from '../utility/contextMenu';
|
||||||
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import { getConnectionInfo, useConnectionList } from '../utility/metadataLoaders';
|
import { getConnectionInfo, useConnectionList } from '../utility/metadataLoaders';
|
||||||
import { duplicateTab } from '../utility/openNewTab';
|
import { duplicateTab } from '../utility/openNewTab';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user