From fe23450b6d2a65b3c8f1be223759a64d9435ffa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E7=86=B1?= Date: Tue, 2 Jul 2024 11:44:54 +0800 Subject: [PATCH] fix(sheets-ui): ensure context menu does not open on sheets tab when `contextMenu` is set to false --- .../src/views/sheet-bar/SheetBar.tsx | 4 +--- .../sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx | 19 ++++++++++++++++--- .../controllers/ui/ui-desktop.controller.tsx | 6 ++++-- .../ui/src/controllers/ui/ui.controller.ts | 2 ++ packages/ui/src/index.ts | 2 +- packages/ui/src/views/DesktopApp.tsx | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx b/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx index be709e45fa4..75cc4ce9ebf 100644 --- a/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx +++ b/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx @@ -15,7 +15,7 @@ */ import type { Workbook } from '@univerjs/core'; -import { ICommandService, IPermissionService, IUniverInstanceService, UniverInstanceType, UserManagerService } from '@univerjs/core'; +import { ICommandService, IPermissionService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core'; import { IncreaseSingle, MoreSingle } from '@univerjs/icons'; import { InsertSheetCommand, WorkbookCreateSheetPermission, WorkbookEditablePermission } from '@univerjs/sheets'; import { useDependency } from '@wendellhu/redi/react-bindings'; @@ -40,8 +40,6 @@ export const SheetBar = () => { const permissionService = useDependency(IPermissionService); const univerInstanceService = useDependency(IUniverInstanceService); - const userManagerService = useDependency(UserManagerService); - const currentUser = useObservable(userManagerService.currentUser$); const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)!; const unitId = workbook.getUnitId(); diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx index b64c872f3a6..74cb1219928 100644 --- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx +++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx @@ -15,7 +15,7 @@ */ import type { ICommandInfo, Workbook } from '@univerjs/core'; -import { ICommandService, IPermissionService, IUniverInstanceService, LocaleService, nameCharacterCheck, UniverInstanceType } from '@univerjs/core'; +import { ICommandService, IConfigService, IPermissionService, IUniverInstanceService, LocaleService, nameCharacterCheck, UniverInstanceType } from '@univerjs/core'; import { Dropdown } from '@univerjs/design'; import { InsertSheetMutation, @@ -32,7 +32,7 @@ import { WorkbookRenameSheetPermission, WorksheetProtectionRuleModel, } from '@univerjs/sheets'; -import { IConfirmService, Menu, useObservable } from '@univerjs/ui'; +import { IConfirmService, Menu, UI_CONFIG_KEY, useObservable } from '@univerjs/ui'; import { useDependency } from '@wendellhu/redi/react-bindings'; import React, { useCallback, useEffect, useRef, useState } from 'react'; @@ -73,6 +73,11 @@ export function SheetBarTabs() { const workbook = useActiveWorkbook()!; const permissionService = useDependency(IPermissionService); + const configService = useDependency(IConfigService); + const uiConfigs = configService.getConfig<{ contextMenu?: boolean }>(UI_CONFIG_KEY); + + const contextMenu = uiConfigs?.contextMenu ?? true; + const updateSheetItems = useCallback(() => { const currentSubUnitId = workbook.getActiveSheet()?.getSheetId() || ''; setActiveKey(currentSubUnitId); @@ -387,6 +392,8 @@ export function SheetBarTabs() { }; const onVisibleChange = (visible: boolean) => { + if (!contextMenu) return; + if (editorBridgeService?.isForceKeepVisible()) { return; } @@ -410,6 +417,7 @@ export function SheetBarTabs() { visible={visible} align={{ offset }} trigger={['contextMenu']} + disabled={!contextMenu} overlay={( -
e.preventDefault()}> +
e.preventDefault()} + onContextMenu={(e) => e.preventDefault()} + >
{sheetList.map((item) => ( diff --git a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx index 2d09e86a619..55ae96ff81f 100644 --- a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx +++ b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Disposable, isInternalEditorID, LifecycleService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core'; +import { Disposable, IConfigService, isInternalEditorID, LifecycleService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core'; import { IRenderManagerService } from '@univerjs/engine-render'; import type { IDisposable } from '@wendellhu/redi'; import { Inject, Injector, Optional } from '@wendellhu/redi'; @@ -27,7 +27,7 @@ import { DesktopApp } from '../../views/DesktopApp'; import { BuiltInUIPart, IUIPartsService } from '../../services/parts/parts.service'; import { CanvasPopup } from '../../views/components/popup/CanvasPopup'; import { FloatDom } from '../../views/components/dom/FloatDom'; -import type { IUniverUIConfig, IWorkbenchOptions } from './ui.controller'; +import { type IUniverUIConfig, type IWorkbenchOptions, UI_CONFIG_KEY } from './ui.controller'; const STEADY_TIMEOUT = 3000; @@ -39,10 +39,12 @@ export class DesktopUIController extends Disposable { @Inject(Injector) private readonly _injector: Injector, @Inject(LifecycleService) private readonly _lifecycleService: LifecycleService, @IUIPartsService private readonly _uiPartsService: IUIPartsService, + @IConfigService private readonly _configService: IConfigService, @Optional(ILayoutService) private readonly _layoutService?: ILayoutService ) { super(); + this._configService.setConfig(UI_CONFIG_KEY, this._config); this._initBuiltinComponents(); Promise.resolve().then(() => this._bootstrapWorkbench()); diff --git a/packages/ui/src/controllers/ui/ui.controller.ts b/packages/ui/src/controllers/ui/ui.controller.ts index 44b85a57fa3..2f9490dc7cd 100644 --- a/packages/ui/src/controllers/ui/ui.controller.ts +++ b/packages/ui/src/controllers/ui/ui.controller.ts @@ -39,3 +39,5 @@ export interface IUniverUIConfig extends IWorkbenchOptions { menu?: MenuConfig; } + +export const UI_CONFIG_KEY = 'UNIVER_UI_CONFIG_KEY'; diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts index 495a9cb340b..63e000efc84 100644 --- a/packages/ui/src/index.ts +++ b/packages/ui/src/index.ts @@ -27,7 +27,7 @@ export { SharedController, UndoShortcutItem, } from './controllers/shared-shortcut.controller'; -export { IUIController, type IWorkbenchOptions } from './controllers/ui/ui.controller'; +export { UI_CONFIG_KEY, IUIController, type IWorkbenchOptions } from './controllers/ui/ui.controller'; export { DesktopUIController } from './controllers/ui/ui-desktop.controller'; export { IUIPartsService, BuiltInUIPart, UIPartsService } from './services/parts/parts.service'; export { DesktopBeforeCloseService, IBeforeCloseService } from './services/before-close/before-close.service'; diff --git a/packages/ui/src/views/DesktopApp.tsx b/packages/ui/src/views/DesktopApp.tsx index 7809ca5f7cc..b73701568d4 100644 --- a/packages/ui/src/views/DesktopApp.tsx +++ b/packages/ui/src/views/DesktopApp.tsx @@ -144,7 +144,7 @@ export function DesktopApp(props: IUniverAppProps) { {/* footer */} {footer && ( )}