From c5388fc0446426b60a6d6ba8f7e306ac65c679a1 Mon Sep 17 00:00:00 2001 From: Leon Hoppe Date: Sat, 5 Jul 2025 15:19:35 +0200 Subject: [PATCH] Made search suggestions togglable --- .idea/.idea.HopFrame/.idea/workspace.xml | 38 +++++++------------ src/HopFrame.Core/Config/TableConfig.cs | 8 ++++ .../Components/Pages/HopFrameTablePage.razor | 2 +- .../SearchSuggestionProvider.cs | 2 - testing/HopFrame.Testing/Program.cs | 3 ++ 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.idea/.idea.HopFrame/.idea/workspace.xml b/.idea/.idea.HopFrame/.idea/workspace.xml index 7332fc3..d483158 100644 --- a/.idea/.idea.HopFrame/.idea/workspace.xml +++ b/.idea/.idea.HopFrame/.idea/workspace.xml @@ -12,19 +12,9 @@ - - - - - - - - + - - - - + @@ -703,7 +693,6 @@ diff --git a/src/HopFrame.Core/Config/TableConfig.cs b/src/HopFrame.Core/Config/TableConfig.cs index 2de5648..668cc77 100644 --- a/src/HopFrame.Core/Config/TableConfig.cs +++ b/src/HopFrame.Core/Config/TableConfig.cs @@ -15,6 +15,7 @@ public class TableConfig { public bool Ignored { get; set; } public int Order { get; set; } internal bool Seeded { get; set; } + public bool ShowSearchSuggestions { get; set; } = true; public string? ViewPolicy { get; set; } public string? CreatePolicy { get; set; } @@ -66,6 +67,13 @@ public sealed class TableConfigurator(TableConfig config) { InnerConfig.Ignored = ignore; return this; } + /// + /// Determines if search suggestions should be displayed in the ui (Advanced Search) + /// + public TableConfigurator ShowSearchSuggestions(bool show = true) { + InnerConfig.ShowSearchSuggestions = show; + return this; + } /// /// Configures the property of the table diff --git a/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor b/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor index 84f19c3..f649f7e 100644 --- a/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor +++ b/src/HopFrame.Web/Components/Pages/HopFrameTablePage.razor @@ -314,7 +314,7 @@ } private void UpdateSearchSuggestions() { - if (_config is null) return; + if (_config is null || !_config.ShowSearchSuggestions) return; _searchSuggestions = SearchSuggestions.GenerateSearchSuggestions(_config, _searchTerm ?? string.Empty).ToList(); } diff --git a/src/HopFrame.Web/Services/Implementation/SearchSuggestionProvider.cs b/src/HopFrame.Web/Services/Implementation/SearchSuggestionProvider.cs index e65f347..4ade985 100644 --- a/src/HopFrame.Web/Services/Implementation/SearchSuggestionProvider.cs +++ b/src/HopFrame.Web/Services/Implementation/SearchSuggestionProvider.cs @@ -7,8 +7,6 @@ namespace HopFrame.Web.Services.Implementation; public sealed class SearchSuggestionProvider : ISearchSuggestionProvider { public IEnumerable GenerateSearchSuggestions(TableConfig table, string searchText) { - if (table.ContextConfig is not DbContextConfig) return []; - var searchParts = searchText.Trim().Split(' '); if (searchParts.Length != 0 && searchParts.Last().EndsWith('=') && !searchText.EndsWith(' ')) { var part = searchParts.Last()[..^1]; diff --git a/testing/HopFrame.Testing/Program.cs b/testing/HopFrame.Testing/Program.cs index 2edbd41..320b1c8 100644 --- a/testing/HopFrame.Testing/Program.cs +++ b/testing/HopFrame.Testing/Program.cs @@ -51,6 +51,9 @@ builder.Services.AddHopFrame(options => { .FormatEach((post, _) => post.Caption); }); + context.Table() + .ShowSearchSuggestions(false); + context.Table() .Property(p => p.Author) //.Format((user, _) => $"{user.FirstName} {user.LastName}")