database file label

This commit is contained in:
Jan Prochazka 2021-05-06 11:17:30 +02:00
parent 62cedd23b7
commit 1638095c98
3 changed files with 12 additions and 4 deletions

View File

@ -20,6 +20,7 @@
import FormProviderCore from '../forms/FormProviderCore.svelte';
import { extensions } from '../stores';
import _ from 'lodash';
import { getDatabaseFileLabel } from '../utility/getConnectionLabel';
export let connection;
@ -54,6 +55,7 @@
? {
..._.omit(e.detail, ['server', 'port', 'defaultDatabase']),
singleDatabase: true,
defaultDatabase: getDatabaseFileLabel(e.detail.databaseFile),
}
: {
..._.omit(e.detail, ['databaseFile']),

View File

@ -1,3 +1,10 @@
export function getDatabaseFileLabel(databaseFile) {
if (!databaseFile) return databaseFile;
const m = databaseFile.match(/[\/]([^\/]+)$/);
if (m) return m[1];
return databaseFile;
}
export default function getConnectionLabel(connection, { allowExplicitDatabase = true } = {}) {
if (!connection) {
return null;
@ -9,9 +16,7 @@ export default function getConnectionLabel(connection, { allowExplicitDatabase =
return `${connection.defaultDatabase} on ${connection.server}`;
}
if (connection.databaseFile) {
const m = connection.databaseFile.match(/[\/]([^\/]+)$/);
if (m) return m[1];
return connection.databaseFile;
return getDatabaseFileLabel(connection.databaseFile);
}
if (connection.server) {
return connection.server;

View File

@ -12,6 +12,7 @@
import axiosInstance from '../utility/axiosInstance';
import ToolbarButton from './ToolbarButton.svelte';
import runCommand from '../commands/runCommand';
import getConnectionLabel from '../utility/getConnectionLabel';
const connections = useConnectionList();
const serverStatus = useServerStatus();
@ -36,7 +37,7 @@
</SearchBoxWrapper>
<WidgetsInnerContainer>
<AppObjectList
list={_.sortBy(connectionsWithStatus, ({ displayName, server }) => (displayName || server || '').toUpperCase())}
list={_.sortBy(connectionsWithStatus, connection => (getConnectionLabel(connection) || '').toUpperCase())}
module={connectionAppObject}
subItemsComponent={SubDatabaseList}
expandOnClick