fix(plugin-object-viewer): disconnect behavior

This commit is contained in:
Wroud
2020-07-14 11:37:28 +03:00
parent 00afe7ebc2
commit 7aeffe87c0
6 changed files with 39 additions and 7 deletions
@@ -23,9 +23,10 @@ export class ConnectionInfoResource extends CachedMapResource<string, Connection
}
async init(id: string, credentials?: any): Promise<Connection> {
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)!;
@@ -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]);
}
@@ -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);
@@ -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);
}
@@ -39,11 +39,11 @@ const stylesArray = [styles];
export const ObjectViewerPanel = observer(function ObjectViewerPanel({
tab, handler,
}: TabHandlerPanelProps<IObjectViewerTabState>) {
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 <Loader />;
}
@@ -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;