- @if (_topics.Any())
+ @if (_topics is not null)
{
-
+ @if(_topics.Count > 0)
+ {
+
+ }
+ else
+ {
+
No topics found
+ }
+
}
else
{
diff --git a/Pages/Tester.razor.cs b/Pages/Tester.razor.cs
index c0a3536..7e431a0 100644
--- a/Pages/Tester.razor.cs
+++ b/Pages/Tester.razor.cs
@@ -11,6 +11,7 @@
using Microsoft.JSInterop;
using KafkaTester.Service;
using Microsoft.AspNetCore.Components.Web;
+using static System.Net.WebRequestMethods;
namespace KafkaTester.Pages
{
@@ -39,7 +40,8 @@ public partial class Tester
private string _exportConfigurationString;
private string _importConfigurationString;
private readonly List
_errors = new();
- private List _topics = new();
+ private List _topics;
+ private List _filteredTopics;
private bool _isTopicLoading = false;
protected override async Task OnAfterRenderAsync(bool isFirstRender)
@@ -176,9 +178,18 @@ private void OnSelectSetting(ChangeEventArgs e)
_setting = setting;
}
+ async Task OnTypeTopic(ChangeEventArgs e)
+ {
+ var filter = e.Value?.ToString();
+ await LoadTopics(null);
+ _filteredTopics = _topics.Where(t => t.Contains(filter ?? string.Empty)).ToList();
+ }
+
private async Task LoadTopics(MouseEventArgs e)
{
- _topics.Clear();
+ if (_topics != null || _isTopicLoading)
+ return;
+
_isTopicLoading = true;
var topics = await TesterService.GetTopicsAsync(_setting.Brokers);
_topics = topics;
@@ -190,6 +201,7 @@ private async Task SelectionTopic(string topic)
{
_setting.Topic = topic;
StateHasChanged();
+ _filteredTopics = null;
await JsRuntime.InvokeVoidAsync("closeTopicSelectionModal");
}
diff --git a/Pages/_Host.cshtml b/Pages/_Host.cshtml
index f0aa5e0..c3f857c 100644
--- a/Pages/_Host.cshtml
+++ b/Pages/_Host.cshtml
@@ -15,6 +15,7 @@
+
diff --git a/wwwroot/css/autocomplete/autocomplete.css b/wwwroot/css/autocomplete/autocomplete.css
new file mode 100644
index 0000000..3d9737c
--- /dev/null
+++ b/wwwroot/css/autocomplete/autocomplete.css
@@ -0,0 +1,41 @@
+.autocomplete {
+ position: relative;
+}
+
+ .autocomplete .options {
+ position: absolute;
+ top: 40px;
+ left: 0;
+ background: white;
+ width: 100%;
+ padding: 0;
+ z-index: 10;
+ border: 1px solid #ced4da;
+ border-radius: 0.5rem;
+ box-shadow: 0 30px 25px 8px rgba(0, 0, 0, 0.1);
+ }
+
+ .autocomplete .option {
+ display: block;
+ padding: 0.25rem;
+ cursor: pointer;
+ }
+
+ .autocomplete .option .option-text {
+ padding: 0.25rem 0.5rem;
+ }
+
+ .autocomplete .option:hover {
+ background: #1E90FF;
+ color: #fff;
+ }
+
+ .autocomplete .option.disabled {
+ background-color: lightgrey;
+ cursor: not-allowed;
+ }
+
+ .autocomplete .option.disabled:hover {
+ background: lightgrey;
+ color: var(--bs-body);
+ }
diff --git a/wwwroot/js/autocomplete/autocomplete.js b/wwwroot/js/autocomplete/autocomplete.js
new file mode 100644
index 0000000..b534584
--- /dev/null
+++ b/wwwroot/js/autocomplete/autocomplete.js
@@ -0,0 +1 @@
+!function (u) { var n = { treshold: 4, maximumItems: 5, highlightTyped: !0, highlightClass: "text-primary" }; function p(e, t, o) { var a; if (o.highlightTyped) { var n = t.label.toLowerCase().indexOf(e.toLowerCase()); a = t.label.substring(0, n) + '' + t.label.substring(n, n + e.length) + "" + t.label.substring(n + e.length, t.label.length) } else a = t.label; return '" } function l(e, t) { var o = e.val(); if (o.length < t.treshold) return e.dropdown("hide"), 0; var a = e.next(); a.html(""); for (var n = 0, l = Object.keys(t.source), r = 0; r < l.length; r++) { var d = l[r], s = t.source[d], i = { label: t.label ? s[t.label] : d, value: t.value ? s[t.value] : s }; if (0 <= i.label.toLowerCase().indexOf(o.toLowerCase()) && (a.append(p(o, i, t)), 0 < t.maximumItems && ++n >= t.maximumItems)) break } return e.next().find(".dropdown-item").click(function () { e.val(u(this).text()), t.onSelectItem && t.onSelectItem({ value: u(this).data("value"), label: u(this).text() }, e[0]) }), a.children().length } u.fn.autocomplete = function (e) { var t = {}; u.extend(t, n, e); var o = u(this); o.parent().removeClass("dropdown"), o.removeAttr("data-toggle"), o.removeClass("dropdown-toggle"), o.parent().find(".dropdown-menu").remove(), o.dropdown("dispose"), o.parent().addClass("dropdown"), o.attr("data-toggle", "dropdown"), o.addClass("dropdown-toggle"); var a = u(''); return t.dropdownClass && a.addClass(t.dropdownClass), o.after(a), o.dropdown(t.dropdownOptions), this.off("click.autocomplete").click("click.autocomplete", function (e) { 0 == l(o, t) && (e.stopPropagation(), o.dropdown("hide")) }), this.off("keyup.autocomplete").keyup("keyup.autocomplete", function () { 0 < l(o, t) ? o.dropdown("show") : o.click() }), this } }(jQuery);
\ No newline at end of file