Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisSinelnikov committed Sep 8, 2023
2 parents 017e621 + 4e0c23e commit e28cedd
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.cloudbeaver;

import org.jkiss.dbeaver.model.access.DBAPermissionRealm;
import org.jkiss.dbeaver.model.rm.RMConstants;

/**
* General constants
Expand All @@ -25,7 +26,7 @@ public class DBWConstants {

public static final String PERMISSION_ADMIN = DBAPermissionRealm.PERMISSION_ADMIN;

public static final String PERMISSION_CONFIGURATION_MANAGER = "configuration-manager";
public static final String PERMISSION_CONFIGURATION_MANAGER = RMConstants.PERMISSION_CONFIGURATION_MANAGER;
public static final String PERMISSION_PRIVATE_PROJECT_ACCESS = "private-project-access";

public static final String PERMISSION_EDIT_STRUCTURE = "edit-meta";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class ConnectionNavNodeService extends Dependency {
connection = await this.connectionsManagerService.requireConnection(createConnectionParam(connection));

if (!connection?.connected) {
throw new Error('Connection not established');
ExecutorInterrupter.interrupt(contexts);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions webapp/packages/core-events/src/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ export class NotificationService {
console.error(exception);
}

throwSilently(exception: Error | GQLError | undefined | null): void {
this.logError({
title: '',
details: exception,
isSilent: true,
});
throw exception;
}

close(id: number, delayDeleting = true): void {
// TODO: emit event or something

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ export class ConnectionSchemaManagerBootstrap extends Bootstrap {

this.menuService.addCreator({
menus: [MENU_CONNECTION_DATA_CONTAINER_SELECTOR],
isApplicable: () => this.connectionSchemaManagerService.isObjectCatalogChangeable && !!this.connectionSchemaManagerService.objectContainerList,
isApplicable: () =>
(this.connectionSchemaManagerService.isObjectCatalogChangeable || this.connectionSchemaManagerService.isObjectSchemaChangeable) &&
!!this.connectionSchemaManagerService.objectContainerList,
getItems: (context, items) => {
items = [...items];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ export function useElementsTree(options: IOptions): IElementsTree {
options.expandStateGetters = useMemo(() => options.expandStateGetters || [], [...(options.expandStateGetters || [])]);
const state = options.localState || localTreeNodesState;

async function handleLoadChildren(id: string, manual: boolean): Promise<boolean> {
try {
return await options.loadChildren(id, manual);
} catch (exception: any) {
notificationService.logException(exception);
return false;
}
}

const functionsRef = useObjectRef({
async loadTree(nodeId: string) {
elementsTree.loading = true;
Expand Down Expand Up @@ -194,7 +203,7 @@ export function useElementsTree(options: IOptions): IElementsTree {
return;
}

const loaded = await options.loadChildren(child, false);
const loaded = await handleLoadChildren(child, false);

if (!loaded) {
const node = navNodeInfoResource.get(child);
Expand Down Expand Up @@ -530,7 +539,7 @@ export function useElementsTree(options: IOptions): IElementsTree {
if (!leaf && this.settings?.foldersTree && expandableOrExpanded) {
const nodeId = node.id;

const loaded = await options.loadChildren(node.id, true);
const loaded = await handleLoadChildren(node.id, false);
if (loaded) {
this.setFilter('');
options.folderExplorer.open(path, nodeId);
Expand All @@ -549,7 +558,7 @@ export function useElementsTree(options: IOptions): IElementsTree {

try {
if (state || (this.filtering && !treeNodeState.showInFilter)) {
state = await options.loadChildren(node.id, true);
state = await handleLoadChildren(node.id, true);
}

if (this.filtering) {
Expand Down Expand Up @@ -611,7 +620,7 @@ export function useElementsTree(options: IOptions): IElementsTree {
async loadPath(path: string[], lastNode?: string): Promise<string | undefined> {
let lastLoadedNode: string | undefined;
for (const nodeId of path) {
const loaded = await options.loadChildren(nodeId, false);
const loaded = await handleLoadChildren(nodeId, false);

if (!loaded) {
return lastLoadedNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,53 +72,43 @@ export class NavigationTreeService extends View<string> {
await this.navNodeManagerService.navToNode(id, parentId);
}

async loadNestedNodes(id = ROOT_NODE_PATH, tryConnect?: boolean, notify = true): Promise<boolean> {
try {
if (this.isConnectionNode(id)) {
let connection = this.connectionInfoResource.getConnectionForNode(id);

if (connection) {
connection = await this.connectionInfoResource.load(createConnectionParam(connection));
} else {
async loadNestedNodes(id = ROOT_NODE_PATH, tryConnect?: boolean): Promise<boolean> {
if (this.isConnectionNode(id)) {
let connection = this.connectionInfoResource.getConnectionForNode(id);

if (connection) {
connection = await this.connectionInfoResource.load(createConnectionParam(connection));
} else {
return false;
}

if (!connection.connected) {
if (!tryConnect) {
return false;
}

if (!connection.connected) {
if (!tryConnect) {
return false;
}

try {
const connected = await this.tryInitConnection(createConnectionParam(connection));
if (!connected) {
return false;
}
} catch {
return false;
}
const connected = await this.tryInitConnection(createConnectionParam(connection));
if (!connected) {
return false;
}
}
}

await this.navTreeResource.waitLoad();

if (tryConnect && this.navTreeResource.getException(id)) {
this.navTreeResource.markOutdated(id);
}
await this.navTreeResource.waitLoad();

const parents = this.navNodeInfoResource.getParents(id);
if (tryConnect && this.navTreeResource.getException(id)) {
this.navTreeResource.markOutdated(id);
}

if (parents.length > 0 && !this.navNodeInfoResource.has(id)) {
return false;
}
const parents = this.navNodeInfoResource.getParents(id);

await this.navTreeResource.load(CachedResourcePageKey(CACHED_RESOURCE_DEFAULT_PAGE_OFFSET, this.navTreeResource.childrenLimit).setTarget(id));
return true;
} catch (exception: any) {
if (notify) {
this.notificationService.logException(exception);
}
if (parents.length > 0 && !this.navNodeInfoResource.has(id)) {
return false;
}
return false;

await this.navTreeResource.load(CachedResourcePageKey(CACHED_RESOURCE_DEFAULT_PAGE_OFFSET, this.navTreeResource.childrenLimit).setTarget(id));

return true;
}

selectNode(id: string, multiple?: boolean): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import { useObjectRef } from '@cloudbeaver/core-blocks';
import { useService } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import type { NavNode } from '@cloudbeaver/core-navigation-tree';

import { NavigationTreeService } from './NavigationTreeService';
Expand All @@ -22,13 +23,19 @@ const bindActions: Array<keyof INavigationTree> = ['handleOpen', 'handleSelect',

export function useNavigationTree(): INavigationTree {
const navigationTreeService = useService(NavigationTreeService);
const notificationService = useService(NotificationService);

return useObjectRef<INavigationTree>(
() => ({
navigationTreeService,
async handleOpen(node: NavNode, folder: boolean) {
if (!folder) {
await this.navigationTreeService.navToNode(node.id, node.parentId);
try {
await this.navigationTreeService.navToNode(node.id, node.parentId);
} catch (exception: any) {
notificationService.logException(exception);
throw exception;
}
}
},
handleSelect(node: NavNode, state: boolean) {
Expand Down
8 changes: 7 additions & 1 deletion webapp/packages/plugin-sql-editor/src/SqlEditorOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getRealExecutionContextId,
} from '@cloudbeaver/core-connections';
import { useService } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { NodeManagerUtils } from '@cloudbeaver/core-navigation-tree';

import type { ISqlEditorTabState } from './ISqlEditorTabState';
Expand All @@ -50,6 +51,7 @@ export const SqlEditorOverlay = observer<Props>(function SqlEditorOverlay({ stat
const translate = useTranslate();
const sqlEditorService = useService(SqlEditorService);
const sqlDataSourceService = useService(SqlDataSourceService);
const notificationService = useService(NotificationService);
const dataSource = sqlDataSourceService.get(state.editorId);
const executionContextId = dataSource?.executionContext?.id;
const executionContext = dataSource?.executionContext;
Expand Down Expand Up @@ -77,7 +79,11 @@ export const SqlEditorOverlay = observer<Props>(function SqlEditorOverlay({ stat
}

async function init() {
await sqlEditorService.initEditorConnection(state);
try {
await sqlEditorService.initEditorConnection(state);
} catch (exception: any) {
notificationService.logException(exception);
}
}

const dataContainer = getComputed(() =>
Expand Down

0 comments on commit e28cedd

Please sign in to comment.