From 76e9ab804d7fee119206d6013a9502685596b84b Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 9 Jan 2024 16:26:13 +0800 Subject: [PATCH 1/2] Move UseComponent extension methods to Framework --- docs/en/UI/Blazor/Basic-Theme.md | 4 +-- .../Navigation/ApplicationMenuExtensions.cs | 19 +++++++++++++- .../BasicThemeNavigationExtensions.cs | 26 ------------------- .../Themes/Basic/FirstLevelNavMenuItem.razor | 3 +-- .../Themes/Basic/SecondLevelNavMenuItem.razor | 3 +-- 5 files changed, 22 insertions(+), 33 deletions(-) delete mode 100644 modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Navigation/BasicThemeNavigationExtensions.cs diff --git a/docs/en/UI/Blazor/Basic-Theme.md b/docs/en/UI/Blazor/Basic-Theme.md index e4124d9a2cd..0c3fc83bd0f 100644 --- a/docs/en/UI/Blazor/Basic-Theme.md +++ b/docs/en/UI/Blazor/Basic-Theme.md @@ -86,10 +86,10 @@ You can simply override the styles in the Global Styles file of your application See the [Customization / Overriding Components](Customization-Overriding-Components.md) to learn how you can replace components, customize and extend the user interface. ### Overriding the Menu Item -Basic theme supports overriding a single menu item with a custom component. You can create a custom component and call `UseComponent` extension method of Basic Theme in the **MenuContributor**. +Basic theme supports overriding a single menu item with a custom component. You can create a custom component and call `UseComponent` extension method in the **MenuContributor**. ```csharp -using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Navigation; +using Volo.Abp.UI.Navigation; //... diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs index 59814ff3be6..48d16d12516 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs @@ -1,11 +1,13 @@ +using System; using JetBrains.Annotations; using System.Linq; -using Volo.Abp.UI.Navigation; namespace Volo.Abp.UI.Navigation; public static class ApplicationMenuExtensions { + public const string CustomDataComponentKey = "ApplicationMenuCustomComponent"; + [NotNull] public static ApplicationMenuItem GetAdministration( [NotNull] this ApplicationMenu applicationMenu) @@ -112,4 +114,19 @@ public static IHasMenuGroups SetMenuGroupOrder( return menuWithGroups; } + + public static ApplicationMenuItem UseComponent(this ApplicationMenuItem applicationMenuItem, Type componentType) + { + return applicationMenuItem.WithCustomData(CustomDataComponentKey, componentType); + } + + public static Type? GetComponentTypeOrDefault(this ApplicationMenuItem applicationMenuItem) + { + if (applicationMenuItem.CustomData.TryGetValue(CustomDataComponentKey, out var value)) + { + return value as Type; + } + + return default; + } } diff --git a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Navigation/BasicThemeNavigationExtensions.cs b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Navigation/BasicThemeNavigationExtensions.cs deleted file mode 100644 index 020709f56c4..00000000000 --- a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Navigation/BasicThemeNavigationExtensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using JetBrains.Annotations; -using Volo.Abp.UI.Navigation; - -namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Navigation; - -public static class BasicThemeNavigationExtensions -{ - public const string CustomDataComponentKey = "BasicTheme.CustomComponent"; - - public static ApplicationMenuItem UseComponent(this ApplicationMenuItem applicationMenuItem, Type componentType) - { - return applicationMenuItem.WithCustomData(CustomDataComponentKey, componentType); - } - - [CanBeNull] - public static Type GetComponentTypeOrDefault(this ApplicationMenuItem applicationMenuItem) - { - if (applicationMenuItem.CustomData.TryGetValue(CustomDataComponentKey, out object componentType)) - { - return componentType as Type; - } - - return default; - } -} \ No newline at end of file diff --git a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/FirstLevelNavMenuItem.razor b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/FirstLevelNavMenuItem.razor index 1f469a809a0..070d514cb65 100644 --- a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/FirstLevelNavMenuItem.razor +++ b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/FirstLevelNavMenuItem.razor @@ -1,5 +1,4 @@ -@using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Navigation; -@using Volo.Abp.UI.Navigation +@using Volo.Abp.UI.Navigation @{ var elementId = MenuItem.ElementId ?? "MenuItem_" + MenuItem.Name.Replace(".", "_"); var cssClass = string.IsNullOrEmpty(MenuItem.CssClass) ? string.Empty : MenuItem.CssClass; diff --git a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/SecondLevelNavMenuItem.razor b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/SecondLevelNavMenuItem.razor index 6d9ffb1fea8..2a93e5459e1 100644 --- a/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/SecondLevelNavMenuItem.razor +++ b/modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/SecondLevelNavMenuItem.razor @@ -1,5 +1,4 @@ -@using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Navigation; -@using Volo.Abp.UI.Navigation +@using Volo.Abp.UI.Navigation @{ var elementId = MenuItem.ElementId ?? "MenuItem_" + MenuItem.Name.Replace(".", "_"); var cssClass = string.IsNullOrEmpty(MenuItem.CssClass) ? string.Empty : MenuItem.CssClass; From 3154128dd08df9fe1c897b378a77e68f8ab36ab8 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 9 Jan 2024 16:26:55 +0800 Subject: [PATCH 2/2] Update ApplicationMenuExtensions.cs --- .../Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs index 48d16d12516..5a755f187ab 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.UI.Navigation; public static class ApplicationMenuExtensions { - public const string CustomDataComponentKey = "ApplicationMenuCustomComponent"; + public const string CustomDataComponentKey = "ApplicationMenu.CustomComponent"; [NotNull] public static ApplicationMenuItem GetAdministration(