mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-24 11:35:54 +08:00
fix(plugin-sql-editor): CB-517 add SQL top nav menu button disabled logic
This commit is contained in:
@@ -77,10 +77,10 @@ export class NavigationTreeService {
|
||||
}
|
||||
|
||||
getView(): IActiveView<string> | null {
|
||||
const context = this.selectedNodes[0];
|
||||
if (!context) {
|
||||
if (!this.selectedNodes.length) {
|
||||
return null;
|
||||
}
|
||||
const context = this.selectedNodes[0];
|
||||
|
||||
return {
|
||||
context,
|
||||
|
||||
@@ -13,6 +13,7 @@ interface ExtensionExecutor {
|
||||
predicate: (extension: IExtension<any>) => extension is T,
|
||||
action: (extension: T) => void
|
||||
) => this;
|
||||
has: (checker: (extension: IExtension<any>) => boolean) => boolean;
|
||||
}
|
||||
|
||||
export const ExtensionUtils = {
|
||||
@@ -29,6 +30,9 @@ export const ExtensionUtils = {
|
||||
}
|
||||
return this;
|
||||
},
|
||||
has(checker: (extension: IExtension<any>) => boolean): boolean {
|
||||
return extensions.some(extension => checker(extension));
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
NavNode, ConnectionSchemaManagerService,
|
||||
isObjectCatalogProvider, isObjectSchemaProvider
|
||||
} from '@cloudbeaver/core-app';
|
||||
import { ConnectionsManagerService, isConnectionProvider } from '@cloudbeaver/core-connections';
|
||||
import { isConnectionProvider } from '@cloudbeaver/core-connections';
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
import { ContextMenuService, IMenuContext } from '@cloudbeaver/core-dialogs';
|
||||
import { ExtensionUtils } from '@cloudbeaver/core-extensions';
|
||||
@@ -27,11 +27,10 @@ export class SqlEditorBootstrap {
|
||||
constructor(
|
||||
private mainMenuService: MainMenuService,
|
||||
private contextMenuService: ContextMenuService,
|
||||
private connectionsManagerService: ConnectionsManagerService,
|
||||
private sqlEditorNavigatorService: SqlEditorNavigatorService,
|
||||
private connectionSchemaManagerService: ConnectionSchemaManagerService,
|
||||
private activeViewService: ActiveViewService
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async bootstrap() {
|
||||
this.mainMenuService.registerRootItem(
|
||||
@@ -40,7 +39,7 @@ export class SqlEditorBootstrap {
|
||||
title: 'SQL',
|
||||
order: 2,
|
||||
onClick: this.openSQLEditor.bind(this),
|
||||
isDisabled: () => !this.connectionsManagerService.hasAnyConnection(),
|
||||
isDisabled: () => this.isSQLEntryDisabled(),
|
||||
}
|
||||
);
|
||||
this.contextMenuService.addMenuItem<NavNode>(this.contextMenuService.getRootMenuToken(), {
|
||||
@@ -59,6 +58,14 @@ export class SqlEditorBootstrap {
|
||||
});
|
||||
}
|
||||
|
||||
private isSQLEntryDisabled() {
|
||||
const activeView = this.activeViewService.view;
|
||||
if (activeView && ExtensionUtils.from(activeView.extensions).has(isConnectionProvider)) {
|
||||
return false;
|
||||
}
|
||||
return !this.connectionSchemaManagerService.currentConnectionId;
|
||||
}
|
||||
|
||||
private openSQLEditor() {
|
||||
let connectionId: string | undefined;
|
||||
let catalogId: string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user