mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 17:46:00 +00:00
getConnectionLabel refactor
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
export function getDatabaseFileLabel(databaseFile) {
|
||||
if (!databaseFile) return databaseFile;
|
||||
const m = databaseFile.match(/[\/]([^\/]+)$/);
|
||||
if (m) return m[1];
|
||||
return databaseFile;
|
||||
}
|
||||
|
||||
function getConnectionLabelCore(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) {
|
||||
return getDatabaseFileLabel(connection.databaseFile);
|
||||
}
|
||||
if (connection.server) {
|
||||
return connection.server;
|
||||
}
|
||||
if (connection.singleDatabase && connection.defaultDatabase) {
|
||||
return `${connection.defaultDatabase}`;
|
||||
}
|
||||
if (connection.useDatabaseUrl) {
|
||||
return `${connection.databaseUrl}`;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
export default function getConnectionLabel(connection, { allowExplicitDatabase = true, showUnsaved = false } = {}) {
|
||||
const res = getConnectionLabelCore(connection, { allowExplicitDatabase });
|
||||
|
||||
if (res && showUnsaved && connection?.unsaved) {
|
||||
return `${res} - unsaved`;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import ImportExportModal from '../modals/ImportExportModal.svelte';
|
||||
import getElectron from './getElectron';
|
||||
import { currentDatabase, extensions, getCurrentDatabase } from '../stores';
|
||||
import { getUploadListener } from './uploadFiles';
|
||||
import getConnectionLabel, { getDatabaseFileLabel } from './getConnectionLabel';
|
||||
import {getConnectionLabel, getDatabaseFileLabel } from 'dbgate-tools';
|
||||
import { apiCall } from './api';
|
||||
import openNewTab from './openNewTab';
|
||||
import { openJsonDocument } from '../tabs/JsonTab.svelte';
|
||||
|
||||
Reference in New Issue
Block a user