extracted getConnectionLabel functionality

This commit is contained in:
Jan Prochazka
2021-05-06 11:08:03 +02:00
parent 3d882f47a7
commit 62cedd23b7
10 changed files with 44 additions and 31 deletions

View 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 '';
}