diff --git a/webapp/packages/core-app/src/shared/NodesManager/NavNodeContextMenuService.ts b/webapp/packages/core-app/src/shared/NodesManager/NavNodeContextMenuService.ts index 8648be6840..8fc42445c9 100644 --- a/webapp/packages/core-app/src/shared/NodesManager/NavNodeContextMenuService.ts +++ b/webapp/packages/core-app/src/shared/NodesManager/NavNodeContextMenuService.ts @@ -9,7 +9,7 @@ import { Bootstrap, injectable } from '@cloudbeaver/core-di'; import { CommonDialogService, ConfirmationDialogDelete, DialogueStateResult, RenameDialog } from '@cloudbeaver/core-dialogs'; import { NotificationService } from '@cloudbeaver/core-events'; -import { ActionService, ACTION_DELETE, ACTION_OPEN, ACTION_REFRESH, ACTION_RENAME, DATA_CONTEXT_MENU_NESTED, MenuSeparatorItem, MenuService } from '@cloudbeaver/core-view'; +import { ActionService, ACTION_DELETE, ACTION_OPEN, ACTION_REFRESH, ACTION_RENAME, DATA_CONTEXT_MENU_NESTED, menuExtractActions, MenuSeparatorItem, MenuService } from '@cloudbeaver/core-view'; import { CoreSettingsService } from '../../CoreSettingsService'; import { DATA_CONTEXT_NAV_NODE_ACTIONS } from '../../NavigationTree/NavigationTreeNode/TreeNodeMenu/DATA_CONTEXT_NAV_NODE_ACTIONS'; @@ -152,40 +152,22 @@ export class NavNodeContextMenuService extends Bootstrap { ], orderItems: (context, items) => { - const refreshIndex = items.indexOf(ACTION_REFRESH); - if (refreshIndex > -1) { - items.splice(refreshIndex, 1); - } + const actionsManage = menuExtractActions(items, [ + ACTION_DELETE, + ACTION_RENAME, + ]); - const renameIndex = items.indexOf(ACTION_RENAME); - if (renameIndex > -1) { - items.splice(renameIndex, 1); - } + const actionsRefresh = menuExtractActions(items, [ + ACTION_REFRESH, + ]); - const deleteIndex = items.indexOf(ACTION_DELETE); - if (deleteIndex > -1) { - items.splice(deleteIndex, 1); - } + items.push(...actionsManage); - if (deleteIndex > -1) { - // if (items.length > 0) { - // items.push(new MenuSeparatorItem()); - // } - items.push(ACTION_DELETE); - } - - if (renameIndex > -1) { - // if (items.length > 0 && deleteIndex === -1) { - // items.push(new MenuSeparatorItem()); - // } - items.push(ACTION_RENAME); - } - - if (refreshIndex > -1) { - if (items.length > 0) { + if (actionsRefresh.length > 0) { + if (items.length > 0){ items.push(new MenuSeparatorItem()); } - items.push(ACTION_REFRESH); + items.push(...actionsRefresh); } return items; diff --git a/webapp/packages/core-ui/src/Tabs/TabsBootstrap.ts b/webapp/packages/core-ui/src/Tabs/TabsBootstrap.ts index 4ec85f020d..bca603407b 100644 --- a/webapp/packages/core-ui/src/Tabs/TabsBootstrap.ts +++ b/webapp/packages/core-ui/src/Tabs/TabsBootstrap.ts @@ -6,17 +6,17 @@ * you may not use this file except in compliance with the License. */ -import { Bootstrap, injectable } from "@cloudbeaver/core-di"; -import { ActionService, DATA_CONTEXT_MENU, MenuService } from "@cloudbeaver/core-view"; +import { Bootstrap, injectable } from '@cloudbeaver/core-di'; +import { ActionService, DATA_CONTEXT_MENU, menuExtractActions, MenuSeparatorItem, MenuService } from '@cloudbeaver/core-view'; -import { ACTION_TAB_CLOSE } from "./Actions/ACTION_TAB_CLOSE"; -import { ACTION_TAB_CLOSE_ALL } from "./Actions/ACTION_TAB_CLOSE_ALL"; -import { ACTION_TAB_CLOSE_ALL_TO_THE_LEFT } from "./Actions/ACTION_TAB_CLOSE_ALL_TO_THE_LEFT"; -import { ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT } from "./Actions/ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT"; -import { ACTION_TAB_CLOSE_OTHERS } from "./Actions/ACTION_TAB_CLOSE_OTHERS"; -import { DATA_CONTEXT_TAB_ID } from "./Tab/DATA_CONTEXT_TAB_ID"; -import { DATA_CONTEXT_TABS_CONTEXT } from "./Tab/DATA_CONTEXT_TABS_CONTEXT"; -import { MENU_TAB } from "./Tab/MENU_TAB"; +import { ACTION_TAB_CLOSE } from './Actions/ACTION_TAB_CLOSE'; +import { ACTION_TAB_CLOSE_ALL } from './Actions/ACTION_TAB_CLOSE_ALL'; +import { ACTION_TAB_CLOSE_ALL_TO_THE_LEFT } from './Actions/ACTION_TAB_CLOSE_ALL_TO_THE_LEFT'; +import { ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT } from './Actions/ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT'; +import { ACTION_TAB_CLOSE_OTHERS } from './Actions/ACTION_TAB_CLOSE_OTHERS'; +import { DATA_CONTEXT_TAB_ID } from './Tab/DATA_CONTEXT_TAB_ID'; +import { DATA_CONTEXT_TABS_CONTEXT } from './Tab/DATA_CONTEXT_TABS_CONTEXT'; +import { MENU_TAB } from './Tab/MENU_TAB'; @injectable() export class TabsBootstrap extends Bootstrap { @@ -24,7 +24,7 @@ export class TabsBootstrap extends Bootstrap { private readonly actionService: ActionService, private readonly menuService: MenuService ) { - super() + super(); } register(): void | Promise { @@ -88,7 +88,7 @@ export class TabsBootstrap extends Bootstrap { this.menuService.addCreator({ isApplicable: context => { const state = context.tryGet(DATA_CONTEXT_TABS_CONTEXT); - return !!state?.enabledBaseActions && context.get(DATA_CONTEXT_MENU) === MENU_TAB + return !!state?.enabledBaseActions && context.get(DATA_CONTEXT_MENU) === MENU_TAB; }, getItems: (context, items) => [ ...items, @@ -96,8 +96,26 @@ export class TabsBootstrap extends Bootstrap { ACTION_TAB_CLOSE_ALL, ACTION_TAB_CLOSE_OTHERS, ACTION_TAB_CLOSE_ALL_TO_THE_LEFT, - ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT + ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT, ], + orderItems: (context, items) => { + const actions = menuExtractActions(items, [ + ACTION_TAB_CLOSE, + ACTION_TAB_CLOSE_ALL, + ACTION_TAB_CLOSE_OTHERS, + ACTION_TAB_CLOSE_ALL_TO_THE_LEFT, + ACTION_TAB_CLOSE_ALL_TO_THE_RIGHT, + ]); + + if (actions.length > 0) { + if (items.length > 0){ + items.push(new MenuSeparatorItem()); + } + items.push(...actions); + } + + return items; + }, }); } diff --git a/webapp/packages/core-view/src/Menu/menuExtractActions.ts b/webapp/packages/core-view/src/Menu/menuExtractActions.ts new file mode 100644 index 0000000000..1cb14e552c --- /dev/null +++ b/webapp/packages/core-view/src/Menu/menuExtractActions.ts @@ -0,0 +1,24 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2022 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 { IAction } from '../Action/IAction'; +import type { MenuCreatorItem } from './IMenuItemsCreator'; + +export function menuExtractActions(items: MenuCreatorItem[], actions: IAction[]): IAction[] { + const list: IAction[] = []; + + for (const action of actions){ + const index = items.indexOf(action); + if (index > -1) { + items.splice(index, 1); + } + list.push(action); + } + + return list; +} diff --git a/webapp/packages/core-view/src/index.ts b/webapp/packages/core-view/src/index.ts index 9110f0b5c9..b2c668a152 100644 --- a/webapp/packages/core-view/src/index.ts +++ b/webapp/packages/core-view/src/index.ts @@ -32,9 +32,10 @@ export * from './Menu/MenuItem/MenuLazyItem'; export * from './Menu/MenuItem/MenuSeparatorItem'; export * from './Menu/MenuItem/MenuSubMenuItem'; export * from './Menu/createMenu'; -export * from './Menu/IMenu'; export * from './Menu/DATA_CONTEXT_MENU_NESTED'; export * from './Menu/DATA_CONTEXT_MENU'; +export * from './Menu/IMenu'; +export * from './Menu/menuExtractActions'; export * from './Menu/MenuService'; export * from './Menu/useMenu'; export * from './Menu/useMenuContext'; diff --git a/webapp/packages/plugin-data-export/src/DataExportMenuService.ts b/webapp/packages/plugin-data-export/src/DataExportMenuService.ts index 503628a30a..3bcf03361a 100644 --- a/webapp/packages/plugin-data-export/src/DataExportMenuService.ts +++ b/webapp/packages/plugin-data-export/src/DataExportMenuService.ts @@ -20,9 +20,9 @@ import { DataExportDialog } from './Dialog/DataExportDialog'; @injectable() export class DataExportMenuService { constructor( - private commonDialogService: CommonDialogService, - private tableFooterMenuService: TableFooterMenuService, - private dataExportSettingsService: DataExportSettingsService, + private readonly commonDialogService: CommonDialogService, + private readonly tableFooterMenuService: TableFooterMenuService, + private readonly dataExportSettingsService: DataExportSettingsService, private readonly actionService: ActionService, private readonly menuService: MenuService, ) { } diff --git a/webapp/packages/plugin-sql-editor-screen/src/PluginBootstrap.ts b/webapp/packages/plugin-sql-editor-screen/src/PluginBootstrap.ts index d32dedde1d..8feffd6ca8 100644 --- a/webapp/packages/plugin-sql-editor-screen/src/PluginBootstrap.ts +++ b/webapp/packages/plugin-sql-editor-screen/src/PluginBootstrap.ts @@ -9,7 +9,7 @@ import { injectable, Bootstrap } from '@cloudbeaver/core-di'; import { NotificationService } from '@cloudbeaver/core-events'; import { MENU_TAB } from '@cloudbeaver/core-ui'; -import { ActionService, ACTION_OPEN_IN_TAB, DATA_CONTEXT_MENU, IDataContextProvider, KeyBindingService, KEY_BINDING_OPEN_IN_TAB, MenuSeparatorItem, MenuService, IAction } from '@cloudbeaver/core-view'; +import { ActionService, ACTION_OPEN_IN_TAB, DATA_CONTEXT_MENU, IDataContextProvider, KeyBindingService, KEY_BINDING_OPEN_IN_TAB, MenuService, IAction } from '@cloudbeaver/core-view'; import { DATA_CONTEXT_SQL_EDITOR_STATE } from '@cloudbeaver/plugin-sql-editor'; import { DATA_CONTEXT_SQL_EDITOR_TAB } from '@cloudbeaver/plugin-sql-editor-navigation-tab'; @@ -53,7 +53,6 @@ export class PluginBootstrap extends Bootstrap { ), getItems: (context, items) => [ ACTION_OPEN_IN_TAB, - ...(items.length > 0 ? [ new MenuSeparatorItem()] : []), ...items, ], });