Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheets-ui): ensure context menu does not open on sheets tab when contextMenu is set to false #2654

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, nameCharacterCheck, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IConfigService, IPermissionService, IUniverInstanceService, LocaleService, nameCharacterCheck, 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 @@ -387,6 +392,8 @@ export function SheetBarTabs() {
};

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

if (editorBridgeService?.isForceKeepVisible()) {
return;
}
Expand All @@ -410,6 +417,7 @@ export function SheetBarTabs() {
visible={visible}
align={{ offset }}
trigger={['contextMenu']}
disabled={!contextMenu}
overlay={(
<Menu
menuType={SheetMenuPosition.SHEET_BAR}
Expand All @@ -422,7 +430,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
Loading