public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Aaron Lauterer <a.lauterer@proxmox.com>
Subject: Re: [pve-devel] [PATCH manager 3/3] ui: ceph pool edit: rework with controller and formulas
Date: Wed, 8 Mar 2023 13:15:00 +0100	[thread overview]
Message-ID: <972c7e4f-d881-32cb-eaec-89d66408a74f@proxmox.com> (raw)
In-Reply-To: <20230113150930.857270-4-a.lauterer@proxmox.com>

some (minor) comments inline

On 1/13/23 16:09, Aaron Lauterer wrote:
> instead of relying purely on listeners that then manually change other
> components, we can use binds, formulas and a basic controller.
> 
> This makes it quite a bit easier to let multiple components react to
> changes.
> 
> A cbind is used for the size component to set the initial start value.
> Other options, like using setValue in the controller init, will trigger
> the change listener and therefore can affect the min size without any
> user interaction.
> 
> Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
> ---
>   www/manager6/ceph/Pool.js | 87 ++++++++++++++++++++++++++++-----------
>   1 file changed, 63 insertions(+), 24 deletions(-)
> 
> diff --git a/www/manager6/ceph/Pool.js b/www/manager6/ceph/Pool.js
> index 86f83ffb..a38c5b3f 100644
> --- a/www/manager6/ceph/Pool.js
> +++ b/www/manager6/ceph/Pool.js
> @@ -7,6 +7,49 @@ Ext.define('PVE.CephPoolInputPanel', {
>       onlineHelp: 'pve_ceph_pools',
>   
>       subject: 'Ceph Pool',
> +
> +    viewModel: {

typically we have the viewmodel between the controller
and the layout, but no big issue
(though we're probably not 100% consistent on that)

> +	data: {
> +	    minSize: null,
> +	    size: null,
> +	},
> +	formulas: {
> +	    minSizeLabel: (get) => {
> +		if (get('showMinSizeOneWarning') || get('showMinSizeHalfWarning')) {
> +		    return `${gettext('Min. Size')} <i class="fa fa-exclamation-triangle warning"></i>`;
> +		}
> +		return gettext('Min. Size');
> +	    },
> +	    showMinSizeOneWarning: (get) => get('minSize') === 1,
> +	    showMinSizeHalfWarning: (get) => {
> +		let minSize = get('minSize');
> +		let size = get('size');
> +		if (minSize === 1) {
> +		    return false;
> +		}
> +		return minSize < (size / 2) && minSize !== size;
> +	    },

mhmm... i generally don't want to have negated variable names,
but since we bind that to the 'hidden' property (negated)

would it maybe make sense to reverse the logic in here and rename them
to 'hide*Warning' ?

not sure about that though

> +	},
> +    },
> +
> +    controller: {
> +	xclass: 'Ext.app.ViewController',
> +
> +	init: function(view) {
> +	    let vm = this.getViewModel();
> +	    vm.set('size', view.defaultSize ? Number(view.defaultSize) : 3);
> +	    vm.set('minSize', view.defaultMinSize ? Number(view.defaultMinSize) : 2);
> +	},
> +	sizeChange: function(field, val) {
> +	    let vm = this.getViewModel();
> +	    let minSize = Math.round(val / 2);
> +	    if (minSize > 1) {
> +		vm.set('minSize', minSize);
> +	    }
> +	    vm.set('size', val); // bind does not work in a pmxDisplayEditField, update manually
> +	},
> +    },
> +
>       column1: [
>   	{
>   	    xtype: 'pmxDisplayEditField',
> @@ -34,12 +77,7 @@ Ext.define('PVE.CephPoolInputPanel', {
>   		maxValue: 7,
>   		allowBlank: false,
>   		listeners: {
> -		    change: function(field, val) {
> -			let size = Math.round(val / 2);
> -			if (size > 1) {
> -			    field.up('inputpanel').down('field[name=min_size]').setValue(size);
> -			}
> -		    },
> +		    change: 'sizeChange',
>   		},
>   	    },
>   	},
> @@ -77,10 +115,13 @@ Ext.define('PVE.CephPoolInputPanel', {
>       advancedColumn1: [
>   	{
>   	    xtype: 'proxmoxintegerfield',
> -	    fieldLabel: gettext('Min. Size'),
> +	    bind: {
> +		fieldLabel: '{minSizeLabel}',
> +		value: '{minSize}',
> +	    },
>   	    name: 'min_size',
> +	    reference: 'min_size',

it seems you don't actually use the reference, maybe a leftover?

>   	    cbind: {
> -		value: (get) => get('defaultMinSize') ?? 2,
>   		minValue: (get) => {
>   		    if (Number(get('defaultMinSize')) === 1) {
>   			return 1;
> @@ -91,28 +132,26 @@ Ext.define('PVE.CephPoolInputPanel', {
>   	    },
>   	    maxValue: 7,
>   	    allowBlank: false,
> -	    listeners: {
> -		change: function(field, minSize) {
> -		    let panel = field.up('inputpanel');
> -		    let size = panel.down('field[name=size]').getValue();
> -
> -		    let showWarning = minSize < (size / 2) && minSize !== size;
> -
> -		    let fieldLabel = gettext('Min. Size');
> -		    if (showWarning) {
> -			fieldLabel = gettext('Min. Size') + ' <i class="fa fa-exclamation-triangle warning"></i>';
> -		    }
> -		    panel.down('field[name=min_size-warning]').setHidden(!showWarning);
> -		    field.setFieldLabel(fieldLabel);
> -		},
> -	    },
>   	},
>   	{
>   	    xtype: 'displayfield',
> -	    name: 'min_size-warning',
> +	    name: 'min_size_half-warning',

a field that's not set/read does not really need a name,
so we can simply omit that

> +	    bind: {
> +		hidden: '{!showMinSizeHalfWarning}',
> +	    },
> +	    hidden: true,
>   	    userCls: 'pmx-hint',
>   	    value: gettext('min_size < size/2 can lead to data loss, incomplete PGs or unfound objects.'),
> +	},
> +	{
> +	    xtype: 'displayfield',
> +	    name: 'min_size_one-warning',

same here

> +	    bind: {
> +		hidden: '{!showMinSizeOneWarning}',
> +	    },
>   	    hidden: true,
> +	    userCls: 'pmx-hint',
> +	    value: gettext('a min_size of 1 is not recommended and can lead to data loss'),
>   	},
>   	{
>   	    xtype: 'pmxDisplayEditField',




      reply	other threads:[~2023-03-08 12:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 15:09 [pve-devel] [PATCH manager 0/3] fix 2515 use default sizes for new ceph Aaron Lauterer
2023-01-13 15:09 ` [pve-devel] [PATCH manager 1/3] api: ceph: add endpoint to fetch config keys Aaron Lauterer
2023-03-08 12:14   ` Dominik Csapak
2023-03-11 17:07     ` Thomas Lamprecht
2023-03-13 12:58       ` Aaron Lauterer
2023-03-13 16:31         ` Thomas Lamprecht
2023-01-13 15:09 ` [pve-devel] [PATCH manager 2/3] fix #2515: ui: ceph pool create: use configured defaults for size and min_size Aaron Lauterer
2023-03-08 12:14   ` Dominik Csapak
2023-01-13 15:09 ` [pve-devel] [PATCH manager 3/3] ui: ceph pool edit: rework with controller and formulas Aaron Lauterer
2023-03-08 12:15   ` Dominik Csapak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=972c7e4f-d881-32cb-eaec-89d66408a74f@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=a.lauterer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal