Skip to content

Commit

Permalink
fix: submenus show/hide rule (#1875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet authored Oct 31, 2022
1 parent 8e9c90f commit 462e08f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/core-browser/src/components/actions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'classnames';
import React, { useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';

import { Button, CheckBox, Icon } from '@opensumi/ide-components';
import { ClickParam, Menu } from '@opensumi/ide-components/lib/menu';
Expand All @@ -16,6 +16,8 @@ import {
SubmenuItemNode,
IMenuAction,
ComponentMenuItemNode,
AbstractMenuService,
generateMergedCtxMenu,
} from '../../menu/next';
import { useInjectable } from '../../react-hooks';
import { useMenus, useContextMenus } from '../../utils';
Expand Down Expand Up @@ -351,8 +353,8 @@ export const TitleActionList: React.FC<
regroup = (...args: [MenuNode[], MenuNode[]]) => args,
}) => {
const ctxMenuRenderer = useInjectable<ICtxMenuRenderer>(ICtxMenuRenderer);
const abstractMenuService = useInjectable<AbstractMenuService>(AbstractMenuService);
const [primary, secondary] = regroup(nav, more);

const handleShowMore = React.useCallback(
(e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
Expand Down Expand Up @@ -391,6 +393,14 @@ export const TitleActionList: React.FC<
);
}

if (item.id === SubmenuItemNode.ID) {
const menus = abstractMenuService.createMenu((item as SubmenuItemNode).submenuId);
const hasSubMenu = generateMergedCtxMenu({ menus }).length > 0;
if (!hasSubMenu) {
return;
}
}

// submenu 使用 submenu-id 作为 id 唯一值
const id = item.id === SubmenuItemNode.ID ? (item as SubmenuItemNode).submenuId : item.id;
return (
Expand Down

0 comments on commit 462e08f

Please sign in to comment.