Skip to content

Commit

Permalink
Merge branch 'devel' into CB-5807-localize-backend-text
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-anton-t authored Dec 12, 2024
2 parents 21787b4 + db9df1f commit 8bbb7ce
Show file tree
Hide file tree
Showing 30 changed files with 204 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ type ConnectionInfo {

properties: Object

template: Boolean!
template: Boolean! @deprecated
connected: Boolean!
provided: Boolean!
readOnly: Boolean!
Expand Down Expand Up @@ -492,7 +492,7 @@ input ConnectionConfig {
description: String

# ID of template connection
templateId: ID
templateId: ID @deprecated
# ID of database driver
driverId: ID

Expand All @@ -519,7 +519,7 @@ input ConnectionConfig {
autocommit: Boolean

# Return template connection state
template: Boolean
template: Boolean @deprecated
# Return read-only connection state
readOnly: Boolean

Expand Down Expand Up @@ -579,7 +579,7 @@ extend type Query {
userConnections( projectId: ID, id: ID, projectIds: [ID!] ): [ ConnectionInfo! ]!

# Return list of template connections by project ID
templateConnections( projectId: ID ): [ ConnectionInfo! ]!
templateConnections( projectId: ID ): [ ConnectionInfo! ]! @deprecated

# List of connection folders
connectionFolders( projectId: ID, path: ID ): [ ConnectionFolderInfo! ]!
Expand Down Expand Up @@ -621,7 +621,7 @@ extend type Mutation {
deleteConnection( id: ID!, projectId: ID ): Boolean!

# Create new custom connection from template
createConnectionFromTemplate( templateId: ID!, projectId: ID!, connectionName: String ): ConnectionInfo!
createConnectionFromTemplate( templateId: ID!, projectId: ID!, connectionName: String ): ConnectionInfo! @deprecated

# Create new folder for connections
createConnectionFolder(parentFolderPath: ID, folderName: String!, projectId: ID ): ConnectionFolderInfo!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ enum CBServerEventId {
cb_datasource_folder_updated,
cb_datasource_folder_deleted,

cb_datasource_disconnected,
cb_datasource_connected,

cb_rm_resource_created,
cb_rm_resource_updated,
cb_rm_resource_deleted,
Expand Down Expand Up @@ -53,6 +56,7 @@ enum CBEventTopic {
cb_object_permissions,
cb_subject_permissions,
cb_database_output_log,
cb_datasource_connection,
cb_delete_temp_folder
}

Expand Down Expand Up @@ -178,6 +182,23 @@ type WSOutputLogInfo {
# Add more fields as needed
}

# Datasource disconnect event
type WSDataSourceDisconnectEvent implements CBServerEvent {
id: CBServerEventId!
topicId: CBEventTopic
connectionId: String!
projectId: String!
timestamp: Int!
}
# Datasource connect event
type WSDataSourceConnectEvent implements CBServerEvent {
id: CBServerEventId!
topicId: CBEventTopic
connectionId: String!
projectId: String!
timestamp: Int!
}

extend type Query {
emptyEvent: Boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.app.DBPPlatform;
import org.jkiss.dbeaver.model.app.DBPProject;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceDisconnectEvent;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceEvent;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty;
import org.jkiss.dbeaver.runtime.jobs.DataSourceMonitorJob;
Expand Down Expand Up @@ -57,14 +58,14 @@ protected void doJob() {
protected void showNotification(@NotNull DBPDataSource dataSource) {
final DBPProject project = dataSource.getContainer().getProject();
if (project.getWorkspaceSession() instanceof WebSession webSession) {
// TODO: Add new event for disconnect datasource
webSession.addSessionEvent(WSDataSourceEvent.update(
webSession.getSessionId(),
webSession.getUserId(),
project.getId(),
List.of(dataSource.getContainer().getId()),
WSDataSourceProperty.CONFIGURATION
));
webSession.addSessionEvent(
new WSDataSourceDisconnectEvent(
project.getId(),
dataSource.getContainer().getId(),
webSession.getSessionId(),
webSession.getUserId()
)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ boolean deleteConnection(
@NotNull String connectionId) throws DBWebException;

@WebAction
@Deprecated
WebConnectionInfo createConnectionFromTemplate(
@NotNull WebSession webSession,
@NotNull String projectId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.jkiss.dbeaver.model.secret.DBSSecretController;
import org.jkiss.dbeaver.model.secret.DBSSecretValue;
import org.jkiss.dbeaver.model.websocket.WSConstants;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceConnectEvent;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDataSourceProperty;
import org.jkiss.dbeaver.registry.DataSourceDescriptor;
import org.jkiss.dbeaver.registry.DataSourceProviderRegistry;
Expand Down Expand Up @@ -366,7 +367,17 @@ public WebConnectionInfo initConnection(

boolean oldSavePassword = dataSourceContainer.isSavePassword();
try {
dataSourceContainer.connect(webSession.getProgressMonitor(), true, false);
boolean connect = dataSourceContainer.connect(webSession.getProgressMonitor(), true, false);
if (connect) {
webSession.addSessionEvent(
new WSDataSourceConnectEvent(
projectId,
connectionId,
webSession.getSessionId(),
webSession.getUserId()
)
);
}
} catch (Exception e) {
throw new DBWebException("Error connecting to database", e);
} finally {
Expand Down Expand Up @@ -600,6 +611,7 @@ public boolean deleteConnection(
}

@Override
@Deprecated
public WebConnectionInfo createConnectionFromTemplate(
@NotNull WebSession webSession,
@NotNull String projectId,
Expand Down
7 changes: 7 additions & 0 deletions webapp/packages/core-blocks/src/ResourcesHooks/useResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type ResourceData<TResource extends IResource<any, any, any, any>, TKey, TInclud

interface IActions<TResource extends IResource<any, any, any, any>, TKey, TIncludes> {
active?: boolean;
/** Indicates whether the resource should be loadable without modifying data, unlike the "active" field */
freeze?: boolean;
forceSuspense?: boolean;
silent?: boolean;
onData?: (data: ResourceData<TResource, TKey, TIncludes>, resource: TResource) => any;
Expand Down Expand Up @@ -184,6 +186,7 @@ export function useResource<
}
return propertiesRef.resource.get(propertiesRef.key);
}

return propertiesRef.resource.data;
}

Expand Down Expand Up @@ -290,6 +293,10 @@ export function useResource<
() => ({
preloaded,
get canLoad(): boolean {
if (actions?.freeze) {
return false;
}

return propertiesRef.key !== null && this.preloaded && this.outdated && !this.loading;
},
get resource() {
Expand Down
34 changes: 34 additions & 0 deletions webapp/packages/core-connections/src/ConnectionInfoResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { schemaValidationError } from '@cloudbeaver/core-utils';

import { CONNECTION_INFO_PARAM_SCHEMA, type IConnectionInfoParams } from './CONNECTION_INFO_PARAM_SCHEMA.js';
import { ConnectionInfoEventHandler, type IConnectionInfoEvent } from './ConnectionInfoEventHandler.js';
import { ConnectionStateEventHandler, type IWsDataSourceConnectEvent, type IWsDataSourceDisconnectEvent } from './ConnectionStateEventHandler.js';
import type { DatabaseConnection } from './DatabaseConnection.js';
import { DBDriverResource } from './DBDriverResource.js';
import { parseConnectionKey } from './parseConnectionKey.js';
Expand Down Expand Up @@ -97,6 +98,7 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
sessionDataResource: SessionDataResource,
appAuthService: AppAuthService,
connectionInfoEventHandler: ConnectionInfoEventHandler,
connectionStateEventHandler: ConnectionStateEventHandler,
userInfoResource: UserInfoResource,
) {
super();
Expand Down Expand Up @@ -163,6 +165,38 @@ export class ConnectionInfoResource extends CachedMapResource<IConnectionInfoPar
this,
);

connectionStateEventHandler.onEvent<IWsDataSourceDisconnectEvent>(
ServerEventId.CbDatasourceDisconnected,
async data => {
const key: IConnectionInfoParams = {
projectId: data.projectId,
connectionId: data.connectionId,
};

if (this.isConnected(key) && !this.isConnecting(key)) {
this.markOutdated(key);
}
},
undefined,
this,
);

connectionStateEventHandler.onEvent<IWsDataSourceConnectEvent>(
ServerEventId.CbDatasourceConnected,
async data => {
const key: IConnectionInfoParams = {
projectId: data.projectId,
connectionId: data.connectionId,
};

if (!this.isConnected(key) && !this.isConnecting(key)) {
this.markOutdated(key);
}
},
undefined,
this,
);

connectionInfoEventHandler.onEvent<ResourceKeyList<IConnectionInfoParams>>(
ServerEventId.CbDatasourceUpdated,
key => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { injectable } from '@cloudbeaver/core-di';
import { type ISessionEvent, type SessionEventId, SessionEventSource, SessionEventTopic, TopicEventHandler } from '@cloudbeaver/core-root';
import type { WsDataSourceConnectEvent, WsDataSourceDisconnectEvent } from '@cloudbeaver/core-sdk';

export type IWsDataSourceDisconnectEvent = WsDataSourceDisconnectEvent;
export type IWsDataSourceConnectEvent = WsDataSourceConnectEvent;

type ConnectionStateEvent = IWsDataSourceConnectEvent | IWsDataSourceDisconnectEvent;

@injectable()
export class ConnectionStateEventHandler extends TopicEventHandler<ConnectionStateEvent, ISessionEvent, SessionEventId, SessionEventTopic> {
constructor(sessionEventSource: SessionEventSource) {
super(SessionEventTopic.CbDatasourceConnection, sessionEventSource);
}

map(event: any): ConnectionStateEvent {
return event;
}
}
1 change: 1 addition & 0 deletions webapp/packages/core-connections/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const manifest: PluginManifest = {
() => import('./ConnectionFolderEventHandler.js').then(m => m.ConnectionFolderEventHandler),
() => import('./ConnectionsSettingsService.js').then(m => m.ConnectionsSettingsService),
() => import('./ConnectionPublicSecretsResource.js').then(m => m.ConnectionPublicSecretsResource),
() => import('./ConnectionStateEventHandler.js').then(m => m.ConnectionStateEventHandler),
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export class NavNodeManagerService extends Bootstrap {
await this.navTree.refreshTree(navNodeId);
}

async refreshNode(navNodeId: string): Promise<void> {
await this.navTree.refreshNode(navNodeId);
}

getTree(navNodeId: string): string[] | undefined;
getTree(navNodeKey: NavNodeKey): string[] | undefined;
getTree(navNodeKey: NavNodeKey[]): Array<string[] | undefined>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<
}

async refreshTree(navNodeId: string, silent = false): Promise<void> {
this.performUpdate(navNodeId, [], async () => {
await this.graphQLService.sdk.navRefreshNode({
nodePath: navNodeId,
});

if (!silent) {
this.markTreeOutdated(navNodeId);
}
await this.onNodeRefresh.execute(navNodeId);
});
}

async refreshNode(navNodeId: string, silent = false): Promise<void> {
this.performUpdate(navNodeId, [], async () => {
await this.graphQLService.sdk.navRefreshNode({
nodePath: navNodeId,
Expand Down Expand Up @@ -257,7 +270,7 @@ export class NavTreeResource extends CachedMapResource<string, string[], Record<
include,
});

this.refreshTree(nodePath);
this.refreshNode(nodePath);
}

async changeName(node: NavNode, name: string): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { createKeyBinding } from '../createKeyBinding.js';

export const KEY_BINDING_REDO = createKeyBinding({
id: 'redo',
keys: ['mod+y', 'mod+shift+z'],
keys: ['mod+y', 'shift+mod+z'],
preventDefault: true,
});
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class ConnectionMenuBootstrap extends Bootstrap {
connection = await this.connectionInfoResource.changeConnectionView(createConnectionParam(connection), settings);

if (connection.nodePath) {
await this.navNodeManagerService.refreshTree(connection.nodePath);
await this.navNodeManagerService.refreshNode(connection.nodePath);
}
} catch (exception: any) {
this.notificationService.logException(exception);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { IKeyBinding } from '@cloudbeaver/core-view';

/* these consts are only used for the user interface in Shortcuts popup, actual bindings in DataGridTable.tsx */
export const KEY_BINDING_REVERT_INLINE_EDITOR_CHANGES: IKeyBinding = {
id: 'data-viewer-revert-inline-editor-changes',
keys: ['Escape'],
};

export const KEY_BINDING_ADD_NEW_ROW: IKeyBinding = {
id: 'data-viewer-add-new-row',
keys: ['Alt+R'],
};

export const KEY_BINDING_DUPLICATE_ROW: IKeyBinding = {
id: 'data-viewer-duplicate-row',
keys: ['Shift+Alt+R'],
};

export const KEY_BINDING_DELETE_ROW: IKeyBinding = {
id: 'data-viewer-delete-row',
keys: ['Delete'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ export const DataGridTable = observer<IDataPresentationProps>(function DataGridT
tableData.editor.revert(...activeElements);
return;
}
case 'Insert': {
case 'KeyR': {
if (event.altKey) {
if (event.ctrlKey || event.metaKey) {
if (event.shiftKey) {
tableData.editor.duplicate(...activeRows);
} else {
tableData.editor.add(cell);
Expand Down
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-spreadsheet-new/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* you may not use this file except in compliance with the License.
*/
export * from './manifest.js';
export * from './DataGrid/DATA_GRID_BINDINGS.js';
1 change: 1 addition & 0 deletions webapp/packages/plugin-help/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@cloudbeaver/core-routing": "^0",
"@cloudbeaver/core-utils": "^0",
"@cloudbeaver/core-view": "^0",
"@cloudbeaver/plugin-data-spreadsheet-new": "^0",
"@cloudbeaver/plugin-navigation-tree": "^0",
"@cloudbeaver/plugin-sql-editor": "^0",
"@cloudbeaver/plugin-top-app-bar": "^0",
Expand Down
Loading

0 comments on commit 8bbb7ce

Please sign in to comment.