Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/CB-5807-localize-backend-text' i…
Browse files Browse the repository at this point in the history
…nto CB-5807-localize-backend-text
  • Loading branch information
DenisSinelnikov committed Dec 17, 2024
2 parents c545f3f + dc30447 commit b1283b2
Show file tree
Hide file tree
Showing 32 changed files with 431 additions and 212 deletions.
12 changes: 12 additions & 0 deletions webapp/packages/core-connections/src/NavTree/getFolderPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { getFolderPathWithProjectId } from './getFolderPathWithProjectId.js';

export function getFolderPath(folderId: string): string {
return getFolderPathWithProjectId(folderId).split('/').slice(1).join('/');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 { isFolderNodeId } from './isFolderNodeId.js';

export function getFolderPathWithProjectId(folderId: string): string {
if (!isFolderNodeId(folderId)) {
throw new Error('Invalid folder id');
}

return folderId.replace('folder://', '');
}
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;
}
3 changes: 3 additions & 0 deletions webapp/packages/core-connections/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export * from './NavTree/ConnectionNavNodeService.js';
export * from './NavTree/NavNodeExtensionsService.js';
export * from './NavTree/getConnectionFolderIdFromNodeId.js';
export * from './NavTree/getConnectionFolderId.js';
export * from './NavTree/getFolderPathWithProjectId.js';
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
@@ -0,0 +1,13 @@
/*
* 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 './EntityTypes.js';
import { NAV_NODE_TYPE_FOLDER } from './NAV_NODE_TYPE_FOLDER.js';

export function isConnectionFolder(node: NavNode | undefined): boolean {
return node?.nodeType === NAV_NODE_TYPE_FOLDER;
}
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 { NAV_NODE_TYPE_PROJECT } from '@cloudbeaver/core-projects';

import type { NavNode } from './EntityTypes.js';

export function isProjectNode(node: NavNode | undefined): boolean {
return node?.nodeType === NAV_NODE_TYPE_PROJECT;
}
2 changes: 2 additions & 0 deletions webapp/packages/core-navigation-tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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/isConnectionFolder.js';
export * from './NodesManager/isProjectNode.js';

export * from './NodesManager/ENodeFeature.js';
export * from './NodesManager/EObjectFeature.js';
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/core-ui/src/ContextMenu/SubMenuElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const SubMenuElement = observer<ISubMenuElementProps, HTMLButtonElement>(
['handleItemClose', 'hasBindings', 'handleVisibleSwitch'],
);

if (hidden) {
if (hidden || !subMenuData.items.length) {
return null;
}

Expand Down
14 changes: 12 additions & 2 deletions webapp/packages/plugin-app-logo-administration/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
"path": "../plugin-app-logo/tsconfig.json"
}
],
"include": ["__custom_mocks__/**/*", "src/**/*", "src/**/*.json", "src/**/*.css", "src/**/*.scss"],
"exclude": ["**/node_modules", "lib/**/*", "dist/**/*"]
"include": [
"__custom_mocks__/**/*",
"src/**/*",
"src/**/*.json",
"src/**/*.css",
"src/**/*.scss"
],
"exclude": [
"**/node_modules",
"lib/**/*",
"dist/**/*"
]
}
3 changes: 3 additions & 0 deletions webapp/packages/plugin-connection-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@
"dependencies": {
"@cloudbeaver/core-blocks": "^0",
"@cloudbeaver/core-connections": "^0",
"@cloudbeaver/core-data-context": "^0",
"@cloudbeaver/core-di": "^0",
"@cloudbeaver/core-dialogs": "^0",
"@cloudbeaver/core-events": "^0",
"@cloudbeaver/core-localization": "^0",
"@cloudbeaver/core-navigation-tree": "^0",
"@cloudbeaver/core-projects": "^0",
"@cloudbeaver/core-resource": "^0",
"@cloudbeaver/core-settings": "^0",
"@cloudbeaver/core-utils": "^0",
"@cloudbeaver/core-view": "^0",
"@cloudbeaver/plugin-connections": "^0",
"@cloudbeaver/plugin-navigation-tree": "^0",
"mobx": "^6",
"mobx-react-lite": "^4",
"react": "^18"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
* you may not use this file except in compliance with the License.
*/
import { importLazyComponent } from '@cloudbeaver/core-blocks';
import { ConnectionsManagerService } from '@cloudbeaver/core-connections';
import { ConnectionsManagerService, getFolderPath, isConnectionNode } 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 { ProjectInfoResource } from '@cloudbeaver/core-projects';
import { DATA_CONTEXT_NAV_NODE, isConnectionFolder, isProjectNode } from '@cloudbeaver/core-navigation-tree';
import { getProjectNodeId, ProjectInfoResource } from '@cloudbeaver/core-projects';
import { CachedMapAllKey, getCachedMapResourceLoaderState } from '@cloudbeaver/core-resource';
import { ActionService, MenuService } from '@cloudbeaver/core-view';
import { MENU_CONNECTIONS } from '@cloudbeaver/plugin-connections';
import { ActionService, type IAction, MenuService } from '@cloudbeaver/core-view';
import { ACTION_TREE_CREATE_CONNECTION, MENU_CONNECTIONS } from '@cloudbeaver/plugin-connections';
import { DATA_CONTEXT_ELEMENTS_TREE, MENU_NAVIGATION_TREE_CREATE, TreeSelectionService } from '@cloudbeaver/plugin-navigation-tree';

import { ACTION_CONNECTION_CUSTOM } from './Actions/ACTION_CONNECTION_CUSTOM.js';
import { CustomConnectionSettingsService } from './CustomConnectionSettingsService.js';
Expand All @@ -28,6 +31,7 @@ export class CustomConnectionPluginBootstrap extends Bootstrap {
private readonly actionService: ActionService,
private readonly connectionsManagerService: ConnectionsManagerService,
private readonly customConnectionSettingsService: CustomConnectionSettingsService,
private readonly treeSelectionService: TreeSelectionService,
) {
super();
}
Expand All @@ -38,33 +42,70 @@ export class CustomConnectionPluginBootstrap extends Bootstrap {
getItems: (context, items) => [...items, ACTION_CONNECTION_CUSTOM],
});

