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 permission rangeSelector & insert menu (#3757)

ybzky1f43484f4d92
diff --git a/packages/sheets-ui/src/controllers/menu/insert.menu.ts b/packages/sheets-ui/src/controllers/menu/insert.menu.ts
index a547854a49..b365bfff63 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<string> {
@@ -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 d42e524314..cb76448b5b 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 5f725ef71b..132f957d19 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<editState>(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 (
<div className={styles.permissionPanelDetailWrapper} onClick={handlePanelClick}>
{/* <FormLayout className={styles.sheetPermissionPanelTitle} label={localeService.t('permission.panel.name')}>
@@ -342,18 +347,18 @@ export const SheetPermissionPanelDetail = ({ fromSheetBar }: { fromSheetBar: boo
</FormLayout> */}
<Spin loading={loading}>
<FormLayout className={styles.sheetPermissionPanelTitle} label={localeService.t('permission.panel.protectedRange')}>
- {RangeSelector && (
+ {RangeSelector && rangeInitialization && (
<RangeSelector
unitId={unitId}
errorText={rangeErrorMsg}
subUnitId={subUnitId}
- initValue={activeRule?.ranges?.map((i) => serializeRange(i)).join(',')}
+ initValue={rangeStr}
onChange={handleRangeChange}
- // onVerify={handleVerify}
+ // onVerify={handleVerify}
isFocus={isFocusRangeSelector}
actions={rangeSelectorActionsRef.current}
/>
- ) }
+ )}
</FormLayout>
<FormLayout className={styles.sheetPermissionPanelTitle} label={localeService.t('permission.panel.permissionDirection')}>
<Input