Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix: fix menu status is incorrect because focusedOnDrawing$ have not initial value (#2431)

ybzky5b7bc17b89ab
diff --git a/packages/sheets-drawing-ui/src/views/menu/image.menu.ts b/packages/sheets-drawing-ui/src/views/menu/image.menu.ts
index 2be62e0c11..49ceae5c0f 100644
--- a/packages/sheets-drawing-ui/src/views/menu/image.menu.ts
+++ b/packages/sheets-drawing-ui/src/views/menu/image.menu.ts
@@ -17,6 +17,8 @@
import { getMenuHiddenObservable, type IMenuItem, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
import { UniverInstanceType } from '@univerjs/core';
+import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
+import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
import { COMPONENT_UPLOAD_FILE_MENU, UploadFileType } from '../upload-component/component-name';
import { InsertCellImageOperation, InsertFloatImageOperation } from '../../commands/operations/insert-image.operation';
@@ -32,6 +34,7 @@ export function ImageMenuFactory(accessor: IAccessor): IMenuItem {
icon: IMAGE_UPLOAD_ICON,
tooltip: 'sheetImage.title',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
};
}
@@ -47,7 +50,6 @@ export function UploadFloatImageMenuFactory(_accessor: IAccessor): IMenuItem {
},
},
positions: [IMAGE_MENU_ID],
- // disabled$: getCurrentSheetDisabled$(_accessor),
hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SHEET),
};
}
@@ -64,7 +66,6 @@ export function UploadCellImageMenuFactory(_accessor: IAccessor): IMenuItem {
},
},
positions: [IMAGE_MENU_ID],
- // disabled$: getCurrentSheetDisabled$(_accessor),
hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SHEET),
};
}
diff --git a/packages/sheets-thread-comment/src/controllers/menu.ts b/packages/sheets-thread-comment/src/controllers/menu.ts
index 780ddaf8a6..745675f98e 100644
--- a/packages/sheets-thread-comment/src/controllers/menu.ts
+++ b/packages/sheets-thread-comment/src/controllers/menu.ts
@@ -19,7 +19,7 @@ import { getMenuHiddenObservable, KeyCode, MenuGroup, MenuItemType, MenuPosition
import type { IAccessor } from '@wendellhu/redi';
import { ToggleSheetCommentPanelOperation } from '@univerjs/thread-comment-ui';
import { UniverInstanceType } from '@univerjs/core';
-import { getCommentDisable$, whenSheetEditorFocused } from '@univerjs/sheets-ui';
+import { getCurrentRangeDisable$, whenSheetEditorFocused } from '@univerjs/sheets-ui';
import { RangeProtectionPermissionEditPoint, WorkbookCommentPermission, WorksheetViewPermission } from '@univerjs/sheets';
import { ShowAddSheetCommentModalOperation } from '../commands/operations/comment.operation';
import { COMMENT_SINGLE_ICON } from '../types/const';
@@ -32,7 +32,7 @@ export const threadCommentMenuFactory = (accessor: IAccessor) => {
icon: COMMENT_SINGLE_ICON,
title: 'sheetThreadComment.menu.addComment',
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
- disabled$: getCommentDisable$(accessor, {
+ disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookCommentPermission],
worksheetTypes: [WorksheetViewPermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
@@ -48,7 +48,7 @@ export const threadPanelMenuFactory = (accessor: IAccessor) => {
tooltip: 'sheetThreadComment.menu.commentManagement',
positions: MenuPosition.TOOLBAR_START,
group: MenuGroup.TOOLBAR_OTHERS,
- disabled$: getCommentDisable$(accessor, {
+ disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookCommentPermission],
worksheetTypes: [WorksheetViewPermission],
rangeTypes: [RangeProtectionPermissionEditPoint],
diff --git a/packages/sheets-ui/src/controllers/menu/menu-util.ts b/packages/sheets-ui/src/controllers/menu/menu-util.ts
index 6dad2c844c..cb208c95ec 100644
--- a/packages/sheets-ui/src/controllers/menu/menu-util.ts
+++ b/packages/sheets-ui/src/controllers/menu/menu-util.ts
@@ -22,7 +22,7 @@ import type { ICellPermission } from '@univerjs/sheets';
import { RangeProtectionRuleModel, SelectionManagerService, WorkbookEditablePermission, WorkbookManageCollaboratorPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
import type { Observable } from 'rxjs';
-import { combineLatest, map, of, switchMap } from 'rxjs';
+import { combineLatest, map, of, startWith, switchMap } from 'rxjs';
interface IActive {
workbook: Workbook;
@@ -54,13 +54,13 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const userManagerService = accessor.get(UserManagerService);
const contextService = accessor.get(IContextService);
- const focusedOnDrawing$ = contextService.subscribeContextValue$(FOCUSING_COMMON_DRAWINGS);
+ const focusedOnDrawing$ = contextService.subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false));
if (!workbook) {
return of(true);
}
return combineLatest([userManagerService.currentUser$, workbook.activeSheet$, selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe(
- switchMap(([_, __, ___, focusOnDrawings]) => {
+ switchMap(([_, __, selection, focusOnDrawings]) => {
if (focusOnDrawings) {
return of(true);
}
@@ -91,7 +91,7 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
}));
}
- const selectionRanges = selectionManagerService.getSelections()?.map((selection) => selection.range);
+ const selectionRanges = selection?.map((selection) => selection.range);
const rules = rangeProtectionRuleModel.getSubunitRuleList(unitId, subUnitId).filter((rule) => {
return selectionRanges?.some((range) => {
return rule.ranges.some((ruleRange) => Rectangle.intersects(range, ruleRange));
diff --git a/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts b/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
index 7b5444b7cb..7692ddbd67 100644
--- a/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
+++ b/packages/sheets-ui/src/controllers/menu/permission-menu-util.ts
@@ -156,7 +156,7 @@ export function getAddPermissionDisableBase$(accessor: IAccessor) {
const userManagerService = accessor.get(UserManagerService);
const permissionService = accessor.get(IPermissionService);
const contextService = accessor.get(IContextService);
- const focusingDrawing$ = contextService.subscribeContextValue$(FOCUSING_COMMON_DRAWINGS);
+ const focusingDrawing$ = contextService.subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false));
return combineLatest([workbook.activeSheet$, userManagerService.currentUser$, focusingDrawing$]).pipe(
switchMap(([sheet, _, focusOnDrawing]) => {
diff --git a/packages/sheets-ui/src/locale/en-US.ts b/packages/sheets-ui/src/locale/en-US.ts
index b04c205af7..8b46a53acd 100644
--- a/packages/sheets-ui/src/locale/en-US.ts
+++ b/packages/sheets-ui/src/locale/en-US.ts
@@ -561,8 +561,8 @@ const locale: typeof zhCN = {
canEdit: 'Can edit',
canView: 'Can view',
delete: 'Delete',
- currentSheet: 'Current worksheet',
- allSheet: 'All worksheets',
+ currentSheet: 'Current sheet',
+ allSheet: 'All sheets',
edit: 'Edit',
Print: 'Print',
Comment: 'Comment',
diff --git a/packages/sheets-ui/src/views/permission/footer/permission-detail-footer.tsx b/packages/sheets-ui/src/views/permission/footer/permission-detail-footer.tsx
index 54e5a7daa3..8d4644a47a 100644
--- a/packages/sheets-ui/src/views/permission/footer/permission-detail-footer.tsx
+++ b/packages/sheets-ui/src/views/permission/footer/permission-detail-footer.tsx
@@ -136,7 +136,7 @@ export const SheetPermissionPanelDetailFooter = () => {
sheetPermissionPanelModel.resetRule();
sheetPermissionUserManagerService.setSelectUserList([]);
const sidebarProps = {
- header: { title: '保护行列' },
+ header: { title: `${localeService.t('permission.panel.title')}` },
children: {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: false,
diff --git a/packages/sheets-ui/src/views/permission/footer/permission-list-footer.tsx b/packages/sheets-ui/src/views/permission/footer/permission-list-footer.tsx
index f6a69ba087..1a1e0a57be 100644
--- a/packages/sheets-ui/src/views/permission/footer/permission-list-footer.tsx
+++ b/packages/sheets-ui/src/views/permission/footer/permission-list-footer.tsx
@@ -60,7 +60,7 @@ export const SheetPermissionPanelAddFooter = () => {
onClick={() => {
sheetPermissionPanelModel.resetRule();
const sidebarProps = {
- header: { title: '保护行列' },
+ header: { title: `${localeService.t('permission.panel.title')}` },
children: {
label: UNIVER_SHEET_PERMISSION_PANEL,
showDetail: true,