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): should disable sheet menus on cell editing #3809

Merged
merged 21 commits into from
Oct 22, 2024
Prev Previous commit
Next Next commit
feat: update
  • Loading branch information
weird94 committed Oct 21, 2024
commit e8d970ae51fd96e500891fe642e92032a4a16738
27 changes: 18 additions & 9 deletions packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/

import type { IAccessor, Workbook } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, IContextService, IPermissionService, IUniverInstanceService, Rectangle, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, IContextService, IPermissionService, IUniverInstanceService, Rectangle, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorkbookManageCollaboratorPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { combineLatest, map, merge, of, startWith, switchMap } from 'rxjs';
import { IEditorBridgeService } from '../../services/editor-bridge.service';

export function getAddPermissionHidden$(accessor: IAccessor) {
const univerInstanceService = accessor.get(IUniverInstanceService);
Expand Down Expand Up @@ -186,10 +187,14 @@ export function getAddPermissionDisableBase$(accessor: IAccessor) {
const permissionService = accessor.get(IPermissionService);
const workbook$ = univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);
const userManagerService = accessor.get(UserManagerService);

return combineLatest([workbook$, userManagerService.currentUser$]).pipe(
switchMap(([workbook, _]) => {
if (!workbook) {
const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
const contextService = accessor.get(IContextService);
const formulaEditorFocus$ = contextService.subscribeContextValue$(FOCUSING_FX_BAR_EDITOR);
const editorVisible$ = editorBridgeService?.visible$ ?? of(null);

return combineLatest([workbook$, userManagerService.currentUser$, editorVisible$, formulaEditorFocus$]).pipe(
switchMap(([workbook, __, visible, formulaEditorFocus]) => {
if (!workbook || (visible?.visible && visible.unitId === workbook.getUnitId()) || formulaEditorFocus) {
return of(true);
}

Expand Down Expand Up @@ -436,10 +441,14 @@ export function getViewPermissionDisable$(accessor: IAccessor) {
const permissionService = accessor.get(IPermissionService);
const workbook$ = univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET);
const userManagerService = accessor.get(UserManagerService);

return combineLatest([workbook$, userManagerService.currentUser$]).pipe(
switchMap(([workbook, _]) => {
if (!workbook) {
const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
const contextService = accessor.get(IContextService);
const formulaEditorFocus$ = contextService.subscribeContextValue$(FOCUSING_FX_BAR_EDITOR);
const editorVisible$ = editorBridgeService?.visible$ ?? of(null);

return combineLatest([workbook$, userManagerService.currentUser$, editorVisible$, formulaEditorFocus$]).pipe(
switchMap(([workbook, __, visible, formulaEditorFocus]) => {
if (!workbook || (visible?.visible && visible.unitId === workbook.getUnitId()) || formulaEditorFocus) {
return of(true);
}

Expand Down
Loading