this.actionService.addHandler({
id: 'connection-custom',
actions: [ACTION_CONNECTION_CUSTOM],
isHidden: (context, action) => {
if (this.connectionsManagerService.createConnectionProjects.length === 0) {
return true;
}
this.menuService.addCreator({
menus: [MENU_NAVIGATION_TREE_CREATE],
isApplicable: context => {
const node = context.get(DATA_CONTEXT_NAV_NODE);

if (action === ACTION_CONNECTION_CUSTOM) {
return this.customConnectionSettingsService.disabled;
if (![isConnectionNode, isConnectionFolder, isProjectNode].some(check => check(node)) || this.isConnectionFeatureDisabled(true)) {
return false;
}

return false;
return true;
},
getItems: (context, items) => [...items, ACTION_TREE_CREATE_CONNECTION],
});

this.actionService.addHandler({
id: 'nav-tree-create-create-connection-handler',
menus: [MENU_NAVIGATION_TREE_CREATE],
actions: [ACTION_TREE_CREATE_CONNECTION],
contexts: [DATA_CONTEXT_ELEMENTS_TREE],
getLoader: (context, action) => getCachedMapResourceLoaderState(this.projectInfoResource, () => CachedMapAllKey),
handler: async (context, action) => {
switch (action) {
case ACTION_CONNECTION_CUSTOM: {
await this.openConnectionsDialog();
break;
}
}
},
handler: this.createConnectionHandler.bind(this),
});

this.actionService.addHandler({
id: 'connection-custom',
actions: [ACTION_CONNECTION_CUSTOM],
isHidden: (context, action) => this.isConnectionFeatureDisabled(action === ACTION_CONNECTION_CUSTOM),
getLoader: (context, action) => getCachedMapResourceLoaderState(this.projectInfoResource, () => CachedMapAllKey),
handler: this.createConnectionHandler.bind(this),
});
}

private async createConnectionHandler(context: IDataContextProvider, action: IAction) {
switch (action) {
case ACTION_TREE_CREATE_CONNECTION: {
const tree = context.get(DATA_CONTEXT_ELEMENTS_TREE)!;
const projectId = this.treeSelectionService.getSelectedProject(tree)?.id;
const selectedNode = this.treeSelectionService.getFirstSelectedNode(tree, getProjectNodeId);
const folderPath = selectedNode?.folderId ? getFolderPath(selectedNode.folderId) : undefined;
await this.openConnectionsDialog(projectId, folderPath);
break;
}
case ACTION_CONNECTION_CUSTOM:
await this.openConnectionsDialog();
break;
}
}

private async openConnectionsDialog() {
await this.commonDialogService.open(DriverSelectorDialog, null);
private isConnectionFeatureDisabled(hasSettings: boolean) {
if (this.connectionsManagerService.createConnectionProjects.length === 0) {
return true;
}

if (hasSettings) {
return this.customConnectionSettingsService.disabled;
}

return false;
}

private async openConnectionsDialog(projectId?: string, folderPath?: string) {
await this.commonDialogService.open(DriverSelectorDialog, {
projectId,
folderPath,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { observer } from 'mobx-react-lite';

import { CommonDialogBody, CommonDialogHeader, CommonDialogWrapper, s, useResource, useS, useTranslate } from '@cloudbeaver/core-blocks';
import { DBDriverResource } from '@cloudbeaver/core-connections';
import type { DialogComponent } from '@cloudbeaver/core-dialogs';
import { ProjectInfoResource } from '@cloudbeaver/core-projects';
import { CachedMapAllKey } from '@cloudbeaver/core-resource';
Expand All @@ -17,23 +16,26 @@ import { DriverSelector } from './DriverSelector.js';
import styles from './DriverSelectorDialog.module.css';
import { useDriverSelectorDialog } from './useDriverSelectorDialog.js';

export const DriverSelectorDialog: DialogComponent<null> = observer(function DriverSelectorDialog({ rejectDialog }) {
type Payload = {
projectId?: string;
folderPath?: string;
};

export const DriverSelectorDialog: DialogComponent<Payload> = observer(function DriverSelectorDialog({ rejectDialog, payload }) {
const translate = useTranslate();
const style = useS(styles);
useResource(DriverSelectorDialog, ProjectInfoResource, CachedMapAllKey, { forceSuspense: true });
const dbDriverResource = useResource(DriverSelectorDialog, DBDriverResource, CachedMapAllKey);

const enabledDrivers = dbDriverResource.resource.enabledDrivers;
const dialog = useDriverSelectorDialog(
enabledDrivers.map(driver => driver.id),
rejectDialog,
);
const dialog = useDriverSelectorDialog({
projectId: payload.projectId,
folderPath: payload.folderPath,
onSelect: rejectDialog,
});

return (
<CommonDialogWrapper size="large" autofocus={false} fixedSize>
<CommonDialogHeader title={translate('plugin_connections_new_connection_dialog_title')} />
<CommonDialogBody noBodyPadding noOverflow>
<DriverSelector className={s(style, { driverSelector: true })} drivers={enabledDrivers} onSelect={dialog.select} />
<DriverSelector className={s(style, { driverSelector: true })} drivers={dialog.enabledDrivers} onSelect={dialog.select} />
</CommonDialogBody>
</CommonDialogWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,56 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { action } from 'mobx';
import { action, observable } from 'mobx';

import { useObservableRef } from '@cloudbeaver/core-blocks';
import { ConnectionsManagerService } from '@cloudbeaver/core-connections';
import { useObservableRef, useResource } from '@cloudbeaver/core-blocks';
import { ConnectionsManagerService, DBDriverResource } from '@cloudbeaver/core-connections';
import { useService } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { CachedMapAllKey } from '@cloudbeaver/core-resource';
import { PublicConnectionFormService } from '@cloudbeaver/plugin-connections';

import type { IDriver } from './Driver.js';

interface State {
select(driverId: string): Promise<void>;
enabledDrivers: IDriver[];
}

interface DriverSelectorDialogArgs {
onSelect?: () => void;
projectId: string | undefined;
folderPath: string | undefined;
}

export function useDriverSelectorDialog(drivers: string[], onSelect?: () => void) {
export function useDriverSelectorDialog({ onSelect, projectId, folderPath }: DriverSelectorDialogArgs) {
const notificationService = useService(NotificationService);
const connectionsManagerService = useService(ConnectionsManagerService);
const publicConnectionFormService = useService(PublicConnectionFormService);
const dbDriverResource = useResource(useDriverSelectorDialog, DBDriverResource, CachedMapAllKey);
const enabledDrivers = dbDriverResource.resource.enabledDrivers;

const state: State = useObservableRef(
() => ({
async select(driverId: string) {
const projects = this.connectionsManagerService.createConnectionProjects;
const drivers = this.enabledDrivers.map(driver => driver.id);

if (projects.length === 0) {
this.notificationService.logError({ title: 'core_projects_no_default_project' });
return;
}

const state = await this.publicConnectionFormService.open(projects[0]!.id, { driverId }, this.drivers);
const selectedProjectId = projects.find(project => project.id === projectId)?.id || projects[0]!.id;
const state = await this.publicConnectionFormService.open(selectedProjectId, { driverId, folder: folderPath }, drivers);

if (state) {
onSelect?.();
}
},
}),
{ select: action.bound },
{ drivers, notificationService, connectionsManagerService, publicConnectionFormService },
{ select: action.bound, enabledDrivers: observable.ref },
{ notificationService, connectionsManagerService, publicConnectionFormService, enabledDrivers },
);

return state;
Expand Down
6 changes: 6 additions & 0 deletions webapp/packages/plugin-connection-custom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
{
"path": "../core-localization/tsconfig.json"
},
{
"path": "../core-navigation-tree/tsconfig.json"
},
{
"path": "../core-projects/tsconfig.json"
},
Expand All @@ -41,6 +44,9 @@
},
{
"path": "../plugin-connections/tsconfig.json"
},
{
"path": "../plugin-navigation-tree/tsconfig.json"
}
],
"include": [
Expand Down
Loading

0 comments on commit b1283b2

Please sign in to comment.