From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 2B4EE1FF142 for ; Mon, 02 Mar 2026 14:29:22 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 87C64325FD; Mon, 2 Mar 2026 14:29:47 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH manager v3 03/18] ui: form: add filtered KVComboBox Date: Mon, 2 Mar 2026 14:20:51 +0100 Message-ID: <20260302132913.3169037-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260302132913.3169037-1-d.csapak@proxmox.com> References: <20260302132913.3169037-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -1.030 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.012 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 1.188 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.93 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: H6MCJT2HCLLWZXSW2ZL6G6FRNHWDMRU7 X-Message-ID-Hash: H6MCJT2HCLLWZXSW2ZL6G6FRNHWDMRU7 X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: this makes it easier to have the same KVComboBox, but for different configurations, depending on a single 'category' value. This is useful for having the same KVComboBox in different categories, such as the cpu architecture, for e.g. the scsi hw or bios selector, which need different values for different architectures. Instead of implementing the logic for each KVComboBox, abstract it away, so we can reuse the code and have consistent behavior here. Signed-off-by: Dominik Csapak --- www/manager6/Makefile | 1 + www/manager6/form/FilteredKVComboBox.js | 67 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 www/manager6/form/FilteredKVComboBox.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index 944dd873..8857045c 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -17,6 +17,7 @@ JSSRC= \ data/ResourceStore.js \ data/model/RRDModels.js \ container/TwoColumnContainer.js \ + form/FilteredKVComboBox.js \ form/ACMEAPISelector.js \ form/ACMEAccountSelector.js \ form/ACMEPluginSelector.js \ diff --git a/www/manager6/form/FilteredKVComboBox.js b/www/manager6/form/FilteredKVComboBox.js new file mode 100644 index 00000000..035e80a8 --- /dev/null +++ b/www/manager6/form/FilteredKVComboBox.js @@ -0,0 +1,67 @@ +Ext.define('PVE.form.FilteredKVComboBox', { + extend: 'Proxmox.form.KVComboBox', + alias: ['widget.pveFilteredKVComboBox'], + + // same as in the KVComboBox + comboItems: undefined, + + // contains the allowed keys per category, e.g. + // { + // category1: ['foo', 'bar'], + // category2: ['foo'],' + // } + // + // to have an effect, the listed values must exist in the comboItems list + allowedValuesPerCategory: {}, + + // the current category. If not set, the store is not filtered. + category: undefined, + + // If set, will be used to update the display value of the '__default__' value + // that is usually set in a KVComboBox. + // + // gets the current category (if any) as parameter) + setDefaultDisplay: undefined, + + setCategory: function (category) { + let me = this; + me.category = category; + me.filterByCategory(category); + }, + + filterByCategory: function (category) { + let me = this; + let wasValid = me.isValid(); + me.store.clearFilter(); + + let allowedKeys = me.allowedValuesPerCategory[category]; + if (allowedKeys) { + me.store.addFilter((rec) => allowedKeys.indexOf(rec.data.key) !== -1); + } + + let isValid = me.isValid(); + // update default value with new arch + if (Ext.isFunction(me.setDefaultDisplay)) { + let record = me.store.findRecord('key', '__default__'); + if (record) { + record.set('value', me.setDefaultDisplay(category)); + record.commit(); + } + } + + // for some reason, adding/changing filters does not trigger this, even though + // it show the field as invalid, so simply track and fire the event manually. + if (wasValid !== isValid) { + me.fireEvent('validitychange', me, isValid); + } + }, + + initComponent: function () { + var me = this; + + me.callParent(); + + // initial filtering + me.setCategory(me.category); + }, +}); -- 2.47.3