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(sheets-ui): hide mobile add sheet button without permission (#8088)

白熱ae32faa2856e
diff --git a/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx b/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx
index f7f257d508..7c598c33df 100644
--- a/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx
+++ b/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx
@@ -323,16 +323,14 @@ function MobileSheetBarImpl(props: { workbook: Workbook }) {
))}
</div>
</div>
- {addSheetButtonShow && (
+ {addSheetButtonShow && !addSheetDisabled && (
<button
type="button"
aria-label={localeService.t<LocaleKey>('sheets-ui.mobile.addSheet')}
- disabled={addSheetDisabled}
className={clsx(resetButtonClassName, borderLeftClassName, `
univer-flex univer-h-10 univer-w-12 univer-shrink-0 univer-items-center univer-justify-center
univer-bg-gray-100 univer-text-lg univer-text-gray-800
active:univer-bg-gray-200
- disabled:univer-cursor-not-allowed disabled:univer-opacity-40
dark:!univer-bg-gray-800 dark:!univer-text-gray-100
dark:active:!univer-bg-gray-700
`)}
diff --git a/packages/sheets-ui/src/views/mobile/sheet-bar/__tests__/MobileSheetBar.spec.tsx b/packages/sheets-ui/src/views/mobile/sheet-bar/__tests__/MobileSheetBar.spec.tsx
index e8a049e15a..614ddcd4d0 100644
--- a/packages/sheets-ui/src/views/mobile/sheet-bar/__tests__/MobileSheetBar.spec.tsx
+++ b/packages/sheets-ui/src/views/mobile/sheet-bar/__tests__/MobileSheetBar.spec.tsx
@@ -42,6 +42,8 @@ import enUS from '../../../../locale/en-US';
import { ISheetBarService, SheetBarService } from '../../../../services/sheet-bar/sheet-bar.service';
import { MobileSheetBar } from '../MobileSheetBar';
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
const disposals: Array<() => void> = [];
function renderSheetBar(show = true) {
@@ -87,18 +89,17 @@ describe('MobileSheetBar permissions', () => {
{ label: 'workbook editing', Permission: WorkbookEditablePermission },
{ label: 'sheet creation', Permission: WorkbookCreateSheetPermission },
])(
- 'prevents insertion when $label is revoked and allows it after permission is restored',
+ 'hides the add button when $label is revoked and allows insertion after permission is restored',
async ({ Permission }) => {
const { container, workbook, permissions } = renderSheetBar();
- const button = container.querySelector<HTMLButtonElement>('button[aria-label="Add sheet"]')!;
const initialCount = workbook.getSheets().length;
const permission = new Permission(workbook.getUnitId());
act(() => permissions.updatePermissionPoint(permission.id, false));
- expect(button.disabled).toBe(true);
- await act(async () => button.click());
- expect(workbook.getSheets()).toHaveLength(initialCount);
+ expect(container.querySelector('button[aria-label="Add sheet"]')).toBeNull();
act(() => permissions.updatePermissionPoint(permission.id, true));
+ const button = container.querySelector<HTMLButtonElement>('button[aria-label="Add sheet"]')!;
+ expect(button).not.toBeNull();
expect(button.disabled).toBe(false);
await act(async () => button.click());
expect(workbook.getSheets()).toHaveLength(initialCount + 1);