From 3618589376439b9a811c745f68c79587acebc927 Mon Sep 17 00:00:00 2001 From: sergeyteleshev Date: Fri, 13 Dec 2024 17:31:05 +0100 Subject: [PATCH] CB-5955 pr fixes --- .../src/NavTree/isConnectionNode.ts | 14 +++++++++++++ webapp/packages/core-connections/src/index.ts | 1 + ...onnectionFolderNode.ts => isFolderNode.ts} | 2 +- .../core-navigation-tree/src/index.ts | 2 +- .../src/CustomConnectionPluginBootstrap.ts | 9 +++------ .../NavNodes/ConnectionFoldersBootstrap.ts | 20 +++++++++---------- .../ElementsTree/TreeSelectionService.ts | 4 ++-- .../NodesManager/NavNodeContextMenuService.ts | 4 ++-- 8 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 webapp/packages/core-connections/src/NavTree/isConnectionNode.ts rename webapp/packages/core-navigation-tree/src/NodesManager/{isConnectionFolderNode.ts => isFolderNode.ts} (83%) diff --git a/webapp/packages/core-connections/src/NavTree/isConnectionNode.ts b/webapp/packages/core-connections/src/NavTree/isConnectionNode.ts new file mode 100644 index 0000000000..adae9c7a9e --- /dev/null +++ b/webapp/packages/core-connections/src/NavTree/isConnectionNode.ts @@ -0,0 +1,14 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2024 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0. + * you may not use this file except in compliance with the License. + */ +import type { NavNode } from '@cloudbeaver/core-navigation-tree'; + +import { NAV_NODE_TYPE_CONNECTION } from './NAV_NODE_TYPE_CONNECTION.js'; + +export function isConnectionNode(node: NavNode | undefined): boolean { + return node?.nodeType === NAV_NODE_TYPE_CONNECTION; +} diff --git a/webapp/packages/core-connections/src/index.ts b/webapp/packages/core-connections/src/index.ts index b0c3372cdb..d6ab151553 100644 --- a/webapp/packages/core-connections/src/index.ts +++ b/webapp/packages/core-connections/src/index.ts @@ -27,6 +27,7 @@ export * from './NavTree/getFolderPath.js'; export * from './NavTree/getConnectionParentId.js'; export * from './NavTree/getFolderNodeParents.js'; export * from './NavTree/NAV_NODE_TYPE_CONNECTION.js'; +export * from './NavTree/isConnectionNode.js'; export * from './extensions/IConnectionProvider.js'; export * from './extensions/IConnectionSetter.js'; diff --git a/webapp/packages/core-navigation-tree/src/NodesManager/isConnectionFolderNode.ts b/webapp/packages/core-navigation-tree/src/NodesManager/isFolderNode.ts similarity index 83% rename from webapp/packages/core-navigation-tree/src/NodesManager/isConnectionFolderNode.ts rename to webapp/packages/core-navigation-tree/src/NodesManager/isFolderNode.ts index 3f724e2a99..6c78bef6d8 100644 --- a/webapp/packages/core-navigation-tree/src/NodesManager/isConnectionFolderNode.ts +++ b/webapp/packages/core-navigation-tree/src/NodesManager/isFolderNode.ts @@ -8,6 +8,6 @@ import type { NavNode } from './EntityTypes.js'; import { NAV_NODE_TYPE_FOLDER } from './NAV_NODE_TYPE_FOLDER.js'; -export function isConnectionFolderNode(node: NavNode | undefined): boolean { +export function isFolderNode(node: NavNode | undefined): boolean { return node?.nodeType === NAV_NODE_TYPE_FOLDER; } diff --git a/webapp/packages/core-navigation-tree/src/index.ts b/webapp/packages/core-navigation-tree/src/index.ts index 48bc428af2..2993ff891d 100644 --- a/webapp/packages/core-navigation-tree/src/index.ts +++ b/webapp/packages/core-navigation-tree/src/index.ts @@ -24,7 +24,7 @@ export * from './NodesManager/navNodeMoveContext.js'; export * from './NodesManager/getNodesFromContext.js'; export * from './NodesManager/NAV_NODE_TYPE_FOLDER.js'; export * from './NodesManager/NAV_NODE_TYPE_ROOT.js'; -export * from './NodesManager/isConnectionFolderNode.js'; +export * from './NodesManager/isFolderNode.js'; export * from './NodesManager/isProjectNode.js'; export * from './NodesManager/ENodeFeature.js'; diff --git a/webapp/packages/plugin-connection-custom/src/CustomConnectionPluginBootstrap.ts b/webapp/packages/plugin-connection-custom/src/CustomConnectionPluginBootstrap.ts index 659e686efa..5f53d1b70d 100644 --- a/webapp/packages/plugin-connection-custom/src/CustomConnectionPluginBootstrap.ts +++ b/webapp/packages/plugin-connection-custom/src/CustomConnectionPluginBootstrap.ts @@ -6,11 +6,11 @@ * you may not use this file except in compliance with the License. */ import { importLazyComponent } from '@cloudbeaver/core-blocks'; -import { ConnectionsManagerService, getFolderPath, NAV_NODE_TYPE_CONNECTION } from '@cloudbeaver/core-connections'; +import { ConnectionsManagerService, getFolderPath, isConnectionNode, NAV_NODE_TYPE_CONNECTION } from '@cloudbeaver/core-connections'; import type { IDataContextProvider } from '@cloudbeaver/core-data-context'; import { Bootstrap, injectable } from '@cloudbeaver/core-di'; import { CommonDialogService } from '@cloudbeaver/core-dialogs'; -import { DATA_CONTEXT_NAV_NODE, NAV_NODE_TYPE_FOLDER } from '@cloudbeaver/core-navigation-tree'; +import { DATA_CONTEXT_NAV_NODE, isFolderNode, isProjectNode, NAV_NODE_TYPE_FOLDER } from '@cloudbeaver/core-navigation-tree'; import { getProjectNodeId, NAV_NODE_TYPE_PROJECT, ProjectInfoResource } from '@cloudbeaver/core-projects'; import { CachedMapAllKey, getCachedMapResourceLoaderState } from '@cloudbeaver/core-resource'; import { ActionService, type IAction, MenuService } from '@cloudbeaver/core-view'; @@ -47,10 +47,7 @@ export class CustomConnectionPluginBootstrap extends Bootstrap { isApplicable: context => { const node = context.get(DATA_CONTEXT_NAV_NODE); - if ( - ![NAV_NODE_TYPE_CONNECTION, NAV_NODE_TYPE_FOLDER, NAV_NODE_TYPE_PROJECT].includes(node?.nodeType ?? '') || - this.isConnectionFeatureDisabled(true) - ) { + if (![isConnectionNode, isFolderNode, isProjectNode].some(check => check(node)) || this.isConnectionFeatureDisabled(true)) { return false; } diff --git a/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts b/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts index c9c4044801..0d501eac6d 100644 --- a/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts +++ b/webapp/packages/plugin-connections/src/NavNodes/ConnectionFoldersBootstrap.ts @@ -18,6 +18,7 @@ import { getConnectionFolderIdFromNodeId, type IConnectionFolderParam, type IConnectionInfoParams, + isConnectionNode, } from '@cloudbeaver/core-connections'; import type { IDataContextProvider } from '@cloudbeaver/core-data-context'; import { Bootstrap, injectable } from '@cloudbeaver/core-di'; @@ -30,8 +31,8 @@ import { ENodeMoveType, getNodesFromContext, type INodeMoveData, - isConnectionFolderNode, - NAV_NODE_TYPE_FOLDER, + isFolderNode, + isProjectNode, type NavNode, NavNodeInfoResource, NavNodeManagerService, @@ -41,7 +42,7 @@ import { ProjectsNavNodeService, ROOT_NODE_PATH, } from '@cloudbeaver/core-navigation-tree'; -import { getProjectNodeId, NAV_NODE_TYPE_PROJECT, ProjectInfoResource } from '@cloudbeaver/core-projects'; +import { getProjectNodeId, ProjectInfoResource } from '@cloudbeaver/core-projects'; import { CachedMapAllKey, resourceKeyList, type ResourceKeySimple, ResourceKeyUtils } from '@cloudbeaver/core-resource'; import { createPath } from '@cloudbeaver/core-utils'; import { ACTION_NEW_FOLDER, ActionService, type IAction, MenuService } from '@cloudbeaver/core-view'; @@ -54,7 +55,6 @@ import { import { FolderDialog } from '@cloudbeaver/plugin-projects'; import { ACTION_TREE_CREATE_FOLDER } from '../Actions/ACTION_TREE_CREATE_FOLDER.js'; -import { NAV_NODE_TYPE_CONNECTION } from './NAV_NODE_TYPE_CONNECTION.js'; @injectable() export class ConnectionFoldersBootstrap extends Bootstrap { @@ -153,7 +153,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap { const targetNode = this.treeSelectionService.getFirstSelectedNode(tree, getProjectNodeId); if ( - ![NAV_NODE_TYPE_CONNECTION, NAV_NODE_TYPE_FOLDER, NAV_NODE_TYPE_PROJECT].includes(node?.nodeType ?? '') || + ![isConnectionNode, isFolderNode, isProjectNode].some(check => check(node)) || !this.userInfoResource.isAuthenticated() || tree.baseRoot !== ROOT_NODE_PATH || targetNode === undefined @@ -175,7 +175,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap { } private async moveConnectionToFolder({ type, targetNode, moveContexts }: INodeMoveData, contexts: IExecutionContextProvider) { - if (![NAV_NODE_TYPE_PROJECT, NAV_NODE_TYPE_FOLDER].includes(targetNode.nodeType!)) { + if (![isProjectNode, isFolderNode].some(check => check(targetNode))) { return; } @@ -189,7 +189,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap { const supported = nodes.every(node => { if ( - ![NAV_NODE_TYPE_CONNECTION, NAV_NODE_TYPE_FOLDER, NAV_NODE_TYPE_PROJECT].includes(node.nodeType!) || + ![isConnectionNode, isFolderNode, isProjectNode].some(check => check(node)) || targetProject !== this.projectsNavNodeService.getProject(node.id) || children.includes(node.id) || targetNode.id === node.id @@ -212,9 +212,9 @@ export class ConnectionFoldersBootstrap extends Bootstrap { const childrenNode = this.navNodeInfoResource.get(resourceKeyList(children)); const folderDuplicates = nodes.filter( node => - isConnectionFolderNode(node) && - (childrenNode.some(child => child && isConnectionFolderNode(child) && child.name === node.name) || - nodes.some(child => isConnectionFolderNode(child) && child.name === node.name && child.id !== node.id)), + isFolderNode(node) && + (childrenNode.some(child => child && isFolderNode(child) && child.name === node.name) || + nodes.some(child => isFolderNode(child) && child.name === node.name && child.id !== node.id)), ); if (folderDuplicates.length > 0) { diff --git a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/TreeSelectionService.ts b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/TreeSelectionService.ts index c0a41813bf..c999b4e3bf 100644 --- a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/TreeSelectionService.ts +++ b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/TreeSelectionService.ts @@ -7,7 +7,7 @@ */ import { ConnectionsManagerService } from '@cloudbeaver/core-connections'; import { injectable } from '@cloudbeaver/core-di'; -import { isConnectionFolderNode, isProjectNode, type NavNode, NavNodeInfoResource, ProjectsNavNodeService } from '@cloudbeaver/core-navigation-tree'; +import { isFolderNode, isProjectNode, type NavNode, NavNodeInfoResource, ProjectsNavNodeService } from '@cloudbeaver/core-navigation-tree'; import { type ProjectInfo } from '@cloudbeaver/core-projects'; import { resourceKeyList } from '@cloudbeaver/core-resource'; import { isNotNullDefined } from '@cloudbeaver/core-utils'; @@ -65,7 +65,7 @@ export class TreeSelectionService { return; } - const selectedFolderNode = this.getParents(tree).slice().reverse().find(isConnectionFolderNode); + const selectedFolderNode = this.getParents(tree).slice().reverse().find(isFolderNode); return { projectId: project.id, diff --git a/webapp/packages/plugin-navigation-tree/src/NodesManager/NavNodeContextMenuService.ts b/webapp/packages/plugin-navigation-tree/src/NodesManager/NavNodeContextMenuService.ts index e8a9168632..a6ceff919d 100644 --- a/webapp/packages/plugin-navigation-tree/src/NodesManager/NavNodeContextMenuService.ts +++ b/webapp/packages/plugin-navigation-tree/src/NodesManager/NavNodeContextMenuService.ts @@ -16,7 +16,7 @@ import { ENodeFeature, getNodePlainName, type INodeActions, - isConnectionFolderNode, + isFolderNode, type NavNode, NavNodeInfoResource, NavNodeManagerService, @@ -101,7 +101,7 @@ export class NavNodeContextMenuService extends Bootstrap { isActionApplicable: (context, action): boolean => { const node = context.get(DATA_CONTEXT_NAV_NODE)!; - if (NodeManagerUtils.isDatabaseObject(node.id) || isConnectionFolderNode(node)) { + if (NodeManagerUtils.isDatabaseObject(node.id) || isFolderNode(node)) { if (action === ACTION_RENAME) { return node.features?.includes(ENodeFeature.canRename) ?? false; }