mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
refactor: CB-1354 context menu code cleanup
This commit is contained in:
@@ -42,10 +42,6 @@ export class NavNodeContextMenuService extends Bootstrap {
|
||||
this.actionService.addHandler({
|
||||
id: 'nav-node-base-handler',
|
||||
isActionApplicable(context, action) {
|
||||
if (context.has(DATA_CONTEXT_MENU_NESTED)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const node = context.tryGet(DATA_CONTEXT_NAV_NODE);
|
||||
|
||||
if (!node) {
|
||||
@@ -57,11 +53,7 @@ export class NavNodeContextMenuService extends Bootstrap {
|
||||
}
|
||||
|
||||
if (action === ACTION_DELETE) {
|
||||
return (
|
||||
node.features?.includes(ENodeFeature.canDelete)
|
||||
// || node.objectFeatures.includes(EObjectFeature.dataSource)
|
||||
|| false
|
||||
);
|
||||
return node.features?.includes(ENodeFeature.canDelete) || false;
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -136,7 +128,7 @@ export class NavNodeContextMenuService extends Bootstrap {
|
||||
});
|
||||
|
||||
this.menuService.addCreator({
|
||||
isApplicable: context => context.has(DATA_CONTEXT_NAV_NODE),
|
||||
isApplicable: context => context.has(DATA_CONTEXT_NAV_NODE) && !context.has(DATA_CONTEXT_MENU_NESTED),
|
||||
getItems: (context, items) => [
|
||||
...items,
|
||||
ACTION_OPEN,
|
||||
|
||||
@@ -53,7 +53,7 @@ export class ConnectionMenuBootstrap extends Bootstrap {
|
||||
|
||||
return (
|
||||
context.has(DATA_CONTEXT_CONNECTION)
|
||||
&& !context.find(DATA_CONTEXT_MENU, MENU_CONNECTION_VIEW)
|
||||
&& !context.has(DATA_CONTEXT_MENU_NESTED)
|
||||
);
|
||||
},
|
||||
getItems: (context, items) => [
|
||||
@@ -79,19 +79,11 @@ export class ConnectionMenuBootstrap extends Bootstrap {
|
||||
|
||||
this.actionService.addHandler({
|
||||
id: 'connection-view',
|
||||
isActionApplicable: (context, action) => {
|
||||
const connection = context.get(DATA_CONTEXT_CONNECTION);
|
||||
|
||||
if (!connection.connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return [
|
||||
ACTION_CONNECTION_VIEW_SIMPLE,
|
||||
ACTION_CONNECTION_VIEW_ADVANCED,
|
||||
ACTION_CONNECTION_VIEW_SYSTEM_OBJECTS,
|
||||
].includes(action);
|
||||
},
|
||||
isActionApplicable: (context, action) => [
|
||||
ACTION_CONNECTION_VIEW_SIMPLE,
|
||||
ACTION_CONNECTION_VIEW_ADVANCED,
|
||||
ACTION_CONNECTION_VIEW_SYSTEM_OBJECTS,
|
||||
].includes(action),
|
||||
isChecked: (context, action) => {
|
||||
const connection = context.get(DATA_CONTEXT_CONNECTION);
|
||||
|
||||
@@ -191,6 +183,7 @@ export class ConnectionMenuBootstrap extends Bootstrap {
|
||||
}
|
||||
case ACTION_CONNECTION_EDIT: {
|
||||
this.publicConnectionFormService.open({ connectionId: connection.id });
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -68,7 +68,11 @@ export class DataExportMenuService {
|
||||
|
||||
this.actionService.addHandler({
|
||||
id: 'data-export',
|
||||
isActionApplicable: (context, action) => action === ACTION_EXPORT,
|
||||
isActionApplicable: (context, action) => (
|
||||
action === ACTION_EXPORT
|
||||
&& context.has(DATA_CONTEXT_CONNECTION)
|
||||
&& context.has(DATA_CONTEXT_NAV_NODE)
|
||||
),
|
||||
handler: async (context, action) => {
|
||||
const node = context.get(DATA_CONTEXT_NAV_NODE);
|
||||
const connection = context.get(DATA_CONTEXT_CONNECTION);
|
||||
|
||||
@@ -71,9 +71,9 @@ export class SqlEditorBootstrap extends Bootstrap {
|
||||
id: 'sql-editor',
|
||||
isActionApplicable: (context, action) => action === ACTION_SQL_EDITOR_OPEN,
|
||||
handler: async (context, action) => {
|
||||
const connection = context.get(DATA_CONTEXT_CONNECTION);
|
||||
const connection = context.tryGet(DATA_CONTEXT_CONNECTION);
|
||||
|
||||
this.sqlEditorNavigatorService.openNewEditor(connection.id);
|
||||
this.sqlEditorNavigatorService.openNewEditor(connection?.id);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user