fix: CB-2418 getParents function & preload parents

This commit is contained in:
Wroud
2022-08-29 18:06:42 +03:00
parent 5fb7970fab
commit 5be609fc86
7 changed files with 80 additions and 31 deletions
@@ -112,7 +112,7 @@ extend type Query {
limit: Int,
onlyFolders: Boolean): [ NavigatorNodeInfo! ]!
# Get child nodes
# Get node's parents
navNodeParents( nodePath: ID! ): [ NavigatorNodeInfo! ]!
navNodeInfo( nodePath: ID! ): NavigatorNodeInfo!
@@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
*/
import { action, makeObservable } from 'mobx';
import { action, makeObservable, runInAction } from 'mobx';
import { injectable } from '@cloudbeaver/core-di';
import { SessionPermissionsResource, EPermission } from '@cloudbeaver/core-root';
@@ -24,6 +24,7 @@ import {
import { MetadataMap } from '@cloudbeaver/core-utils';
import type { NavNode } from './EntityTypes';
import { NodeManagerUtils } from './NodeManagerUtils';
type NavNodeInfo = NavNodeInfoFragment;
@@ -99,10 +100,14 @@ export class NavNodeInfoResource extends CachedMapResource<string, NavNode> {
const parents: string[] = [];
let current = this.get(key);
if (!current) {
return NodeManagerUtils.parentsFromPath(key);
}
while (
current
&& current.parentId !== current.id
&& current.parentId !== ROOT_NODE_PATH
// && current.parentId !== ROOT_NODE_PATH
) {
parents.unshift(current.parentId);
current = this.get(current.parentId);
@@ -174,13 +179,42 @@ export class NavNodeInfoResource extends CachedMapResource<string, NavNode> {
}
private async loadNodeInfo(nodePath: string): Promise<NavNode> {
if (this.has(nodePath)) {
const metadata = this.metadata.get(nodePath);
const { navNodeInfo } = await this.graphQLService.sdk.navNodeInfo({
nodePath,
withDetails: metadata.withDetails,
});
return this.navNodeInfoToNavNode(navNodeInfo);
} else {
return await this.loadNodeParents(nodePath);
}
}
private async loadNodeParents(nodePath: string): Promise<NavNode> {
const metadata = this.metadata.get(nodePath);
const { navNodeInfo } = await this.graphQLService.sdk.navNodeInfo({
const { node, parents } = await this.graphQLService.sdk.getNodeParents({
nodePath,
withDetails: metadata.withDetails,
});
return this.navNodeInfoToNavNode(navNodeInfo);
return runInAction(() => {
const navNode = this.navNodeInfoToNavNode(node, parents[0]?.id ?? ROOT_NODE_PATH);
this.updateNode(
resourceKeyList(parents.map(node => node.id), node.id),
[
...parents.reduce((list, node, index, array) => {
list.push(this.navNodeInfoToNavNode(node, array[index + 1]?.id ?? ROOT_NODE_PATH));
return list;
}, [] as NavNode[]),
navNode,
]
);
return navNode;
});
}
}
@@ -362,21 +362,7 @@ export class NavNodeManagerService extends Bootstrap {
canOpen = true;
};
const getParents = () => {
const parents: string[] = [];
let parent = this.getNode(nodeId);
if (!parent) {
return NodeManagerUtils.parentsFromPath(nodeId);
}
while (parent && parent.id !== parent.parentId) {
parents.unshift(parent.parentId);
parent = this.getNode(parent.parentId);
}
return parents;
};
const getParents = () => this.navNodeInfoResource.getParents(nodeId);
const loadParents = async (parents: string[]) => {
let parentId = ROOT_NODE_PATH;
@@ -11,14 +11,14 @@ query navGetStructContainers(
) {
catalogList {
catalog {
...NavNodeInfo
...NavNodeInfo
}
schemaList {
...NavNodeInfo
...NavNodeInfo
}
}
schemaList {
...NavNodeInfo
...NavNodeInfo
}
supportsCatalogChange
supportsSchemaChange
@@ -0,0 +1,11 @@
query getNodeParents(
$nodePath: ID!
$withDetails: Boolean!
) {
node: navNodeInfo(nodePath: $nodePath) {
...NavNodeInfo
}
parents: navNodeParents(nodePath: $nodePath) {
...NavNodeInfo
}
}
+21
View File
@@ -2330,6 +2330,14 @@ export type GetNavNodeFullNameQueryVariables = Exact<{
export type GetNavNodeFullNameQuery = { navNodeInfo: { fullName?: string } };
export type GetNodeParentsQueryVariables = Exact<{
nodePath: Scalars['ID'];
withDetails: Scalars['Boolean'];
}>;
export type GetNodeParentsQuery = { node: { id: string, name?: string, hasChildren?: boolean, nodeType?: string, icon?: string, folder?: boolean, inline?: boolean, navigable?: boolean, features?: Array<string>, object?: { features?: Array<string> }, nodeDetails?: Array<{ id?: string, category?: string, dataType?: string, description?: string, displayName?: string, length: ObjectPropertyLength, features: Array<string>, value?: any, order: number }> }, parents: Array<{ id: string, name?: string, hasChildren?: boolean, nodeType?: string, icon?: string, folder?: boolean, inline?: boolean, navigable?: boolean, features?: Array<string>, object?: { features?: Array<string> }, nodeDetails?: Array<{ id?: string, category?: string, dataType?: string, description?: string, displayName?: string, length: ObjectPropertyLength, features: Array<string>, value?: any, order: number }> }> };
export type NavDeleteNodesMutationVariables = Exact<{
nodePaths: Array<Scalars['ID']> | Scalars['ID'];
}>;
@@ -3779,6 +3787,16 @@ export const GetNavNodeFullNameDocument = `
}
}
`;
export const GetNodeParentsDocument = `
query getNodeParents($nodePath: ID!, $withDetails: Boolean!) {
node: navNodeInfo(nodePath: $nodePath) {
...NavNodeInfo
}
parents: navNodeParents(nodePath: $nodePath) {
...NavNodeInfo
}
}
${NavNodeInfoFragmentDoc}`;
export const NavDeleteNodesDocument = `
mutation navDeleteNodes($nodePaths: [ID!]!) {
navDeleteNodes(nodePaths: $nodePaths)
@@ -4356,6 +4374,9 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
getNavNodeFullName(variables: GetNavNodeFullNameQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GetNavNodeFullNameQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GetNavNodeFullNameQuery>(GetNavNodeFullNameDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getNavNodeFullName', 'query');
},
getNodeParents(variables: GetNodeParentsQueryVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<GetNodeParentsQuery> {
return withWrapper((wrappedRequestHeaders) => client.request<GetNodeParentsQuery>(GetNodeParentsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'getNodeParents', 'query');
},
navDeleteNodes(variables: NavDeleteNodesMutationVariables, requestHeaders?: Dom.RequestInit["headers"]): Promise<NavDeleteNodesMutation> {
return withWrapper((wrappedRequestHeaders) => client.request<NavDeleteNodesMutation>(NavDeleteNodesDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'navDeleteNodes', 'mutation');
},
@@ -6,7 +6,7 @@
* you may not use this file except in compliance with the License.
*/
import { computed, makeObservable } from 'mobx';
import { computed, makeObservable, untracked } from 'mobx';
import {
ConnectionExecutionContextResource,
@@ -28,7 +28,7 @@ import {
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { Executor, ExecutorInterrupter, IExecutionContextProvider } from '@cloudbeaver/core-executor';
import { NavNodeManagerService, objectNavNodeProvider, NodeManagerUtils } from '@cloudbeaver/core-navigation-tree';
import { objectNavNodeProvider, NodeManagerUtils, NavNodeInfoResource } from '@cloudbeaver/core-navigation-tree';
import { CachedMapAllKey, NavNodeInfoFragment, ResourceKey, resourceKeyList, ResourceKeyUtils } from '@cloudbeaver/core-sdk';
import { NavigationTabsService, TabHandler, ITab, ITabOptions } from '@cloudbeaver/plugin-navigation-tabs';
import { SqlResultTabsService, ISqlEditorTabState, SqlEditorService, SqlDataSourceService } from '@cloudbeaver/plugin-sql-editor';
@@ -55,7 +55,7 @@ export class SqlEditorTabService extends Bootstrap {
private readonly connectionExecutionContextService: ConnectionExecutionContextService,
private readonly connectionExecutionContextResource: ConnectionExecutionContextResource,
private readonly connectionInfoResource: ConnectionInfoResource,
private readonly navNodeManagerService: NavNodeManagerService,
private readonly navNodeInfoResource: NavNodeInfoResource,
private readonly sqlDataSourceService: SqlDataSourceService,
private readonly connectionsManagerService: ConnectionsManagerService,
private readonly containerResource: ContainerResource
@@ -190,12 +190,9 @@ export class SqlEditorTabService extends Bootstrap {
return;
}
const parents = NodeManagerUtils.parentsFromPath(nodeId);
const parent = this.navNodeManagerService.getNode(parents[0]);
const parents = this.navNodeInfoResource.getParents(nodeId);
if (parent) {
parents.unshift(parent.parentId);
}
untracked(() => this.navNodeInfoResource.load(nodeId!));
return {
nodeId,