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: fix status bar performance #2537

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: fix status bar performance
  • Loading branch information
ybzky committed Jun 17, 2024
commit 7e4b4b78c9cf7f74705202d6f1dd4bf7358d7f54
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
* limitations under the License.
*/

import type { ICellDataForSheetInterceptor, IRange, Workbook } from '@univerjs/core';
import type { Workbook } from '@univerjs/core';
import { DisposableCollection, IPermissionService, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable } from '@univerjs/core';
import { getSheetCommandTarget, RangeProtectionRuleModel } from '@univerjs/sheets';
import { getSheetCommandTarget, RangeProtectionRenderModel, WorksheetViewPermission } from '@univerjs/sheets';
import { Inject, Injector } from '@wendellhu/redi';
import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { UnitAction } from '@univerjs/protocol';
import { NullValueObject } from '@univerjs/engine-formula';
import { StatusBarController } from '../status-bar.controller';

type ICellPermission = Record<UnitAction, boolean> & { ruleId?: string; ranges?: IRange[] };

export const SHEET_PERMISSION_PASTE_PLUGIN = 'SHEET_PERMISSION_PASTE_PLUGIN';

@OnLifecycle(LifecycleStages.Steady, SheetPermissionInterceptorFormulaRenderController)
Expand All @@ -36,8 +34,8 @@ export class SheetPermissionInterceptorFormulaRenderController extends RxDisposa
@Inject(Injector) private readonly _injector: Injector,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IPermissionService private readonly _permissionService: IPermissionService,
@Inject(RangeProtectionRuleModel) private _rangeProtectionRuleModel: RangeProtectionRuleModel,
@Inject(StatusBarController) private readonly _statusBarController: StatusBarController
@Inject(StatusBarController) private readonly _statusBarController: StatusBarController,
@Inject(RangeProtectionRenderModel) private _rangeProtectionRenderModel: RangeProtectionRenderModel
) {
super();
this._initStatusBarPermissionInterceptor();
Expand All @@ -52,20 +50,36 @@ export class SheetPermissionInterceptorFormulaRenderController extends RxDisposa
if (!target) {
return defaultValue ?? [];
}
const { worksheet } = target;
originValue.forEach((item) => {
const itemValue = item.getArrayValue();
const startRow = item.getCurrentRow();
const startCol = item.getCurrentColumn();
itemValue.forEach((row, rowIndex) => {
row.forEach((col, colIndex) => {
const permission = (worksheet.getCell(rowIndex + startRow, colIndex + startCol) as (ICellDataForSheetInterceptor & { selectionProtection: ICellPermission[] }))?.selectionProtection?.[0];
if (permission?.[UnitAction.View] === false) {
const { worksheet, unitId, subUnitId } = target;
const sheetViewPermission = this._permissionService.getPermissionPoint(new WorksheetViewPermission(unitId, subUnitId).id)?.value;
if (sheetViewPermission === false) {
originValue.forEach((item) => {
const itemValue = item.getArrayValue();
itemValue.forEach((row, rowIndex) => {
row.forEach((col, colIndex) => {
itemValue[rowIndex][colIndex] = NullValueObject.create();
}
});
});
});
} else {
originValue.forEach((item) => {
const itemValue = item.getArrayValue();
const startRow = item.getCurrentRow();
const startCol = item.getCurrentColumn();
itemValue.forEach((row, rowIndex) => {
row.forEach((col, colIndex) => {
const cellValue = worksheet.getCellRaw(rowIndex + startRow, colIndex + startCol)?.v;
if (cellValue === undefined) {
return;
}
const permission = this._rangeProtectionRenderModel.getCellInfo(unitId, subUnitId, rowIndex + startRow, colIndex + startCol)?.[0];
if (permission?.[UnitAction.View] === false) {
itemValue[rowIndex][colIndex] = NullValueObject.create();
}
});
});
});
});
}
return originValue;
},
})
Expand Down
Loading