From 3df44cea4dfca43854e4af75bd10b63554c2dea5 Mon Sep 17 00:00:00 2001 From: Wroud Date: Thu, 11 Jun 2020 11:53:42 +0300 Subject: [PATCH] refactor(core): rename loadConnection in CSMS CB-148 --- .../ConnectionSchemaManagerService.ts | 56 +++++++++++-------- .../ConnectionSelector/ConnectionSelector.tsx | 5 +- .../ConnectionSelectorController.ts | 6 +- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSchemaManagerService.ts b/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSchemaManagerService.ts index 572d3afdda..155d942532 100644 --- a/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSchemaManagerService.ts +++ b/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSchemaManagerService.ts @@ -142,7 +142,7 @@ export class ConnectionSchemaManagerService { return; } this.activeItem.changeConnectionId(connectionId, this.activeItem.context); - this.loadConnection(connectionId); + this.updateContainer(connectionId); } /** @@ -153,7 +153,7 @@ export class ConnectionSchemaManagerService { throw new Error('The try to change catalog without connection'); } this.activeItem.changeCatalogId(catalogId, this.activeItem.context); - this.loadConnection(this.currentConnectionId!, catalogId); + this.updateContainer(this.currentConnectionId, catalogId); } /** @@ -166,6 +166,35 @@ export class ConnectionSchemaManagerService { this.activeItem.changeSchemaId(schemaId, this.activeItem.context); } + async updateContainer(connectionId?: string, catalogId?: string) { + if (!connectionId) { + connectionId = this.currentConnectionId; + } + if (!catalogId) { + catalogId = this.currentObjectCatalogId; + } + if (!connectionId) { + return; + } + + try { + await this.connectionsManagerService.dbDrivers.load(); + } catch (exception) { + this.notificationService.logException(exception, 'Can\'t load database drivers', true); + } + + if (this.activeItem?.changeCatalogId || this.activeItem?.changeSchemaId) { + try { + await this.connectionsManagerService.loadObjectContainer(connectionId, catalogId); + } catch (exception) { + this.notificationService.logException( + exception, + `Can't load objectContainers for ${connectionId}@${catalogId}`, + ); + } + } + } + private onNodeSelect([navNodeId, selected]: [string, boolean]) { if (selected) { const item: IActiveItem = { @@ -238,31 +267,10 @@ export class ConnectionSchemaManagerService { this.activeItem = item; this.activeItemHistory.push(item); - if (this.currentConnectionId) { - this.loadConnection(this.currentConnectionId, this.currentObjectCatalogId); - } + this.updateContainer(); } private clearHistory(id: string) { this.activeItemHistory = this.activeItemHistory.filter(item => item.id !== id); } - - private async loadConnection(connectionId: string, catalogId?: string) { - try { - await this.connectionsManagerService.dbDrivers.load(); - } catch (exception) { - this.notificationService.logException(exception, 'Can\'t load database drivers', true); - } - - if (this.activeItem?.changeCatalogId || this.activeItem?.changeSchemaId) { - try { - await this.connectionsManagerService.loadObjectContainer(connectionId, catalogId); - } catch (exception) { - this.notificationService.logException( - exception, - `Can't load objectContainers for ${connectionId}@${catalogId}`, - ); - } - } - } } diff --git a/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelector.tsx b/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelector.tsx index 254d22c01a..ed82458462 100644 --- a/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelector.tsx +++ b/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelector.tsx @@ -55,7 +55,10 @@ export const ConnectionSelector = observer(function ConnectionSelector() { {controller.isObjectContainerSelectorVisible && ( - + )} ); diff --git a/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelectorController.ts b/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelectorController.ts index 41109aaad4..109951fe86 100644 --- a/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelectorController.ts +++ b/webapp/packages/core/src/app/TopNavBar/ConnectionSchemaManager/ConnectionSelector/ConnectionSelectorController.ts @@ -71,8 +71,10 @@ export class ConnectionSelectorController { return 'database'; } - constructor(private connectionSelectorService: ConnectionSchemaManagerService, - private connectionsManagerService: ConnectionsManagerService) { + constructor( + private connectionSelectorService: ConnectionSchemaManagerService, + private connectionsManagerService: ConnectionsManagerService, + ) { this.connectionMenu = new ComputedMenuItemModel({ id: 'connectionsDropdown',