From de1c16e01d3506fa6b0a97b11675932bb16fd6ae Mon Sep 17 00:00:00 2001 From: ybzky Date: Sat, 15 Jun 2024 10:22:59 +0800 Subject: [PATCH 1/4] fix: change permission collaborator --- packages/core/package.json | 2 +- packages/data-validation/package.json | 2 +- .../package.json | 2 +- .../package.json | 2 +- packages/sheets-data-validation/package.json | 2 +- packages/sheets-find-replace/package.json | 2 +- packages/sheets-hyper-link/package.json | 2 +- packages/sheets-ui/package.json | 2 +- .../sheet-permission-open-panel.operation.ts | 2 +- .../src/controllers/menu/menu-util.ts | 85 ++++++++++--------- .../footer/permission-detail-footer.tsx | 8 +- .../footer/permission-list-footer.tsx | 2 +- .../src/views/permission/panel-list/index.tsx | 2 +- .../permission/permission-dialog/index.tsx | 3 +- packages/sheets/package.json | 2 +- packages/thread-comment-ui/package.json | 2 +- packages/thread-comment/package.json | 2 +- packages/umd/package.json | 2 +- packages/uniscript/package.json | 2 +- pnpm-lock.yaml | 58 ++++++------- 20 files changed, 96 insertions(+), 90 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 5100d96dcad..d41dacf2685 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -64,7 +64,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3", + "@univerjs/protocol": "0.1.38-alpha.4", "nanoid": "5.0.7", "numeral": "^2.0.6", "ot-json1": "^1.0.2" diff --git a/packages/data-validation/package.json b/packages/data-validation/package.json index fca1c1ee52a..dcc6e9dd999 100644 --- a/packages/data-validation/package.json +++ b/packages/data-validation/package.json @@ -69,7 +69,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@univerjs/core": "workspace:*", diff --git a/packages/sheets-conditional-formatting-ui/package.json b/packages/sheets-conditional-formatting-ui/package.json index f477d7ad4cb..daa2b78b797 100644 --- a/packages/sheets-conditional-formatting-ui/package.json +++ b/packages/sheets-conditional-formatting-ui/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "@univerjs/icons": "^0.1.56", - "@univerjs/protocol": "0.1.38-alpha.3", + "@univerjs/protocol": "0.1.38-alpha.4", "@univerjs/sheets-conditional-formatting": "workspace:*", "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", diff --git a/packages/sheets-conditional-formatting/package.json b/packages/sheets-conditional-formatting/package.json index 85b520777f2..cf24947ccf5 100644 --- a/packages/sheets-conditional-formatting/package.json +++ b/packages/sheets-conditional-formatting/package.json @@ -70,7 +70,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@univerjs/core": "workspace:*", diff --git a/packages/sheets-data-validation/package.json b/packages/sheets-data-validation/package.json index 4a08de22530..5a29da427a4 100644 --- a/packages/sheets-data-validation/package.json +++ b/packages/sheets-data-validation/package.json @@ -79,7 +79,7 @@ }, "dependencies": { "@univerjs/icons": "^0.1.56", - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@univerjs/core": "workspace:*", diff --git a/packages/sheets-find-replace/package.json b/packages/sheets-find-replace/package.json index bd45aa8c271..dbdf3fe9251 100644 --- a/packages/sheets-find-replace/package.json +++ b/packages/sheets-find-replace/package.json @@ -71,7 +71,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@univerjs/core": "workspace:*", diff --git a/packages/sheets-hyper-link/package.json b/packages/sheets-hyper-link/package.json index e07a6f0eab3..a409a61957f 100644 --- a/packages/sheets-hyper-link/package.json +++ b/packages/sheets-hyper-link/package.json @@ -68,7 +68,7 @@ "devDependencies": { "@univerjs/core": "workspace:*", "@univerjs/engine-formula": "workspace:*", - "@univerjs/protocol": "0.1.38-alpha.3", + "@univerjs/protocol": "0.1.38-alpha.4", "@univerjs/shared": "workspace:*", "@univerjs/sheets": "workspace:*", "@wendellhu/redi": "^0.15.4", diff --git a/packages/sheets-ui/package.json b/packages/sheets-ui/package.json index 6e25e341439..969bc74e20e 100644 --- a/packages/sheets-ui/package.json +++ b/packages/sheets-ui/package.json @@ -81,7 +81,7 @@ }, "dependencies": { "@univerjs/icons": "^0.1.56", - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@types/react": "^18.3.3", diff --git a/packages/sheets-ui/src/commands/operations/sheet-permission-open-panel.operation.ts b/packages/sheets-ui/src/commands/operations/sheet-permission-open-panel.operation.ts index 64a282fa183..161b29a74bc 100644 --- a/packages/sheets-ui/src/commands/operations/sheet-permission-open-panel.operation.ts +++ b/packages/sheets-ui/src/commands/operations/sheet-permission-open-panel.operation.ts @@ -43,7 +43,7 @@ export const SheetPermissionOpenPanelOperation: ICommand(UniverInstanceType.UNIVER_SHEET)!; + const workbook$ = univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET); const userManagerService = accessor.get(UserManagerService); const contextService = accessor.get(IContextService); 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(([_, __, selection, focusOnDrawings]) => { - if (focusOnDrawings) { + return combineLatest([userManagerService.currentUser$, workbook$, selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe( + switchMap(([_, workbook, selection, focusOnDrawings]) => { + if (focusOnDrawings || !workbook) { return of(true); } - const worksheet = workbook.getActiveSheet(); - const unitId = workbook.getUnitId(); - const subUnitId = worksheet.getSheetId(); - - const permissionService = accessor.get(IPermissionService); + return workbook.activeSheet$.pipe( + switchMap((worksheet) => { + if (!worksheet) { + return of(true); + } + const unitId = workbook.getUnitId(); + const subUnitId = worksheet.getSheetId(); - const { workbookTypes = [WorkbookEditablePermission], worksheetTypes, rangeTypes } = permissionTypes; + const permissionService = accessor.get(IPermissionService); - const permissionIds: string[] = []; + const { workbookTypes = [WorkbookEditablePermission], worksheetTypes, rangeTypes } = permissionTypes; - workbookTypes?.forEach((F) => { - permissionIds.push(new F(unitId).id); - }); + const permissionIds: string[] = []; - worksheetTypes?.forEach((F) => { - permissionIds.push(new F(unitId, subUnitId).id); - }); + workbookTypes?.forEach((F) => { + permissionIds.push(new F(unitId).id); + }); - const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId); + worksheetTypes?.forEach((F) => { + permissionIds.push(new F(unitId, subUnitId).id); + }); - if (worksheetRule) { - return permissionService.composePermission$(permissionIds).pipe(map((list) => { - return list.some((item) => item.value === false); - })); - } - - 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)); - }); - }); + const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId); - rangeTypes?.forEach((F) => { - rules.forEach((rule) => { - permissionIds.push(new F(unitId, subUnitId, rule.permissionId).id); - }); - }); + if (worksheetRule) { + return permissionService.composePermission$(permissionIds).pipe(map((list) => { + return list.some((item) => item.value === false); + })); + } - return permissionService.composePermission$(permissionIds).pipe(map((list) => { - return list.some((item) => item.value === false); - })); + 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)); + }); + }); + + rangeTypes?.forEach((F) => { + rules.forEach((rule) => { + permissionIds.push(new F(unitId, subUnitId, rule.permissionId).id); + }); + }); + + return permissionService.composePermission$(permissionIds).pipe(map((list) => { + return list.some((item) => item.value === false); + })); + }) + ); }) ); } 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 8d4644a47ad..3db5b6dccec 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 @@ -19,7 +19,7 @@ import { useDependency } from '@wendellhu/redi/react-bindings'; import React from 'react'; import { ISidebarService, useObservable } from '@univerjs/ui'; import { IAuthzIoService, ICommandService, LocaleService } from '@univerjs/core'; -import { UnitAction, UnitObject, UnitRole } from '@univerjs/protocol'; +import { CreateRequest_WorkSheetObjectScope, UnitAction, UnitObject, UnitRole } from '@univerjs/protocol'; import { AddRangeProtectionCommand } from '@univerjs/sheets'; import { SheetPermissionPanelModel, viewState } from '../../../services/permission/sheet-permission-panel.model'; import { SheetPermissionUserManagerService } from '../../../services/permission/sheet-permission-user-list.service'; @@ -79,6 +79,7 @@ export const SheetPermissionPanelDetailFooter = () => { unitID: activeRule.unitId, name: activeRule.name, strategies: [{ role: UnitRole.Editor, action: UnitAction.Edit }, { role: UnitRole.Reader, action: UnitAction.View }], + scope: CreateRequest_WorkSheetObjectScope.SomeCollaborator, }, objectType: UnitObject.Worksheet, }); @@ -109,10 +110,11 @@ export const SheetPermissionPanelDetailFooter = () => { unitID: activeRule.unitId, name: activeRule.name, strategies: [{ role: UnitRole.Editor, action: UnitAction.Edit }, { role: UnitRole.Reader, action: UnitAction.View }], + scope: CreateRequest_WorkSheetObjectScope.SomeCollaborator, }, objectType: UnitObject.Worksheet, }); - const { ranges = [], ...sheetRule } = activeRule; + const { ranges: _range = [], ...sheetRule } = activeRule; sheetRule.permissionId = permissionId; commandService.executeCommand(AddWorksheetProtectionCommand.id, { rule: sheetRule, @@ -141,7 +143,7 @@ export const SheetPermissionPanelDetailFooter = () => { label: UNIVER_SHEET_PERMISSION_PANEL, showDetail: false, }, - width: 320, + width: 330, footer: { label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER, 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 1a1e0a57be0..c4bc01dcbdf 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 @@ -65,7 +65,7 @@ export const SheetPermissionPanelAddFooter = () => { label: UNIVER_SHEET_PERMISSION_PANEL, showDetail: true, }, - width: 320, + width: 330, footer: { label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER, showDetail: true, diff --git a/packages/sheets-ui/src/views/permission/panel-list/index.tsx b/packages/sheets-ui/src/views/permission/panel-list/index.tsx index 96ba4d1cec2..6812bec8a4a 100644 --- a/packages/sheets-ui/src/views/permission/panel-list/index.tsx +++ b/packages/sheets-ui/src/views/permission/panel-list/index.tsx @@ -176,7 +176,7 @@ export const SheetPermissionPanelList = () => { label: UNIVER_SHEET_PERMISSION_PANEL, showDetail: true, }, - width: 320, + width: 330, footer: { label: UNIVER_SHEET_PERMISSION_PANEL_FOOTER, showDetail: true, diff --git a/packages/sheets-ui/src/views/permission/permission-dialog/index.tsx b/packages/sheets-ui/src/views/permission/permission-dialog/index.tsx index 899530a9ab1..d51f4d955d7 100644 --- a/packages/sheets-ui/src/views/permission/permission-dialog/index.tsx +++ b/packages/sheets-ui/src/views/permission/permission-dialog/index.tsx @@ -24,7 +24,7 @@ import { IAuthzIoService, ICommandService, IPermissionService, IUniverInstanceSe import { IDialogService } from '@univerjs/ui'; import { getAllWorksheetPermissionPoint, SetWorksheetPermissionPointsCommand, WorksheetProtectionPointModel } from '@univerjs/sheets'; import type { ICollaborator, UnitAction } from '@univerjs/protocol'; -import { UnitObject, UnitRole } from '@univerjs/protocol'; +import { CreateRequest_WorkSheetObjectScope, UnitObject, UnitRole } from '@univerjs/protocol'; import Spin from '../spin'; import { defaultWorksheetUnitActionList, subUnitPermissionTypeMap, UNIVER_SHEET_PERMISSION_DIALOG_ID } from '../../../basics/const/permission'; import styles from './index.module.less'; @@ -129,6 +129,7 @@ export const SheetPermissionDialog = () => { collaborators, name: '', strategies: actions, + scope: CreateRequest_WorkSheetObjectScope.AllCollaborator, }, }); diff --git a/packages/sheets/package.json b/packages/sheets/package.json index d49b94e8f4e..a87792a7ff6 100644 --- a/packages/sheets/package.json +++ b/packages/sheets/package.json @@ -69,7 +69,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@univerjs/core": "workspace:*", diff --git a/packages/thread-comment-ui/package.json b/packages/thread-comment-ui/package.json index 6f311c06c06..f088cfcf101 100644 --- a/packages/thread-comment-ui/package.json +++ b/packages/thread-comment-ui/package.json @@ -75,7 +75,7 @@ }, "dependencies": { "@univerjs/icons": "^0.1.56", - "@univerjs/protocol": "0.1.38-alpha.3", + "@univerjs/protocol": "0.1.38-alpha.4", "@univerjs/thread-comment": "workspace:*" }, "devDependencies": { diff --git a/packages/thread-comment/package.json b/packages/thread-comment/package.json index bcb1e5d10be..5738274978a 100644 --- a/packages/thread-comment/package.json +++ b/packages/thread-comment/package.json @@ -66,7 +66,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3" + "@univerjs/protocol": "0.1.38-alpha.4" }, "devDependencies": { "@univerjs/core": "workspace:*", diff --git a/packages/umd/package.json b/packages/umd/package.json index 0b86c082439..dc68ac38122 100644 --- a/packages/umd/package.json +++ b/packages/umd/package.json @@ -53,7 +53,7 @@ "@univerjs/facade": "workspace:*", "@univerjs/find-replace": "workspace:*", "@univerjs/network": "workspace:*", - "@univerjs/protocol": "0.1.38-alpha.3", + "@univerjs/protocol": "0.1.38-alpha.4", "@univerjs/rpc": "workspace:*", "@univerjs/sheets": "workspace:*", "@univerjs/sheets-conditional-formatting": "workspace:*", diff --git a/packages/uniscript/package.json b/packages/uniscript/package.json index 605ea403871..0b094a0ae02 100644 --- a/packages/uniscript/package.json +++ b/packages/uniscript/package.json @@ -77,7 +77,7 @@ "rxjs": ">=7.0.0" }, "dependencies": { - "@univerjs/protocol": "0.1.38-alpha.3", + "@univerjs/protocol": "0.1.38-alpha.4", "@univerjs/sheets": "workspace:*" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6236b968fd..dadafa59d91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -374,8 +374,8 @@ importers: packages/core: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) nanoid: specifier: 5.0.7 version: 5.0.7 @@ -411,8 +411,8 @@ importers: packages/data-validation: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@univerjs/core': specifier: workspace:* @@ -1103,8 +1103,8 @@ importers: packages/sheets: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@univerjs/core': specifier: workspace:* @@ -1140,8 +1140,8 @@ importers: packages/sheets-conditional-formatting: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@univerjs/core': specifier: workspace:* @@ -1189,8 +1189,8 @@ importers: specifier: ^0.1.56 version: 0.1.57(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) '@univerjs/sheets-conditional-formatting': specifier: workspace:* version: link:../sheets-conditional-formatting @@ -1277,8 +1277,8 @@ importers: specifier: ^0.1.56 version: 0.1.57(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@univerjs/core': specifier: workspace:* @@ -1520,8 +1520,8 @@ importers: packages/sheets-find-replace: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@univerjs/core': specifier: workspace:* @@ -1637,8 +1637,8 @@ importers: specifier: workspace:* version: link:../engine-formula '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) '@univerjs/shared': specifier: workspace:* version: link:../../common/shared @@ -1890,8 +1890,8 @@ importers: specifier: ^0.1.56 version: 0.1.57(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@types/react': specifier: ^18.3.3 @@ -2081,8 +2081,8 @@ importers: packages/thread-comment: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) devDependencies: '@univerjs/core': specifier: workspace:* @@ -2118,8 +2118,8 @@ importers: specifier: ^0.1.56 version: 0.1.57(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) '@univerjs/thread-comment': specifier: workspace:* version: link:../thread-comment @@ -2289,8 +2289,8 @@ importers: specifier: workspace:* version: link:../network '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) '@univerjs/rpc': specifier: workspace:* version: link:../rpc @@ -2391,8 +2391,8 @@ importers: packages/uniscript: dependencies: '@univerjs/protocol': - specifier: 0.1.38-alpha.3 - version: 0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) + specifier: 0.1.38-alpha.4 + version: 0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1) '@univerjs/sheets': specifier: workspace:* version: link:../sheets @@ -4923,8 +4923,8 @@ packages: react: '*' react-dom: '*' - '@univerjs/protocol@0.1.38-alpha.3': - resolution: {integrity: sha512-fSPi8dFO66OJEjpGs3p0HUTmka7MNghbsp58CtkK7ZuxpqXBDZme36wN1mDAbSb80/9qc3+/2Q2i4dhyyolIiA==} + '@univerjs/protocol@0.1.38-alpha.4': + resolution: {integrity: sha512-ILqkhWhPw83z0AM7KzJI+PXvv/I8GAfLjD3V5wTX87oCRZn1nqRQ4N7993U1S5bDyTTExIzYpCKKuFYkfe1GTA==} engines: {node: '>=16.0.0', npm: '>=8.0.0'} peerDependencies: '@grpc/grpc-js': ^1.9.14 @@ -13653,7 +13653,7 @@ snapshots: react: 18.3.1 react-dom: 18.3.1(react@18.3.1) - '@univerjs/protocol@0.1.38-alpha.3(@grpc/grpc-js@1.10.9)(rxjs@7.8.1)': + '@univerjs/protocol@0.1.38-alpha.4(@grpc/grpc-js@1.10.9)(rxjs@7.8.1)': dependencies: '@grpc/grpc-js': 1.10.9 rxjs: 7.8.1 From 47e83d935c06fddcf5ea438c7463eebcd7c51f94 Mon Sep 17 00:00:00 2001 From: ybzky Date: Sat, 15 Jun 2024 11:05:55 +0800 Subject: [PATCH 2/4] fix: fix test --- packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts b/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts index 6e5d9e632c5..b5d4b8b0c42 100644 --- a/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts +++ b/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts @@ -93,10 +93,10 @@ describe('test menu items', () => { disposableCollection.add(menuItem.activated$!.subscribe((v: boolean) => (activated = v))); disposableCollection.add(menuItem.disabled$!.subscribe((v: boolean) => (disabled = v))); expect(activated).toBeFalsy(); - expect(disabled).toBeFalsy(); select({ startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 }); expect(await commandService.executeCommand(SetBoldCommand.id)).toBeTruthy(); expect(activated).toBe(true); + expect(disabled).toBeFalsy(); }); }); From 6e922fa7b8c9751c6106e494eb5545c5525dcd17 Mon Sep 17 00:00:00 2001 From: ybzky Date: Sat, 15 Jun 2024 13:57:52 +0800 Subject: [PATCH 3/4] chore: reset menu --- packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts b/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts index b5d4b8b0c42..6e5d9e632c5 100644 --- a/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts +++ b/packages/sheets-ui/src/controllers/menu/__tests__/menu.spec.ts @@ -93,10 +93,10 @@ describe('test menu items', () => { disposableCollection.add(menuItem.activated$!.subscribe((v: boolean) => (activated = v))); disposableCollection.add(menuItem.disabled$!.subscribe((v: boolean) => (disabled = v))); expect(activated).toBeFalsy(); + expect(disabled).toBeFalsy(); select({ startRow: 0, startColumn: 0, endRow: 0, endColumn: 0 }); expect(await commandService.executeCommand(SetBoldCommand.id)).toBeTruthy(); expect(activated).toBe(true); - expect(disabled).toBeFalsy(); }); }); From 632039aff1f1e15400b01de4b92a2653dd390220 Mon Sep 17 00:00:00 2001 From: ybzky Date: Sat, 15 Jun 2024 13:59:03 +0800 Subject: [PATCH 4/4] chore: reset menu --- .../src/controllers/menu/menu-util.ts | 85 +++++++++---------- 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/packages/sheets-ui/src/controllers/menu/menu-util.ts b/packages/sheets-ui/src/controllers/menu/menu-util.ts index ebdf0388385..cb208c95ec0 100644 --- a/packages/sheets-ui/src/controllers/menu/menu-util.ts +++ b/packages/sheets-ui/src/controllers/menu/menu-util.ts @@ -51,65 +51,62 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP const selectionManagerService = accessor.get(SelectionManagerService); const rangeProtectionRuleModel = accessor.get(RangeProtectionRuleModel); const worksheetRuleModel = accessor.get(WorksheetProtectionRuleModel); - const workbook$ = univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET); + const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)!; const userManagerService = accessor.get(UserManagerService); const contextService = accessor.get(IContextService); const focusedOnDrawing$ = contextService.subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)); + if (!workbook) { + return of(true); + } - return combineLatest([userManagerService.currentUser$, workbook$, selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe( - switchMap(([_, workbook, selection, focusOnDrawings]) => { - if (focusOnDrawings || !workbook) { + return combineLatest([userManagerService.currentUser$, workbook.activeSheet$, selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe( + switchMap(([_, __, selection, focusOnDrawings]) => { + if (focusOnDrawings) { return of(true); } - return workbook.activeSheet$.pipe( - switchMap((worksheet) => { - if (!worksheet) { - return of(true); - } - const unitId = workbook.getUnitId(); - const subUnitId = worksheet.getSheetId(); + const worksheet = workbook.getActiveSheet(); + const unitId = workbook.getUnitId(); + const subUnitId = worksheet.getSheetId(); - const permissionService = accessor.get(IPermissionService); + const permissionService = accessor.get(IPermissionService); - const { workbookTypes = [WorkbookEditablePermission], worksheetTypes, rangeTypes } = permissionTypes; + const { workbookTypes = [WorkbookEditablePermission], worksheetTypes, rangeTypes } = permissionTypes; - const permissionIds: string[] = []; + const permissionIds: string[] = []; - workbookTypes?.forEach((F) => { - permissionIds.push(new F(unitId).id); - }); + workbookTypes?.forEach((F) => { + permissionIds.push(new F(unitId).id); + }); - worksheetTypes?.forEach((F) => { - permissionIds.push(new F(unitId, subUnitId).id); - }); + worksheetTypes?.forEach((F) => { + permissionIds.push(new F(unitId, subUnitId).id); + }); - const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId); + const worksheetRule = worksheetRuleModel.getRule(unitId, subUnitId); - if (worksheetRule) { - return permissionService.composePermission$(permissionIds).pipe(map((list) => { - return list.some((item) => item.value === false); - })); - } + if (worksheetRule) { + return permissionService.composePermission$(permissionIds).pipe(map((list) => { + return list.some((item) => item.value === false); + })); + } - 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)); - }); - }); - - rangeTypes?.forEach((F) => { - rules.forEach((rule) => { - permissionIds.push(new F(unitId, subUnitId, rule.permissionId).id); - }); - }); - - return permissionService.composePermission$(permissionIds).pipe(map((list) => { - return list.some((item) => item.value === false); - })); - }) - ); + 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)); + }); + }); + + rangeTypes?.forEach((F) => { + rules.forEach((rule) => { + permissionIds.push(new F(unitId, subUnitId, rule.permissionId).id); + }); + }); + + return permissionService.composePermission$(permissionIds).pipe(map((list) => { + return list.some((item) => item.value === false); + })); }) ); }