mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 21:46:00 +00:00
handle tab focus
This commit is contained in:
@@ -38,7 +38,7 @@ import { switchCurrentDatabase } from './common';
|
||||
// }
|
||||
// });
|
||||
|
||||
export async function changeDatabaseByCurrentTab() {
|
||||
export async function handleAfterTabClick() {
|
||||
const currentTab = getActiveTab();
|
||||
const { conid, database, objectTypeField, pureName, schemaName, defaultActionId } = currentTab?.props || {};
|
||||
const db = getCurrentDatabase();
|
||||
@@ -67,6 +67,14 @@ export async function changeDatabaseByCurrentTab() {
|
||||
schemaName,
|
||||
});
|
||||
}
|
||||
|
||||
// focus current tab
|
||||
openedTabs.update(tabs => {
|
||||
return tabs.map(tab => ({
|
||||
...tab,
|
||||
focused: !!tab.selected && !tab.closedTime,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
currentDatabase.subscribe(currentDb => {
|
||||
|
||||
@@ -30,12 +30,23 @@ export function markTabSaved(tabid) {
|
||||
openedTabs.update(files => files.map(tab => (tab.tabid == tabid ? { ...tab, unsaved: false } : tab)));
|
||||
}
|
||||
|
||||
export function setSelectedTabFunc(files, tabid, previewModeValue = undefined) {
|
||||
export function setSelectedTabFunc(files, tabid, additionalProps = {}) {
|
||||
return [
|
||||
...(files || []).filter(x => x.tabid != tabid).map(x => ({ ...x, selected: false })),
|
||||
...(files || [])
|
||||
.filter(x => x.tabid != tabid)
|
||||
.map(x => ({
|
||||
...x,
|
||||
selected: false,
|
||||
focused: false,
|
||||
})),
|
||||
...(files || [])
|
||||
.filter(x => x.tabid == tabid)
|
||||
.map(x => ({ ...x, selected: true, tabPreviewMode: previewModeValue ?? x.tabPreviewMode })),
|
||||
.map(x => ({
|
||||
...x,
|
||||
selected: true,
|
||||
focused: false,
|
||||
...additionalProps,
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,9 @@ export default async function openNewTab(newTab, initialData: any = undefined, o
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
openedTabs.update(tabs => setSelectedTabFunc(tabs, existing.tabid, !tabPreviewMode ? false : undefined));
|
||||
openedTabs.update(tabs =>
|
||||
setSelectedTabFunc(tabs, existing.tabid, !tabPreviewMode ? { tabPreviewMode: false } : {})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user