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.

refactor(ui): sheet bar right menu

Dushusirf41a4969f784
diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.ts
index 7e7991adfc..e46df7ca75 100644
--- a/packages/base-sheets/src/index.ts
+++ b/packages/base-sheets/src/index.ts
@@ -67,3 +67,4 @@ export {
export { SetWorksheetRowHideCommand } from './Commands/Commands/set-worksheet-row-hide.command';
export { SetWorksheetRowShowCommand } from './Commands/Commands/set-worksheet-row-show.command';
export { RemoveSheetCommand } from './Commands/Commands/remove-sheet.command';
+export { SetWorksheetHideCommand } from './Commands/Commands/set-worksheet-hide.command';
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 6c3312ae28..748cdb8884 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -122,6 +122,14 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
}
};
+ handleItemClick = (item:IMenuButtonItem) =>{
+
+ // When there is no need to execute the command, execute click
+ if(item.onClick){
+ item.onClick()
+ }
+ this.showMenu(false)
+ }
// eslint-disable-next-line max-lines-per-function
render() {
const { context, props, state } = this;
@@ -200,8 +208,8 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
);
})}
{/* render submenus */}
- {menuItems?.map((item, index) => (
- <MenuItem menuItem={item} index={index} onClick={() => this.showMenu(false)} />
+ {menuItems?.map((item: IDisplayMenuItem<IMenuItem>, index) => (
+ <MenuItem menuItem={item} index={index} onClick={this.handleItemClick.bind(this,item as IMenuButtonItem)} />
))}
</ul>
);
@@ -335,7 +343,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
const item = menuItem as IDisplayMenuItem<IMenuButtonItem>;
return (
- <li className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}>
+ <li className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')} onClick={(e) => this.handleClick(e, item, index)}>
{/* FIXME after translate title,use title for value display*/}
<NeoCustomLabel value={item.title} onChange={this.onChange}></NeoCustomLabel>
</li>
diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.ts
index d1c2ee57d7..0d0eb9f788 100644
--- a/packages/base-ui/src/services/menu/menu.ts
+++ b/packages/base-ui/src/services/menu/menu.ts
@@ -56,6 +56,8 @@ export interface IMenuButtonItem extends IMenuItemBase {
type: MenuItemType.BUTTON;
activated$?: Observable<boolean>;
+
+ onClick?: (...arg: any) => void; // menu button click callback, does not trigger command. e.g. sheet bar rename
}
export function isMenuButtonItem(v: IMenuItem): v is IMenuButtonItem {
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
index c401528c5f..5b654d30d9 100644
--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
@@ -23,7 +23,7 @@ import { SheetBar } from '../View/SheetBar';
import styles from '../View/SheetBar/index.module.less';
import { SheetBarMenuItem } from '../View/SheetBar/SheetBarMenu';
import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const';
-import { DeleteSheetMenuItemFactory } from './menu';
+import { ChangeColorSheetMenuItemFactory, CopySheetMenuItemFactory, DeleteSheetMenuItemFactory, HideSheetMenuItemFactory, RenameSheetMenuItemFactory, UnHideSheetMenuItemFactory } from './menu';
interface SheetUl extends BaseMenuItem {
label?: ICustomComponent | string;
@@ -358,7 +358,14 @@ export class SheetBarUIController extends Disposable {
}
private _initializeContextMenu() {
- [DeleteSheetMenuItemFactory].forEach((factory) => {
+ [
+ DeleteSheetMenuItemFactory,
+ CopySheetMenuItemFactory,
+ RenameSheetMenuItemFactory,
+ ChangeColorSheetMenuItemFactory,
+ HideSheetMenuItemFactory,
+ UnHideSheetMenuItemFactory,
+ ].forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
});
}
diff --git a/packages/ui-plugin-sheets/src/Controller/menu.ts b/packages/ui-plugin-sheets/src/Controller/menu.ts
index 2fa29cb3f4..acb0eca163 100644
--- a/packages/ui-plugin-sheets/src/Controller/menu.ts
+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts
@@ -29,6 +29,7 @@ import {
RemoveSheetCommand,
SetWorksheetRowHideCommand,
SetWorksheetRowShowCommand,
+ SetWorksheetHideCommand,
} from '@univerjs/base-sheets';
import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes, IDisplayMenuItem, IValueOption, ICustomComponentOption } from '@univerjs/base-ui';
import { FontItalic, FontWeight, ICommandService, IPermissionService, IUndoRedoService, RedoCommand, UndoCommand } from '@univerjs/core';
@@ -703,8 +704,76 @@ export function DeleteRangeMoveUpMenuItemFactory(accessor: IAccessor): IMenuButt
export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: RemoveSheetCommand.id,
+ type: MenuItemType.BUTTON,
positions: [MenuPosition.SHEET_BAR],
title: 'sheetConfig.delete',
+ parentId: 'sheet-bar-right-menu',
+ };
+}
+
+export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ // TODO@Dushusir use real command id
+ id: "CopySheetCommand.id",
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.copy',
+ parentId: 'sheet-bar-right-menu',
+ };
+}
+
+// TODO@Dushusir onClick to rename tab
+// No need to trigger command after clicking,maybe no need Command id?
+export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: "RenameSheetCommand.id",
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.rename',
+ parentId: 'sheet-bar-right-menu',
+ onClick:()=>{
+ // TODO@Dushusir 这里能监听到点击事件,但是无法触发到 this._sheetBar.reNameSheet(this._dataId);
+ console.info('rename=========')
+ }
+ };
+}
+
+// TODO@Dushusir add command
+export function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ return {
+ id: "ChangeColorSheetCommand.id",
+ title: 'sheetConfig.changeColor',
+ positions: [MenuPosition.SHEET_BAR],
+ display: DisplayTypes.COLOR,
+ selectType: SelectTypes.NEO,
+ type: MenuItemType.SELECTOR,
+ selections: [
+ {
+ id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
+ },
+ ],
+ parentId: 'sheet-bar-right-menu',
+ };
+}
+
+export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: SetWorksheetHideCommand.id,
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.hide',
+ parentId: 'sheet-bar-right-menu',
+ };
+}
+
+// TODO@Dushusir use show worksheet command
+export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: "SetWorksheetHideCommand.id",
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.SHEET_BAR],
+ title: 'sheetConfig.unhide',
+ parentId: 'sheet-bar-right-menu',
};
}
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index 3ca5fc3838..7811c64157 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -214,7 +214,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
</div>
{/* mouse right button context menu */}
- <Menu className={styles.sheetUl} menu={sheetUl} menuItems={this.state.menuItems} ref={this.ulRef} />
+ <Menu className={styles.sheetUl} menu={sheetUl} menuId={'sheet-bar-right-menu'} ref={this.ulRef} />
{/* prev next scroll button */}
<div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}>