From 191a1fcef0f318a39b157fb43b416d2532bc7c4a Mon Sep 17 00:00:00 2001 From: Damien LEROY Date: Tue, 9 May 2023 10:23:01 +0200 Subject: [PATCH] Fixing issues with topic selection autocomplete --- Pages/Tester.razor | 2 +- Pages/Tester.razor.cs | 25 ++++++++++++++++++++--- Service/KafkaTesterService.cs | 4 ++-- wwwroot/css/autocomplete/autocomplete.css | 2 ++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Pages/Tester.razor b/Pages/Tester.razor index d6e5de8..97c354e 100644 --- a/Pages/Tester.razor +++ b/Pages/Tester.razor @@ -37,7 +37,7 @@
- + @if (_filteredTopics is not null) {
    diff --git a/Pages/Tester.razor.cs b/Pages/Tester.razor.cs index 7e431a0..e14c67e 100644 --- a/Pages/Tester.razor.cs +++ b/Pages/Tester.razor.cs @@ -180,14 +180,33 @@ private void OnSelectSetting(ChangeEventArgs e) async Task OnTypeTopic(ChangeEventArgs e) { - var filter = e.Value?.ToString(); + if (e != null) + { + _setting.Topic = e.Value.ToString(); + } + + var filter = _setting.Topic; + await JsRuntime.InvokeVoidAsync("console.log", filter); await LoadTopics(null); - _filteredTopics = _topics.Where(t => t.Contains(filter ?? string.Empty)).ToList(); + _filteredTopics = _topics?.Where(t => t.Contains(filter ?? string.Empty)).ToList(); + + if (_filteredTopics?.Count == 1 && filter.Equals(_filteredTopics.First(), StringComparison.InvariantCultureIgnoreCase)) + _filteredTopics = null; + } + + async Task OnLostTopicFocus(FocusEventArgs e) + { + await Task.Delay(200).ContinueWith(t => _filteredTopics = null); + } + + async Task OnGetTopicFocus(FocusEventArgs e) + { + await OnTypeTopic(null); } private async Task LoadTopics(MouseEventArgs e) { - if (_topics != null || _isTopicLoading) + if (_topics != null || _isTopicLoading || string.IsNullOrWhiteSpace(_setting.Brokers)) return; _isTopicLoading = true; diff --git a/Service/KafkaTesterService.cs b/Service/KafkaTesterService.cs index b0d5594..2e8e8b7 100644 --- a/Service/KafkaTesterService.cs +++ b/Service/KafkaTesterService.cs @@ -85,8 +85,8 @@ public async Task> GetTopicsAsync(string servers) } catch (Exception e) { - Console.WriteLine(e); - return new List(); + _logger.LogError($"Error occured: {e.Message}"); + return null; } } diff --git a/wwwroot/css/autocomplete/autocomplete.css b/wwwroot/css/autocomplete/autocomplete.css index 3d9737c..4934c08 100644 --- a/wwwroot/css/autocomplete/autocomplete.css +++ b/wwwroot/css/autocomplete/autocomplete.css @@ -13,6 +13,8 @@ border: 1px solid #ced4da; border-radius: 0.5rem; box-shadow: 0 30px 25px 8px rgba(0, 0, 0, 0.1); + max-height: 500px; + overflow: auto; } .autocomplete .option {