Skip to content

Commit

Permalink
fix(sheets-ui): ensure context menu does not open on sheets tab when …
Browse files Browse the repository at this point in the history
…`contextMenu` is set to false
  • Loading branch information
jikkai committed Jul 2, 2024
1 parent 21008f9 commit 2cdb9bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
4 changes: 1 addition & 3 deletions packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { ICommandInfo, Workbook } from '@univerjs/core';
import { ICommandService, IPermissionService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IConfigService, IPermissionService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { Dropdown } from '@univerjs/design';
import {
InsertSheetMutation,
Expand All @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -363,6 +368,8 @@ export function SheetBarTabs() {
};

const onVisibleChange = (visible: boolean) => {
if (!contextMenu) return;

if (editorBridgeService?.isForceKeepVisible()) {
return;
}
Expand All @@ -386,6 +393,7 @@ export function SheetBarTabs() {
visible={visible}
align={{ offset }}
trigger={['contextMenu']}
disabled={!contextMenu}
overlay={(
<Menu
menuType={SheetMenuPosition.SHEET_BAR}
Expand All @@ -398,7 +406,12 @@ export function SheetBarTabs() {
)}
onVisibleChange={onVisibleChange}
>
<div className={styles.slideTabBarContainer} ref={slideTabBarContainerRef} onDragStart={(e) => e.preventDefault()}>
<div
className={styles.slideTabBarContainer}
ref={slideTabBarContainerRef}
onDragStart={(e) => e.preventDefault()}
onContextMenu={(e) => e.preventDefault()}
>
<div className={styles.slideTabBar} style={{ boxShadow }}>
{sheetList.map((item) => (
<SheetBarItem {...item} key={item.sheetId} selected={activeKey === item.sheetId} />
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/controllers/ui/ui-desktop.controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/controllers/ui/ui.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export interface IUniverUIConfig extends IWorkbenchOptions {

menu?: MenuConfig;
}

export const UI_CONFIG_KEY = 'UNIVER_UI_CONFIG_KEY';
2 changes: 1 addition & 1 deletion packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/views/DesktopApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function DesktopApp(props: IUniverAppProps) {
{/* footer */}
{footer && (
<footer className={styles.appFooter}>
<ComponentContainer key="footer" components={footerComponents} />
<ComponentContainer key="footer" components={footerComponents} sharedProps={{ contextMenu }} />
</footer>
)}

Expand Down

0 comments on commit 2cdb9bd

Please sign in to comment.