all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH manager] ui: bridge selector: add search field to the drop-down list
@ 2026-11-27 10:00 Krasimir Rangelov
  0 siblings, 0 replies; only message in thread
From: Krasimir Rangelov @ 2026-11-27 10:00 UTC (permalink / raw)
  To: pve-devel; +Cc: Krasimir Rangelov

On nodes with many bridges or SDN VNets, finding the right one in the
network device edit window means scrolling through the whole list.

Add a search field on top of the bridge list, similar to the one in the
storage add wizard. It filters the list to the entries that contain all
entered words in their name, type or comment, so one can also search
for e.g. a VLAN or a description noted in the comment.

The search field gets the focus when the list opens. The arrow keys move
the highlight through the matches without changing the value, ENTER
selects the highlighted entry and ESC clears the search or closes the
list. The search is reset whenever the list closes.

As the list normally only closes when the focus leaves the field, and a
click on the mask of the modal edit window focuses its first field
again, also close the list on any click outside of it.

This affects the network device edit windows of VMs and containers, as
well as the guest import wizard.

Signed-off-by: Krasimir Rangelov <krasiaa123@gmail.com>
---
 www/manager6/form/BridgeSelector.js | 144 ++++++++++++++++++++++++++++
 1 file changed, 144 insertions(+)

diff --git a/www/manager6/form/BridgeSelector.js b/www/manager6/form/BridgeSelector.js
index b5949018..7e84a0b3 100644
--- a/www/manager6/form/BridgeSelector.js
+++ b/www/manager6/form/BridgeSelector.js
@@ -39,6 +39,150 @@ Ext.define('PVE.form.BridgeSelector', {
         ],
     },
 
+    // filter the list to the entries that contain every word of the search text in their name,
+    // type or comment, and highlight the first match
+    applySearch: function (value) {
+        let me = this;
+        let words = (value ?? '').toLowerCase().split(/\s+/).filter(Boolean);
+        if (words.join(' ') === me.searchText) {
+            return; // keep the highlight, e.g. on ENTER after the buffered change already applied
+        }
+        me.searchText = words.join(' ');
+        if (!words.length) {
+            me.store.removeFilter('bridgeSearch');
+            me.highlightRecord(me.getSelection());
+            return;
+        }
+        let text = (rec) =>
+            [rec.get('iface'), rec.get('type'), rec.get('comments')].join(' ').toLowerCase();
+        me.store.addFilter({
+            id: 'bridgeSearch',
+            filterFn: (rec) => words.every((word) => text(rec).includes(word)),
+        });
+        me.highlightRecord(me.store.first());
+    },
+
+    // mark an entry without selecting it, as selecting would set the value and close the list
+    highlightRecord: function (rec) {
+        let me = this;
+        let picker = me.picker;
+        me.highlighted = rec && me.store.indexOf(rec) !== -1 ? rec : null;
+        if (!me.highlighted) {
+            picker.getView().clearHighlight();
+            return;
+        }
+        picker.ensureVisible(me.highlighted, {
+            callback: (success, record, node) => {
+                if (success && node) {
+                    picker.getView().highlightItem(node);
+                }
+            },
+        });
+    },
+
+    moveHighlight: function (step) {
+        let me = this;
+        let count = me.store.getCount();
+        if (!count) {
+            return;
+        }
+        let index = me.highlighted ? me.store.indexOf(me.highlighted) : -1;
+        index = index === -1 ? 0 : Ext.Number.constrain(index + step, 0, count - 1);
+        me.highlightRecord(me.store.getAt(index));
+    },
+
+    chooseRecord: function (rec) {
+        let me = this;
+        if (rec) {
+            me.picker.getSelectionModel().select(rec);
+        }
+        me.collapse();
+        me.focus();
+    },
+
+    // The combobox marks the current value when the list opens by moving the focus to its row,
+    // which would take the focus away from the search field. Highlight it without focus instead.
+    doAutoSelect: function () {
+        let me = this;
+        if (me.isExpanded) {
+            me.highlightRecord(me.getSelection());
+            me.searchField.focus();
+        }
+    },
+
+    createPicker: function () {
+        let me = this;
+        let picker = me.callParent(arguments);
+
+        me.searchField = Ext.create('Ext.form.field.Text', {
+            flex: 1,
+            emptyText: gettext('Search bridge'),
+            submitValue: false,
+            isFormField: false,
+            listeners: {
+                change: {
+                    buffer: 150,
+                    fn: (field, value) => me.applySearch(value),
+                },
+                specialkey: (field, event) => {
+                    let key = event.getKey();
+                    if (key === event.DOWN || key === event.UP) {
+                        event.stopEvent();
+                        me.moveHighlight(key === event.DOWN ? 1 : -1);
+                    } else if (key === event.ENTER) {
+                        event.stopEvent();
+                        me.applySearch(field.getValue());
+                        if (me.highlighted) {
+                            me.chooseRecord(me.highlighted);
+                        }
+                    } else if (key === event.ESC) {
+                        event.stopEvent();
+                        if (field.getValue()) {
+                            field.setValue('');
+                        } else {
+                            me.chooseRecord();
+                        }
+                    }
+                },
+            },
+        });
+
+        picker.addDocked({
+            xtype: 'toolbar',
+            dock: 'top',
+            items: [me.searchField],
+        });
+
+        // The list normally closes when the focus leaves the field. But a click on the mask of a
+        // modal edit window focuses its first field again, which can be this one, so also close
+        // the list on any click outside of it.
+        me.on({
+            expand: () => {
+                me.outsideClickListener = me.mon(Ext.getDoc(), {
+                    mousedown: me.collapseIf,
+                    scope: me,
+                    delegated: false,
+                    destroyable: true,
+                });
+            },
+            collapse: () => {
+                Ext.destroy(me.outsideClickListener);
+                me.outsideClickListener = null;
+            },
+        });
+
+        picker.on('hide', () => {
+            me.searchField.suspendEvents();
+            me.searchField.setValue('');
+            me.searchField.resumeEvents();
+            me.store.removeFilter('bridgeSearch');
+            me.searchText = '';
+            me.highlighted = null;
+        });
+
+        return picker;
+    },
+
     setNodename: function (nodename) {
         var me = this;
 
-- 
2.51.0




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-27 17:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 10:00 [PATCH manager] ui: bridge selector: add search field to the drop-down list Krasimir Rangelov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal