mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-21 01:41:31 +00:00
Create tabs manager and refactor tab related logic (#66)
Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
This commit is contained in:
@@ -46,7 +46,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
this.parameters = ko.observable(Date.now());
|
||||
|
||||
this.container.selectedNode.subscribe((newValue: any) => this.triggerRender());
|
||||
this.container.activeTab.subscribe((newValue: ViewModels.Tab) => this.triggerRender());
|
||||
this.container.tabsManager.activeTab.subscribe((newValue: ViewModels.Tab) => this.triggerRender());
|
||||
this.container.isNotebookEnabled.subscribe(newValue => this.triggerRender());
|
||||
|
||||
this.koSubsDatabaseIdMap = new ArrayHashMap();
|
||||
@@ -171,7 +171,9 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
}
|
||||
database.selectDatabase();
|
||||
this.container.onUpdateTabsButtons([]);
|
||||
database.refreshTabSelectedState();
|
||||
this.container.tabsManager.refreshActiveTab(
|
||||
(tab: ViewModels.Tab) => tab.collection && tab.collection.getDatabase().rid === database.rid
|
||||
);
|
||||
},
|
||||
onContextMenuOpen: () => this.container.selectedNode(database)
|
||||
};
|
||||
@@ -268,7 +270,9 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
// Rewritten version of expandCollapseCollection
|
||||
this.container.selectedNode(collection);
|
||||
this.container.onUpdateTabsButtons([]);
|
||||
collection.refreshActiveTab();
|
||||
this.container.tabsManager.refreshActiveTab(
|
||||
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
|
||||
);
|
||||
},
|
||||
onExpanded: () => {
|
||||
if (ResourceTreeAdapter.showScriptNodes(this.container)) {
|
||||
@@ -294,7 +298,9 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
})),
|
||||
onClick: () => {
|
||||
collection.selectedSubnodeKind(ViewModels.CollectionTabKind.StoredProcedures);
|
||||
collection.refreshActiveTab();
|
||||
this.container.tabsManager.refreshActiveTab(
|
||||
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -311,7 +317,9 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
})),
|
||||
onClick: () => {
|
||||
collection.selectedSubnodeKind(ViewModels.CollectionTabKind.UserDefinedFunctions);
|
||||
collection.refreshActiveTab();
|
||||
this.container.tabsManager.refreshActiveTab(
|
||||
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -327,7 +335,9 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
})),
|
||||
onClick: () => {
|
||||
collection.selectedSubnodeKind(ViewModels.CollectionTabKind.Triggers);
|
||||
collection.refreshActiveTab();
|
||||
this.container.tabsManager.refreshActiveTab(
|
||||
(tab: ViewModels.Tab) => tab.collection && tab.collection.rid === collection.rid
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -409,7 +419,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
className: "notebookHeader galleryHeader",
|
||||
onClick: () => this.container.openGallery(),
|
||||
isSelected: () => {
|
||||
const activeTab = this.container.findActiveTab();
|
||||
const activeTab = this.container.tabsManager.activeTab();
|
||||
return activeTab && activeTab.tabKind === ViewModels.CollectionTabKind.Gallery;
|
||||
}
|
||||
};
|
||||
@@ -517,7 +527,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
className: "notebookHeader",
|
||||
onClick: () => onFileClick(item),
|
||||
isSelected: () => {
|
||||
const activeTab = this.container.findActiveTab();
|
||||
const activeTab = this.container.tabsManager.activeTab();
|
||||
return (
|
||||
activeTab &&
|
||||
activeTab.tabKind === ViewModels.CollectionTabKind.NotebookV2 &&
|
||||
@@ -634,7 +644,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
}
|
||||
},
|
||||
isSelected: () => {
|
||||
const activeTab = this.container.findActiveTab();
|
||||
const activeTab = this.container.tabsManager.activeTab();
|
||||
return (
|
||||
activeTab &&
|
||||
activeTab.tabKind === ViewModels.CollectionTabKind.NotebookV2 &&
|
||||
@@ -657,14 +667,6 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
window.requestAnimationFrame(() => this.parameters(Date.now()));
|
||||
}
|
||||
|
||||
private getActiveTab(): ViewModels.Tab {
|
||||
const activeTabs: ViewModels.Tab[] = this.container.openedTabs().filter((tab: ViewModels.Tab) => tab.isActive());
|
||||
if (activeTabs.length) {
|
||||
return activeTabs[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private isDataNodeSelected(rid: string, nodeKind: string, subnodeKind: ViewModels.CollectionTabKind): boolean {
|
||||
if (!this.container.selectedNode || !this.container.selectedNode()) {
|
||||
return false;
|
||||
@@ -674,7 +676,7 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
if (subnodeKind === undefined) {
|
||||
return selectedNode.rid === rid && selectedNode.nodeKind === nodeKind;
|
||||
} else {
|
||||
const activeTab = this.getActiveTab();
|
||||
const activeTab = this.container.tabsManager.activeTab();
|
||||
let selectedSubnodeKind;
|
||||
if (nodeKind === "Database" && (selectedNode as ViewModels.Database).selectedSubnodeKind) {
|
||||
selectedSubnodeKind = (selectedNode as ViewModels.Database).selectedSubnodeKind();
|
||||
|
||||
Reference in New Issue
Block a user