mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-16 06:40:05 +08:00
fix(plugin-sql-editor): CB-1498 chain executors
This commit is contained in:
@@ -17,18 +17,16 @@ import { ConnectionInfoResource, Connection } from './ConnectionInfoResource';
|
||||
import { ContainerResource, IStructContainers, ObjectContainer } from './ContainerResource';
|
||||
import { EConnectionFeature } from './EConnectionFeature';
|
||||
|
||||
type ConnectionHandlerState = 'before' | 'after';
|
||||
|
||||
export interface IConnectionHandlerData {
|
||||
export interface IConnectionExecutorData {
|
||||
connectionId: string;
|
||||
state: ConnectionHandlerState;
|
||||
state: 'before' | 'after';
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export class ConnectionsManagerService {
|
||||
readonly connectionExecutor: IExecutor<string | null>;
|
||||
readonly onDisconnect: IExecutor<IConnectionHandlerData>;
|
||||
readonly onDelete: IExecutor<IConnectionHandlerData>;
|
||||
readonly onDisconnect: IExecutor<IConnectionExecutorData>;
|
||||
readonly onDelete: IExecutor<IConnectionExecutorData>;
|
||||
|
||||
private disconnecting: boolean;
|
||||
|
||||
@@ -45,6 +43,7 @@ export class ConnectionsManagerService {
|
||||
this.onDelete = new Executor();
|
||||
|
||||
this.connectionExecutor.addHandler(() => connectionInfo.load(CachedMapAllKey));
|
||||
this.onDelete.before(this.onDisconnect);
|
||||
}
|
||||
|
||||
async requireConnection(connectionId: string | null = null): Promise<Connection | null> {
|
||||
@@ -97,15 +96,6 @@ export class ConnectionsManagerService {
|
||||
return;
|
||||
}
|
||||
|
||||
const contexts = await this.onDelete.execute({
|
||||
connectionId: id,
|
||||
state: 'before',
|
||||
});
|
||||
|
||||
if (ExecutorInterrupter.isInterrupted(contexts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await this.commonDialogService.open(ConfirmationDialogDelete, {
|
||||
title: 'ui_data_delete_confirmation',
|
||||
message: `You're going to delete "${connection.name}" connection. Are you sure?`,
|
||||
@@ -115,6 +105,15 @@ export class ConnectionsManagerService {
|
||||
return;
|
||||
}
|
||||
|
||||
const contexts = await this.onDelete.execute({
|
||||
connectionId: id,
|
||||
state: 'before',
|
||||
});
|
||||
|
||||
if (ExecutorInterrupter.isInterrupted(contexts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.connectionInfo.deleteConnection(id);
|
||||
|
||||
this.onDelete.execute({
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
ConnectionSchemaManagerService,
|
||||
isObjectCatalogProvider, isObjectSchemaProvider, DATA_CONTEXT_NAV_NODE, NavigationTabsService
|
||||
} from '@cloudbeaver/core-app';
|
||||
import { ConnectionsManagerService, IConnectionHandlerData, isConnectionProvider } from '@cloudbeaver/core-connections';
|
||||
import { ConnectionsManagerService, IConnectionExecutorData, isConnectionProvider } from '@cloudbeaver/core-connections';
|
||||
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
|
||||
import { CommonDialogService, DialogueStateResult, RenameDialog } from '@cloudbeaver/core-dialogs';
|
||||
import { ExecutorInterrupter, IExecutionContextProvider, IExecutorHandler } from '@cloudbeaver/core-executor';
|
||||
@@ -52,8 +52,7 @@ export class SqlEditorBootstrap extends Bootstrap {
|
||||
|
||||
register(): void {
|
||||
this.authenticationService.onLogout.addHandler(this.logoutHandler.bind(this));
|
||||
this.connectionsManagerService.onDisconnect.addHandler(this.connectionHandler.bind(this));
|
||||
this.connectionsManagerService.onDelete.addHandler(this.connectionHandler.bind(this));
|
||||
this.connectionsManagerService.onDisconnect.addHandler(this.disconnectHandler.bind(this));
|
||||
|
||||
this.mainMenuService.registerRootItem(
|
||||
{
|
||||
@@ -208,9 +207,9 @@ export class SqlEditorBootstrap extends Bootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
private async connectionHandler(
|
||||
data: IConnectionHandlerData,
|
||||
contexts: IExecutionContextProvider<IConnectionHandlerData>
|
||||
private async disconnectHandler(
|
||||
data: IConnectionExecutorData,
|
||||
contexts: IExecutionContextProvider<IConnectionExecutorData>
|
||||
) {
|
||||
if (data.state === 'before') {
|
||||
for (const tab of this.sqlEditorTabService.sqlEditorTabs) {
|
||||
@@ -218,9 +217,9 @@ export class SqlEditorBootstrap extends Bootstrap {
|
||||
continue;
|
||||
}
|
||||
|
||||
const canPerformAction = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState);
|
||||
const canDisconnect = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState);
|
||||
|
||||
if (!canPerformAction) {
|
||||
if (!canDisconnect) {
|
||||
ExecutorInterrupter.interrupt(contexts);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user