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(ui): fix missing context menu items #3758

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import type { IAccessor, ICommand } from '@univerjs/core';
import { CommandType, ICommandService, LocaleService } from '@univerjs/core';
import { IConfirmService } from '@univerjs/ui';
import type { IAccessor, ICommand } from '@univerjs/core';
import { COMPONENT_DOC_CREATE_TABLE_CONFIRM } from '../../views/table/create/component-name';
import { CreateDocTableCommand } from '../commands/table/doc-table-create.command';

Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import type { MenuSchemaType } from '@univerjs/ui';
import { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../commands/commands/clipboard.command';
import { DeleteLeftCommand } from '../commands/commands/delete.command';
import { OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
Expand Down
8 changes: 5 additions & 3 deletions packages/docs-ui/src/controllers/menu/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import type { IAccessor } from '@univerjs/core';
import type { IRectRangeWithStyle } from '@univerjs/engine-render';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, Observable } from 'rxjs';
import type { IAccessor } from '@univerjs/core';
import type { IRectRangeWithStyle } from '@univerjs/engine-render';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../../commands/commands/clipboard.command';
import { DeleteLeftCommand } from '../../commands/commands/delete.command';
import { DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand } from '../../commands/commands/table/doc-table-delete.command';
Expand Down Expand Up @@ -85,6 +85,8 @@ const getDisableWhenSelectionNotInTableObservable = (accessor: IAccessor) => {
subscriber.next(true);
});

subscriber.next(true);

return () => observable.unsubscribe();
});
};
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import type { MenuSchemaType } from '@univerjs/ui';
import {
AddWorksheetMergeAllCommand,
AddWorksheetMergeCommand,
Expand Down Expand Up @@ -42,7 +43,6 @@ import {
SetWorksheetRowIsAutoHeightCommand,
} from '@univerjs/sheets';
import { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import type { MenuSchemaType } from '@univerjs/ui';
import {
SheetCopyCommand,
// SheetCutCommand,
Expand Down
27 changes: 14 additions & 13 deletions packages/ui/src/components/menu/desktop/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { CheckMarkSingle, MoreSingle } from '@univerjs/icons';
import clsx from 'clsx';
import React, { useMemo, useState } from 'react';

import { combineLatest, isObservable, map, Observable } from 'rxjs';
import { combineLatest, isObservable, Observable } from 'rxjs';
import { ILayoutService } from '../../../services/layout/layout.service';
import { MenuItemType } from '../../../services/menu/menu';
import { IMenuManagerService } from '../../../services/menu/menu-manager.service';
Expand Down Expand Up @@ -74,18 +74,19 @@ function MenuWrapper(props: IBaseMenuProps) {
if (!item.children) return item;

let hasChildren = false;
const hiddenObservables = item.children?.map((item) => item.item?.hidden$ ?? new Observable<boolean>((n) => n.next(false)));

combineLatest(hiddenObservables)
.pipe(
map((hiddenValues) => hiddenValues.every((hidden) => hidden === true))
)
.subscribe((allHidden) => {
if (!allHidden) {
hasChildren = true;
}
})
.unsubscribe();
const hiddenObservables = item.children?.map((subItem) => {
return subItem.item?.hidden$ ?? new Observable<boolean>((s) => {
s.next(false);
return s.unsubscribe();
});
});
combineLatest(hiddenObservables).subscribe((hiddenValues) => {
hasChildren = hiddenValues.every((hidden) => hidden === true);

if (!hasChildren) {
hasChildren = true;
}
}).unsubscribe();

return hasChildren;
});
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/services/confirm/desktop-confirm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
* limitations under the License.
*/

import type { IConfirmPartMethodOptions } from '../../views/components/confirm-part/interface';
import type { IConfirmService } from './confirm.service';
import { connectInjector, Disposable, toDisposable } from '@univerjs/core';
import { type IDisposable, Inject, Injector } from '@univerjs/core';
import { Subject } from 'rxjs';

import type { IConfirmPartMethodOptions } from '../../views/components/confirm-part/interface';
import { BuiltInUIPart, IUIPartsService } from '../parts/parts.service';
import { type IDisposable, Inject, Injector } from '@univerjs/core';
import { BehaviorSubject } from 'rxjs';
import { ConfirmPart } from '../../views/components/confirm-part/ConfirmPart';
import type { IConfirmService } from './confirm.service';
import { BuiltInUIPart, IUIPartsService } from '../parts/parts.service';

export class DesktopConfirmService extends Disposable implements IConfirmService {
private _confirmOptions: IConfirmPartMethodOptions[] = [];
readonly confirmOptions$ = new Subject<IConfirmPartMethodOptions[]>();
readonly confirmOptions$ = new BehaviorSubject<IConfirmPartMethodOptions[]>([]);

constructor(
@Inject(Injector) protected readonly _injector: Injector,
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/services/menu/menu-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

import type { IAccessor, Nullable } from '@univerjs/core';
import { createIdentifier, Disposable, IConfigService, Inject, Injector, Tools } from '@univerjs/core';
import type { Observable } from 'rxjs';
import { Subject } from 'rxjs';
import type { IMenuItem } from '../menu/menu';
import { createIdentifier, Disposable, IConfigService, Inject, Injector, Tools } from '@univerjs/core';
import { Subject } from 'rxjs';
import { mergeMenuConfigs } from '../../common/menu-merge-configs';
import { ContextMenuGroup, ContextMenuPosition, MenuManagerPosition, RibbonDataGroup, RibbonFormulasGroup, RibbonInsertGroup, RibbonOthersGroup, RibbonPosition, RibbonStartGroup, RibbonViewGroup } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/

import type { IConfirmProps } from '@univerjs/design';
import { Confirm } from '@univerjs/design';
import type { IConfirmPartMethodOptions } from './interface';
import { useDependency } from '@univerjs/core';
import React, { useEffect, useState } from 'react';
import { Confirm } from '@univerjs/design';

import React, { useEffect, useState } from 'react';
import { CustomLabel } from '../../../components/custom-label/CustomLabel';
import { IConfirmService } from '../../../services/confirm/confirm.service';
import type { IConfirmPartMethodOptions } from './interface';

export function ConfirmPart() {
const confirmService = useDependency(IConfirmService);
Expand Down