Merge pull request #904 from dbeaver/fix/sql-editor-link

fix(core-app): CB-1675 check if connection is connected
This commit is contained in:
Alexey
2022-06-17 15:34:25 +03:00
committed by GitHub
3 changed files with 21 additions and 14 deletions
@@ -11,7 +11,6 @@ import { injectable } from '@cloudbeaver/core-di';
import { LocalizationService } from '@cloudbeaver/core-localization';
import { ActionService, ACTION_COLLAPSE_ALL, ACTION_FILTER, DATA_CONTEXT_MENU, IAction, IDataContextProvider, KeyBindingService, MenuService } from '@cloudbeaver/core-view';
import { NavNodeInfoResource } from '../../../shared/NodesManager/NavNodeInfoResource';
import { ConnectionSchemaManagerService } from '../../../TopNavBar/ConnectionSchemaManager/ConnectionSchemaManagerService';
import { getNavigationTreeUserSettingsId } from '../../getNavigationTreeUserSettingsId';
import { ACTION_LINK_OBJECT } from '../ACTION_LINK_OBJECT';
@@ -32,7 +31,6 @@ export class ElementsTreeToolsMenuService {
private readonly connectionSchemaManagerService: ConnectionSchemaManagerService,
private readonly menuService: MenuService,
private readonly localizationService: LocalizationService,
private readonly navNodeInfoResource: NavNodeInfoResource,
) {}
register() {
@@ -66,7 +64,7 @@ export class ElementsTreeToolsMenuService {
if (action === ACTION_LINK_OBJECT && tree) {
const navNode = this.connectionSchemaManagerService.activeNavNode;
const nodeInTree = navNode?.path.includes(tree.baseRoot) && this.navNodeInfoResource.has(navNode.nodeId);
const nodeInTree = navNode?.path.includes(tree.baseRoot);
return !nodeInTree;
}
@@ -162,7 +160,7 @@ export class ElementsTreeToolsMenuService {
case ACTION_LINK_OBJECT: {
const navNode = this.connectionSchemaManagerService.activeNavNode;
if (navNode?.path.includes(tree.baseRoot) && this.navNodeInfoResource.has(navNode.nodeId)) {
if (navNode?.path.includes(tree.baseRoot)) {
tree.show(navNode.nodeId, navNode.path);
}
break;
@@ -43,7 +43,7 @@ export class ObjectViewerTabService {
private readonly dbObjectPageService: DBObjectPageService,
private readonly notificationService: NotificationService,
private readonly navigationTabsService: NavigationTabsService,
private readonly connectionInfo: ConnectionInfoResource,
private readonly connectionInfoResource: ConnectionInfoResource,
) {
this.tabHandler = this.navigationTabsService
.registerTabHandler<IObjectViewerTabState>({
@@ -72,9 +72,9 @@ export class ObjectViewerTabService {
registerTabHandler(): void {
this.navNodeManagerService.navigator.addHandler(this.navigationHandler.bind(this));
this.navNodeManagerService.navigator.addPostHandler(this.navigationPostHandler.bind(this));
this.connectionInfo.onConnectionClose.addHandler(this.closeConnectionInfoTabs.bind(this));
this.connectionInfo.onItemAdd.addHandler(this.updateConnectionTabs.bind(this));
this.connectionInfo.onItemDelete.addHandler(this.closeConnectionTabs.bind(this));
this.connectionInfoResource.onConnectionClose.addHandler(this.closeConnectionInfoTabs.bind(this));
this.connectionInfoResource.onItemAdd.addHandler(this.updateConnectionTabs.bind(this));
this.connectionInfoResource.onItemDelete.addHandler(this.closeConnectionTabs.bind(this));
this.navNodeManagerService.navTree.onItemDelete.addHandler(this.removeTabs.bind(this));
}
@@ -219,7 +219,7 @@ export class ObjectViewerTabService {
private async removeTabs(key: ResourceKey<string>) {
const tabs: string[] = [];
await this.connectionInfo.load(CachedMapAllKey);
await this.connectionInfoResource.load(CachedMapAllKey);
ResourceKeyUtils.forEach(key, key => {
const tab = this.navigationTabsService.findTab(
@@ -228,7 +228,7 @@ export class ObjectViewerTabService {
if (tab) {
if (tab.handlerState.connectionId) {
const connection = this.connectionInfo.get(tab.handlerState.connectionId);
const connection = this.connectionInfoResource.get(tab.handlerState.connectionId);
if (connection && !connection.connected) {
return;
@@ -242,7 +242,15 @@ export class ObjectViewerTabService {
this.navigationTabsService.closeTabSilent(resourceKeyList(tabs), true);
}
private getNavNode(context: ITab<IObjectViewerTabState>): IDataContextActiveNode {
private getNavNode(context: ITab<IObjectViewerTabState>) {
if (context.handlerState.connectionId) {
const connection = this.connectionInfoResource.get(context.handlerState.connectionId);
if (!connection?.connected) {
return;
}
}
return {
nodeId: context.handlerState.objectId,
path: context.handlerState.parents,
@@ -308,8 +316,8 @@ export class ObjectViewerTabService {
&& (!tab.handlerState.tabTitle || typeof tab.handlerState.tabTitle === 'string')
) {
if (tab.handlerState.connectionId) {
await this.connectionInfo.load(CachedMapAllKey);
if (!this.connectionInfo.has(tab.handlerState.connectionId)) {
await this.connectionInfoResource.load(CachedMapAllKey);
if (!this.connectionInfoResource.has(tab.handlerState.connectionId)) {
return false;
}
}
@@ -136,8 +136,9 @@ export class SqlEditorTabService extends Bootstrap {
const objectSchema = this.connectionSchemaManagerService.currentObjectSchema;
const nodeId = objectSchema?.id ?? objectCatalog?.id;
const connection = this.connectionInfoResource.getConnectionForNode(nodeId ?? '');
if (!nodeId) {
if (!nodeId || connection?.connected === false) {
return;
}