Made search suggestions togglable

This commit is contained in:
2025-07-05 15:19:35 +02:00
parent 66d03513eb
commit c5388fc044
5 changed files with 26 additions and 27 deletions

View File

@@ -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<TModel>(TableConfig config) {
InnerConfig.Ignored = ignore;
return this;
}
/// <summary>
/// Determines if search suggestions should be displayed in the ui (Advanced Search)
/// </summary>
public TableConfigurator<TModel> ShowSearchSuggestions(bool show = true) {
InnerConfig.ShowSearchSuggestions = show;
return this;
}
/// <summary>
/// Configures the property of the table

View File

@@ -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();
}

View File

@@ -7,8 +7,6 @@ namespace HopFrame.Web.Services.Implementation;
public sealed class SearchSuggestionProvider : ISearchSuggestionProvider {
public IEnumerable<string> 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];