Skip to content

Commit

Permalink
CB-5955 pr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyteleshev committed Dec 13, 2024
1 parent 2761970 commit 3618589
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
14 changes: 14 additions & 0 deletions webapp/packages/core-connections/src/NavTree/isConnectionNode.ts
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions webapp/packages/core-connections/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion webapp/packages/core-navigation-tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -30,8 +31,8 @@ import {
ENodeMoveType,
getNodesFromContext,
type INodeMoveData,
isConnectionFolderNode,
NAV_NODE_TYPE_FOLDER,
isFolderNode,
isProjectNode,
type NavNode,
NavNodeInfoResource,
NavNodeManagerService,
Expand All @@ -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';
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -175,7 +175,7 @@ export class ConnectionFoldersBootstrap extends Bootstrap {
}

private async moveConnectionToFolder({ type, targetNode, moveContexts }: INodeMoveData, contexts: IExecutionContextProvider<INodeMoveData>) {
if (![NAV_NODE_TYPE_PROJECT, NAV_NODE_TYPE_FOLDER].includes(targetNode.nodeType!)) {
if (![isProjectNode, isFolderNode].some(check => check(targetNode))) {
return;
}

Expand All @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ENodeFeature,
getNodePlainName,
type INodeActions,
isConnectionFolderNode,
isFolderNode,
type NavNode,
NavNodeInfoResource,
NavNodeManagerService,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3618589

Please sign in to comment.