From 7aeffe87c0338faaec10cf853bed67282c585354 Mon Sep 17 00:00:00 2001 From: Wroud Date: Tue, 14 Jul 2020 11:37:28 +0300 Subject: [PATCH] fix(plugin-object-viewer): disconnect behavior --- .../ConnectionInfoResource.ts | 3 ++- .../ConnectionsManagerService.ts | 17 +++++++++++++++-- .../NodesManager/NavNodeManagerService.ts | 7 ++++++- webapp/packages/core-di/src/entities/Entity.ts | 13 +++++++++++++ .../src/ObjectViewerPanel.tsx | 4 ++-- .../src/ObjectViewerTabService.ts | 2 +- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionInfoResource.ts b/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionInfoResource.ts index 6078f41831..27457abb37 100644 --- a/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionInfoResource.ts +++ b/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionInfoResource.ts @@ -23,9 +23,10 @@ export class ConnectionInfoResource extends CachedMapResource { - await this.performUpdate(id, async () => { + const connection = await this.performUpdate(id, async () => { const connection = await this.setActivePromise(id, this.initConnection(id, credentials)); this.set(id, connection); + return connection; }); return this.get(id)!; diff --git a/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionsManagerService.ts b/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionsManagerService.ts index b0a0e61d39..d202169470 100644 --- a/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionsManagerService.ts +++ b/webapp/packages/core-app/src/shared/ConnectionsManager/ConnectionsManagerService.ts @@ -11,7 +11,7 @@ import { Subject } from 'rxjs'; import { injectable } from '@cloudbeaver/core-di'; import { NotificationService } from '@cloudbeaver/core-events'; import { SessionResource } from '@cloudbeaver/core-root'; -import { DataSourceInfo } from '@cloudbeaver/core-sdk'; +import { DataSourceInfo, isResourceKeyList } from '@cloudbeaver/core-sdk'; import { ROOT_NODE_PATH } from '../NodesManager/NavNodeInfoResource'; import { NavNodeManagerService } from '../NodesManager/NavNodeManagerService'; @@ -35,13 +35,26 @@ export class ConnectionsManagerService { private notificationService: NotificationService ) { this.sessionResource.onDataUpdate.subscribe(this.restoreConnections.bind(this)); + this.connectionInfo.onItemAdd.subscribe(async (key) => { + if (isResourceKeyList(key)) { + for (const id of key.list) { + const nodeId = NodeManagerUtils.connectionIdToConnectionNodeId(id); + this.navNodeManagerService + .markTreeOutdated(nodeId); + } + return; + } + const nodeId = NodeManagerUtils.connectionIdToConnectionNodeId(key); + this.navNodeManagerService + .markTreeOutdated(nodeId); + }); } async addOpenedConnection(connection: Connection) { this.addConnection(connection); const nodeId = NodeManagerUtils.connectionIdToConnectionNodeId(connection.id); - await this.navNodeManagerService.loadNode({ nodeId, parentId: ROOT_NODE_PATH }); + await this.navNodeManagerService.refreshNode(nodeId); this.navNodeManagerService.navTree.unshiftToNode(ROOT_NODE_PATH, [nodeId]); } diff --git a/webapp/packages/core-app/src/shared/NodesManager/NavNodeManagerService.ts b/webapp/packages/core-app/src/shared/NodesManager/NavNodeManagerService.ts index a043db6256..070da4318a 100644 --- a/webapp/packages/core-app/src/shared/NodesManager/NavNodeManagerService.ts +++ b/webapp/packages/core-app/src/shared/NodesManager/NavNodeManagerService.ts @@ -121,10 +121,15 @@ export class NavNodeManagerService { await this.graphQLService.gql.navRefreshNode({ nodePath: navNodeId, }); - this.navTree.markOutdated(resourceKeyList(this.navTree.getNestedChildren(navNodeId))); + this.markTreeOutdated(navNodeId); await this.navTree.refresh(navNodeId); } + markTreeOutdated(navNodeId: string) { + const nodes = [navNodeId, ...this.navTree.getNestedChildren(navNodeId)]; + this.navTree.markOutdated(resourceKeyList(nodes)); + } + async updateRootChildren() { if (!await this.permissionsService.hasAsync(EPermission.public)) { this.navTree.delete(ROOT_NODE_PATH); diff --git a/webapp/packages/core-di/src/entities/Entity.ts b/webapp/packages/core-di/src/entities/Entity.ts index 53fded763b..746df4e9df 100644 --- a/webapp/packages/core-di/src/entities/Entity.ts +++ b/webapp/packages/core-di/src/entities/Entity.ts @@ -50,6 +50,19 @@ export class Entity { } } + removeAll() { + const ids: string[] = []; + + for (const [key, value] of this.children) { + ids.push(key); + value.destroyEntity(); + } + + for (const id of ids) { + this.children.delete(id); + } + } + getChild(id: string): Entity | undefined { return this.children.get(id); } diff --git a/webapp/packages/plugin-object-viewer/src/ObjectViewerPanel.tsx b/webapp/packages/plugin-object-viewer/src/ObjectViewerPanel.tsx index 813889a892..8609e48c5d 100644 --- a/webapp/packages/plugin-object-viewer/src/ObjectViewerPanel.tsx +++ b/webapp/packages/plugin-object-viewer/src/ObjectViewerPanel.tsx @@ -39,11 +39,11 @@ const stylesArray = [styles]; export const ObjectViewerPanel = observer(function ObjectViewerPanel({ tab, handler, }: TabHandlerPanelProps) { - const { children, isLoading } = useChildren(tab.handlerState.objectId); + const { children, isOutdated, isLoading } = useChildren(tab.handlerState.objectId); const dbObjectPagesService = useService(DBObjectPageService); const pages = dbObjectPagesService.orderedPages; - if (!children && isLoading) { + if (!isOutdated && isLoading) { return ; } diff --git a/webapp/packages/plugin-object-viewer/src/ObjectViewerTabService.ts b/webapp/packages/plugin-object-viewer/src/ObjectViewerTabService.ts index a45f597d00..b140bd29a6 100644 --- a/webapp/packages/plugin-object-viewer/src/ObjectViewerTabService.ts +++ b/webapp/packages/plugin-object-viewer/src/ObjectViewerTabService.ts @@ -220,8 +220,8 @@ export class ObjectViewerTabService { nodeId: tab.handlerState.objectId, parentId: tab.handlerState.parentId, }); - const children = await this.navNodeManagerService.loadTree(tab.handlerState.objectId); await this.dbObjectService.load(tab.handlerState.objectId); + const children = await this.navNodeManagerService.loadTree(tab.handlerState.objectId); const folderId = tab.handlerState.folderId;