mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 12:26:01 +00:00
tab order by creation
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import uuidv1 from 'uuid/v1';
|
||||
import { get } from 'svelte/store';
|
||||
import { openedTabs } from '../stores';
|
||||
import { getOpenedTabs, openedTabs, tabDatabaseGroupOrder } from '../stores';
|
||||
import tabs from '../tabs';
|
||||
import { setSelectedTabFunc } from './common';
|
||||
import localforage from 'localforage';
|
||||
@@ -72,15 +72,38 @@ export default async function openNewTab(newTab, initialData = undefined, option
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openedTabs.update(files => [
|
||||
...(files || []).map(x => ({ ...x, selected: false })),
|
||||
{
|
||||
...newTab,
|
||||
tabid,
|
||||
selected: true,
|
||||
// @ts-ignore
|
||||
tabOrder: (_.max(files.map(x => x.tabOrder || 0)) || 0) + 1,
|
||||
},
|
||||
]);
|
||||
|
||||
const allOpenedTabs = getOpenedTabs();
|
||||
|
||||
tabDatabaseGroupOrder.update(groupOrder => {
|
||||
const groupOrderFiltered = _.pickBy(groupOrder, (v, k) =>
|
||||
allOpenedTabs.filter(x => x.closedTime == null).find(x => getTabDbKey(x) == k)
|
||||
);
|
||||
const dbKey = getTabDbKey({
|
||||
...newTab,
|
||||
tabid,
|
||||
});
|
||||
const newOrder =
|
||||
groupOrderFiltered[dbKey] ||
|
||||
// @ts-ignore
|
||||
(_.max(Object.values(groupOrderFiltered)) || 0) + 1;
|
||||
return {
|
||||
...groupOrderFiltered,
|
||||
[dbKey]: newOrder,
|
||||
};
|
||||
});
|
||||
|
||||
// console.log('OPENING NEW TAB', newTab);
|
||||
// const tabid = uuidv1();
|
||||
// openedTabs.update(tabs => [
|
||||
@@ -124,3 +147,16 @@ export async function duplicateTab(tab) {
|
||||
{ forceNewTab: true }
|
||||
);
|
||||
}
|
||||
|
||||
export function getTabDbKey(tab) {
|
||||
if (tab.props && tab.props.conid && tab.props.database) {
|
||||
return `database://${tab.props.database}-${tab.props.conid}`;
|
||||
}
|
||||
if (tab.props && tab.props.conid) {
|
||||
return `server://${tab.props.conid}`;
|
||||
}
|
||||
if (tab.props && tab.props.archiveFolder) {
|
||||
return `archive://${tab.props.archiveFolder}`;
|
||||
}
|
||||
return `no://${tab.tabid}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user