diff --git a/packages/sheets-ui/src/controllers/menu/insert.menu.ts b/packages/sheets-ui/src/controllers/menu/insert.menu.ts index a547854a496..b365bfff634 100644 --- a/packages/sheets-ui/src/controllers/menu/insert.menu.ts +++ b/packages/sheets-ui/src/controllers/menu/insert.menu.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import type { IAccessor } from '@univerjs/core'; +import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui'; import { InsertColAfterCommand, InsertColBeforeCommand, @@ -25,13 +27,11 @@ import { WorksheetInsertColumnPermission, WorksheetInsertRowPermission, } from '@univerjs/sheets'; -import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui'; import { MenuItemType } from '@univerjs/ui'; -import type { IAccessor } from '@univerjs/core'; import { InsertRangeMoveDownConfirmCommand } from '../../commands/commands/insert-range-move-down-confirm.command'; import { InsertRangeMoveRightConfirmCommand } from '../../commands/commands/insert-range-move-right-confirm.command'; -import { getBaseRangeMenuHidden$, getCellMenuHidden$, getCurrentRangeDisable$, getInsertAfterMenuHidden$, getInsertBeforeMenuHidden$, getObservableWithExclusiveRange$ } from './menu-util'; +import { getBaseRangeMenuHidden$, getCellMenuHidden$, getCurrentRangeDisable$, getObservableWithExclusiveRange$ } from './menu-util'; export const COL_INSERT_MENU_ID = 'sheet.menu.col-insert'; export function ColInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem { @@ -40,7 +40,6 @@ export function ColInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem type: MenuItemType.SUBITEMS, title: 'rightClick.insert', icon: 'Insert', - hidden$: getBaseRangeMenuHidden$(accessor), disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetInsertColumnPermission] }), }; } @@ -52,8 +51,7 @@ export function RowInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem type: MenuItemType.SUBITEMS, title: 'rightClick.insert', icon: 'Insert', - hidden$: getBaseRangeMenuHidden$(accessor), - disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), + disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission] }), }; } @@ -75,8 +73,7 @@ export function InsertRowBeforeMenuItemFactory(accessor: IAccessor): IMenuButton type: MenuItemType.BUTTON, title: 'rightClick.insertRowBefore', icon: 'InsertRowAbove', - disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), - hidden$: getInsertBeforeMenuHidden$(accessor, 'row'), + disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission] }), }; } @@ -86,8 +83,7 @@ export function InsertRowAfterMenuItemFactory(accessor: IAccessor): IMenuButtonI type: MenuItemType.BUTTON, title: 'rightClick.insertRow', icon: 'InsertRowBelow', - disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), - hidden$: getInsertAfterMenuHidden$(accessor, 'row'), + disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertRowPermission, WorksheetEditPermission] }), }; } @@ -97,8 +93,7 @@ export function InsertColBeforeMenuItemFactory(accessor: IAccessor): IMenuButton type: MenuItemType.BUTTON, title: 'rightClick.insertColumnBefore', icon: 'LeftInsertColumn', - disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertColumnPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), - hidden$: getInsertBeforeMenuHidden$(accessor, 'col'), + disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertColumnPermission, WorksheetEditPermission] }), }; } @@ -108,8 +103,7 @@ export function InsertColAfterMenuItemFactory(accessor: IAccessor): IMenuButtonI type: MenuItemType.BUTTON, title: 'rightClick.insertColumn', icon: 'RightInsertColumn', - disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertColumnPermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), - hidden$: getInsertAfterMenuHidden$(accessor, 'col'), + disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetInsertColumnPermission, WorksheetEditPermission] }), }; } diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts index d42e524314a..cb76448b5bf 100644 --- a/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts +++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-init.controller.ts @@ -19,6 +19,7 @@ import type { IAddRangeProtectionMutationParams, IAddWorksheetProtectionParams, import { Disposable, IAuthzIoService, ICommandService, Inject, InterceptorEffectEnum, IPermissionService, IUndoRedoService, IUniverInstanceService, UniverInstanceType, UserManagerService } from '@univerjs/core'; import { UnitAction, UnitObject } from '@univerjs/protocol'; import { AddRangeProtectionMutation, AddWorksheetProtectionMutation, defaultWorkbookPermissionPoints, defaultWorksheetPermissionPoint, getAllRangePermissionPoint, getAllWorkbookPermissionPoint, getAllWorksheetPermissionPoint, getAllWorksheetPermissionPointByPointPanel, INTERCEPTOR_POINT, RangeProtectionCache, RangeProtectionRuleModel, SetWorksheetPermissionPointsMutation, SheetInterceptorService, WorksheetEditPermission, WorksheetProtectionPointModel, WorksheetProtectionRuleModel, WorksheetViewPermission } from '@univerjs/sheets'; +import { skip } from 'rxjs'; export class SheetPermissionInitController extends Disposable { constructor( @@ -282,7 +283,8 @@ export class SheetPermissionInitController extends Disposable { private _initUserChange() { this.disposeWithMe( - this._userManagerService.currentUser$.subscribe(() => { + // When the user changes, the permission points are updated. The first modification needs to be filtered here because it is a Behavior type, but in fact the user information is ready when this controller is initialized. + this._userManagerService.currentUser$.pipe(skip(1)).subscribe(() => { // This is to minimize the need for access providers to update the reference to permission points when the current user changes, reducing the integration steps required. // If not handled this way, the access providers would have to handle the changes in user and the resulting changes in permission point references. const _map = this._permissionService.getAllPermissionPoint(); diff --git a/packages/sheets-ui/src/views/permission/panel-detail/index.tsx b/packages/sheets-ui/src/views/permission/panel-detail/index.tsx index 5f725ef71bf..132f957d193 100644 --- a/packages/sheets-ui/src/views/permission/panel-detail/index.tsx +++ b/packages/sheets-ui/src/views/permission/panel-detail/index.tsx @@ -59,11 +59,13 @@ export const SheetPermissionPanelDetail = ({ fromSheetBar }: { fromSheetBar: boo const selectUserList = useObservable(sheetPermissionUserManagerService.selectUserList$, sheetPermissionUserManagerService.selectUserList); -// The status of these two collaborators is updated directly by calling the interface, and will not be written to the snapshot or undoredo, so they are pulled in real time when they need to be displayed. + // The status of these two collaborators is updated directly by calling the interface, and will not be written to the snapshot or undoredo, so they are pulled in real time when they need to be displayed. const [editorGroupValue, setEditorGroupValue] = React.useState(selectUserList.length ? editState.designedUserCanEdit : editState.onlyMe); const [viewGroupValue, setViewGroupValue] = React.useState(viewState.othersCanView); const [loading, setLoading] = useState(!!activeRule?.permissionId); + const [rangeInitialization, setRangeInitialization] = useState(false); + const handleAddPerson = async () => { const userList = await authzIoService.listCollaborators({ objectID: unitId, @@ -182,6 +184,7 @@ export const SheetPermissionPanelDetail = ({ fromSheetBar }: { fromSheetBar: boo unitType: fromSheetBar ? UnitObject.Worksheet : UnitObject.SelectRange, }); + setRangeInitialization(true); }, [activeRule?.permissionId, fromSheetBar, selectionManagerService, sheetPermissionPanelModel, subUnitId, unitId, worksheet]); useEffect(() => { @@ -330,6 +333,8 @@ export const SheetPermissionPanelDetail = ({ fromSheetBar }: { fromSheetBar: boo handleOutClick && handleOutClick(e, isFocusRangeSelectorSet); }; + const rangeStr = activeRule?.ranges?.map((i) => serializeRange(i)).join(','); + return (
{/* @@ -342,18 +347,18 @@ export const SheetPermissionPanelDetail = ({ fromSheetBar }: { fromSheetBar: boo */} - {RangeSelector && ( + {RangeSelector && rangeInitialization && ( serializeRange(i)).join(',')} + initValue={rangeStr} onChange={handleRangeChange} - // onVerify={handleVerify} + // onVerify={handleVerify} isFocus={isFocusRangeSelector} actions={rangeSelectorActionsRef.current} /> - ) } + )}