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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-ui): hide gridlines outside sheets (#7486)
Univer3350da7e43b4
diff --git a/packages/sheets-ui/src/menu/__tests__/gridlines.menu.spec.ts b/packages/sheets-ui/src/menu/__tests__/gridlines.menu.spec.tsnew file mode 100644index 0000000000..80c17025ed--- /dev/null+++ b/packages/sheets-ui/src/menu/__tests__/gridlines.menu.spec.ts@@ -0,0 +1,60 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import {+ ICommandService,+ IContextService,+ Injector,+ IUniverInstanceService,+ UniverInstanceType,+ UserManagerService,+} from '@univerjs/core';+import { of, Subject } from 'rxjs';+import { describe, expect, it } from 'vitest';+import { ToggleGridlinesMenuFactory } from '../gridlines.menu';++function createMenuAccessor(unitType: UniverInstanceType): Injector {+ return new Injector([+ [ICommandService, { useValue: {} }],+ [IUniverInstanceService, {+ useValue: {+ focused$: new Subject<string | null>(),+ getFocusedUnit: () => ({ getUnitId: () => 'unit-1' }),+ getCurrentUnitOfType: () => null,+ getCurrentTypeOfUnit$: () => of(null),+ getUnitType: () => unitType,+ },+ }],+ [UserManagerService, { useValue: { currentUser$: of(null) } }],+ [IContextService, { useValue: { subscribeContextValue$: () => of(false) } }],+ ]);+}++describe('gridlines menu visibility', () => {+ it.each([+ [UniverInstanceType.UNIVER_SHEET, false],+ [UniverInstanceType.UNIVER_SLIDE, true],+ ])('for focused unit type %s sets hidden to %s', (unitType, expectedHidden) => {+ const accessor = createMenuAccessor(unitType);+ const hiddenValues: boolean[] = [];+ const subscription = ToggleGridlinesMenuFactory(accessor).hidden$?.subscribe((hidden) => hiddenValues.push(hidden));++ expect(hiddenValues).toEqual([expectedHidden]);++ subscription?.unsubscribe();+ accessor.dispose();+ });+});diff --git a/packages/sheets-ui/src/menu/gridlines.menu.ts b/packages/sheets-ui/src/menu/gridlines.menu.tsindex 4e61049f7d..c14e5cdf23 100644--- a/packages/sheets-ui/src/menu/gridlines.menu.ts+++ b/packages/sheets-ui/src/menu/gridlines.menu.ts@@ -31,7 +31,7 @@ import {WorkbookEditablePermission,WorksheetEditPermission,} from '@univerjs/sheets';-import { MenuItemType } from '@univerjs/ui';+import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';import { Observable } from 'rxjs';import { getCurrentRangeDisable$ } from './menu-util';@@ -44,6 +44,7 @@ export function ToggleGridlinesMenuFactory(accessor: IAccessor): IMenuButtonItemtype: MenuItemType.BUTTON,tooltip: 'sheets-ui.toolbar.toggleGridlines',icon: 'HideGridlinesIcon',+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),activated$: new Observable<boolean>((observer) => {const getValue = () => {const workbook = instanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);