Skip to content

Commit

Permalink
Fixing issues with topic selection autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien LEROY committed May 9, 2023
1 parent ce8bc9b commit 191a1fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Pages/Tester.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<label for="topic" class="col-2 col-form-label text-right">Topic</label>
<div class="col-10">
<div class="input-group autocomplete">
<input type="text" class="form-control" id="topic" placeholder="topic" @bind="_setting.Topic" @oninput="OnTypeTopic">
<input type="text" class="form-control" id="topic" placeholder="topic" @bind="_setting.Topic" @oninput="OnTypeTopic" @onfocusout="OnLostTopicFocus" @onfocusin="OnGetTopicFocus">
@if (_filteredTopics is not null)
{
<ul class="options">
Expand Down
25 changes: 22 additions & 3 deletions Pages/Tester.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Service/KafkaTesterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public async Task<List<string>> GetTopicsAsync(string servers)
}
catch (Exception e)
{
Console.WriteLine(e);
return new List<string>();
_logger.LogError($"Error occured: {e.Message}");
return null;
}
}

Expand Down
2 changes: 2 additions & 0 deletions wwwroot/css/autocomplete/autocomplete.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 191a1fc

Please sign in to comment.