change to recent database

This commit is contained in:
Jan Prochazka
2021-03-25 13:20:42 +01:00
parent 2a9c67d2f6
commit 638b04877d
4 changed files with 51 additions and 2 deletions

View File

@@ -0,0 +1,30 @@
import _ from 'lodash';
import { recentDatabases, currentDatabase, getRecentDatabases } from '../stores';
import registerCommand from './registerCommand';
currentDatabase.subscribe(value => {
console.log('DB', value);
if (!value) return;
recentDatabases.update(list => {
const res = [
value,
..._.compact(list).filter(x => x.name != value.name || x.connection?._id != value.connection?.id),
].slice(0, 10);
return res;
});
});
function switchDatabaseCommand(db) {
return {
text: `${db.name} on ${db?.connection?.displayName || db?.connection?.server}`,
onClick: () => currentDatabase.set(db),
};
}
registerCommand({
id: 'database.switch',
category: 'Database',
name: 'Change to recent',
keyText: 'Ctrl+D',
getSubCommands: () => getRecentDatabases().map(switchDatabaseCommand),
});