From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id B512A1FF15E
	for <inbox@lore.proxmox.com>; Fri, 26 Jul 2024 15:43:02 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id D3CC21EE8C;
	Fri, 26 Jul 2024 15:43:02 +0200 (CEST)
Mime-Version: 1.0
Date: Fri, 26 Jul 2024 15:42:29 +0200
Message-Id: <D2ZIJ6YJHEH1.XZQUFY7Z493@proxmox.com>
From: "Shannon Sterz" <s.sterz@proxmox.com>
To: "Theodor Fumics" <theodor.fumics@gmx.net>, <pve-devel@lists.proxmox.com>
X-Mailer: aerc 0.17.0-69-g65571b67d7d3-dirty
References: <20240726132745.168971-1-theodor.fumics@gmx.net>
In-Reply-To: <20240726132745.168971-1-theodor.fumics@gmx.net>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.048 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
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH manager] sdn: subnets: hide irrelevant
 fields depending on zone type
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

On Fri Jul 26, 2024 at 3:27 PM CEST, Theodor Fumics wrote:
> The SNAT option is only applicable to Simple and EVPN zone types.
> For other zone types, this field is irrelevant and can cause confusion.
> This commit hides the SNAT field when it is not applicable to the
> selected zone type, improving clarity for users.
>
> Signed-off-by: Theodor Fumics <theodor.fumics@gmx.net>
> ---
>  www/manager6/sdn/SubnetEdit.js | 18 ++++++++++++++++++
>  www/manager6/sdn/SubnetView.js | 16 ++++++++++++++++
>  www/manager6/sdn/VnetView.js   |  9 +++++++++
>  3 files changed, 43 insertions(+)
>
> diff --git a/www/manager6/sdn/SubnetEdit.js b/www/manager6/sdn/SubnetEdit.js
> index 8fc3f52b..d80eeca2 100644
> --- a/www/manager6/sdn/SubnetEdit.js
> +++ b/www/manager6/sdn/SubnetEdit.js
> @@ -2,6 +2,8 @@ Ext.define('PVE.sdn.SubnetInputPanel', {
>      extend: 'Proxmox.panel.InputPanel',
>      mixins: ['Proxmox.Mixin.CBind'],
>
> +    zoneInfo: undefined,
> +
>      onGetValues: function(values) {
>  	let me = this;
>
> @@ -38,6 +40,7 @@ Ext.define('PVE.sdn.SubnetInputPanel', {
>  	},
>  	{
>  	    xtype: 'proxmoxcheckbox',
> +	    itemId: 'snatSubnetCheckbox',
>  	    name: 'snat',
>  	    uncheckedValue: null,
>  	    checked: false,
> @@ -57,6 +60,18 @@ Ext.define('PVE.sdn.SubnetInputPanel', {
>  	    },
>  	},
>      ],
> +
> +    initComponent: function() {
> +	let me = this;
> +	me.callParent();
> +
> +	let zoneType = me.zoneInfo?.type;
> +
> +	var showSNATCheckbox = ['simple', 'evpn'].includes(zoneType);
> +
> +	var snatCheckbox = me.down('#snatSubnetCheckbox');
> +	snatCheckbox.setHidden(!showSNATCheckbox);

hey thanks for your contribution, any reason you are using `var` instead
of `let` here? our style guide says all new code should use `let` or
`const` and i can't determine a reason why you'd need a `var` here.
generally the behaviour of a `var` is also less predictable in regards
to hoisting etc.

> +    },
>  });
>
>  Ext.define('PVE.sdn.SubnetDhcpRangePanel', {
> @@ -243,6 +258,8 @@ Ext.define('PVE.sdn.SubnetEdit', {
>
>      base_url: undefined,
>
> +    zoneInfo: undefined,
> +
>      bodyPadding: 0,
>
>      initComponent: function() {
> @@ -261,6 +278,7 @@ Ext.define('PVE.sdn.SubnetEdit', {
>  	let ipanel = Ext.create('PVE.sdn.SubnetInputPanel', {
>  	    isCreate: me.isCreate,
>  	    title: gettext('General'),
> +	    zoneInfo: me.zoneInfo,
>  	});
>
>  	let dhcpPanel = Ext.create('PVE.sdn.SubnetDhcpRangePanel', {
> diff --git a/www/manager6/sdn/SubnetView.js b/www/manager6/sdn/SubnetView.js
> index d342f0ba..fd103d78 100644
> --- a/www/manager6/sdn/SubnetView.js
> +++ b/www/manager6/sdn/SubnetView.js
> @@ -7,6 +7,9 @@ Ext.define('PVE.sdn.SubnetView', {
>
>      base_url: undefined,
>
> +    zoneName: undefined,
> +    zoneInfo: undefined,
> +
>      remove_btn: undefined,
>
>      setBaseUrl: function(url) {
> @@ -28,6 +31,18 @@ Ext.define('PVE.sdn.SubnetView', {
>  	}
>      },
>
> +    loadZone: function(name) {
> +	let me = this;
> +
> +	Proxmox.Utils.API2Request({
> +	    url: `/cluster/sdn/zones/${name}?pending=1`,
> +	    method: 'GET',
> +	    success: function(response) {
> +		me.zoneInfo = response?.result?.data;
> +	    },
> +	});
> +    },
> +
>      initComponent: function() {
>  	let me = this;
>
> @@ -59,6 +74,7 @@ Ext.define('PVE.sdn.SubnetView', {
>  		let win = Ext.create('PVE.sdn.SubnetEdit', {
>  		    autoShow: true,
>  		    base_url: me.base_url,
> +		    zoneInfo: me.zoneInfo,
>  		    type: 'subnet',
>  		});
>  		win.on('destroy', reload);
> diff --git a/www/manager6/sdn/VnetView.js b/www/manager6/sdn/VnetView.js
> index 3fd3c916..9c9dcc5b 100644
> --- a/www/manager6/sdn/VnetView.js
> +++ b/www/manager6/sdn/VnetView.js
> @@ -141,6 +141,15 @@ Ext.define('PVE.sdn.VnetView', {
>  		select: function(_sm, rec) {
>  		    let url = `/cluster/sdn/vnets/${rec.data.vnet}/subnets`;
>  		    me.subnetview_panel.setBaseUrl(url);
> +
> +		    let zoneName;
> +		    if (rec.data.pending) {
> +			zoneName = rec.data.pending.zone;
> +		    } else {
> +			zoneName = rec.data.zone;
> +		    }
> +
> +		    me.subnetview_panel.loadZone(zoneName);
>  		},
>  		deselect: function() {
>  		    me.subnetview_panel.setBaseUrl(undefined);
> --
> 2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel