From 32eeb88101df01d9c804834a0f941466bddf5383 Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 11 Nov 2024 10:09:46 +0800 Subject: [PATCH] feat: support hiding menu items (#5624) * feat: support hiding menu items * fix: hidden --- .../schema-component/antd/menu/Menu.Designer.tsx | 15 +++++++++++++++ .../src/schema-component/antd/menu/Menu.tsx | 14 ++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/menu/Menu.Designer.tsx b/packages/core/client/src/schema-component/antd/menu/Menu.Designer.tsx index 02bc320bae..85d8232bb6 100644 --- a/packages/core/client/src/schema-component/antd/menu/Menu.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/menu/Menu.Designer.tsx @@ -20,6 +20,7 @@ import { SchemaSettingsModalItem, SchemaSettingsRemove, SchemaSettingsSubMenu, + SchemaSettingsSwitchItem, useAPIClient, useDesignable, useURLAndHTMLSchema, @@ -373,6 +374,20 @@ export const MenuDesigner = () => { initialValues={initialValues} onSubmit={onEditSubmit} /> + { + fieldSchema['x-component-props'].hidden = !!v; + field.componentProps.hidden = !!v; + dn.emit('patch', { + schema: { + 'x-uid': fieldSchema['x-uid'], + 'x-component-props': fieldSchema['x-component-props'], + }, + }); + }} + /> { const { t } = useMenuTranslation(); + const { designable } = useDesignable(); const { pushMenuItem } = useCollectMenuItems(); - const { icon, children, ...others } = props; + const { icon, children, hidden, ...others } = props; const schema = useFieldSchema(); const field = useField(); const Designer = useContext(MenuItemDesignerContext); const item = useMemo(() => { return { ...others, + hidden: designable ? false : hidden, className: menuItemClass, key: schema.name, eventKey: schema.name, @@ -599,7 +601,8 @@ const MenuURLButton = ({ href, params, icon }) => { Menu.URL = observer( (props) => { const { pushMenuItem } = useCollectMenuItems(); - const { icon, children, ...others } = props; + const { designable } = useDesignable(); + const { icon, children, hidden, ...others } = props; const schema = useFieldSchema(); const field = useField(); const Designer = useContext(MenuItemDesignerContext); @@ -612,6 +615,7 @@ Menu.URL = observer( const item = useMemo(() => { return { ...others, + hidden: designable ? false : hidden, className: menuItemClass, key: schema.name, eventKey: schema.name, @@ -625,7 +629,7 @@ Menu.URL = observer( ), }; - }, [field.title, icon, props.href, schema, JSON.stringify(props.params)]); + }, [field.title, designable, hidden, icon, props.href, schema, JSON.stringify(props.params)]); pushMenuItem(item); return null; @@ -636,9 +640,10 @@ Menu.URL = observer( Menu.SubMenu = observer( (props) => { const { t } = useMenuTranslation(); + const { designable } = useDesignable(); const { Component, getMenuItems } = useMenuItem(); const { pushMenuItem } = useCollectMenuItems(); - const { icon, children, ...others } = props; + const { icon, children, hidden, ...others } = props; const schema = useFieldSchema(); const field = useField(); const mode = useContext(MenuModeContext); @@ -646,6 +651,7 @@ Menu.SubMenu = observer( const submenu = useMemo(() => { return { ...others, + hidden: designable ? false : hidden, className: menuItemClass, key: schema.name, eventKey: schema.name,