all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Aaron Lauterer <a.lauterer@proxmox.com>
Subject: Re: [pve-devel] [PATCH manager] fix #3451 ui: ceph create osd: show custom device classes
Date: Mon, 24 Jan 2022 16:39:06 +0100	[thread overview]
Message-ID: <8e3db760-b373-fb75-f091-4be9ec9940c5@proxmox.com> (raw)
In-Reply-To: <cc4c1169-0e1d-0298-30a4-a4445e587482@proxmox.com>

On 24.01.22 16:32, Thomas Lamprecht wrote:
> On 21.01.22 15:51, Aaron Lauterer wrote:
>> +	    success: function(response, opts) {
>> +		let data = response.result.data;
>> +
>> +		let classes = new Set();
>> +		for (const match of data.matchAll(/^device\s[0-9]*\sosd\.[0-9]*\sclass\s(.*)$/gim)) {
>> +		    classes.add(match[1]);
>> +		}
>> +		for (const v of ['hdd', 'ssd', 'nvme']) {
>> +		    classes.delete(v);
>> +		}
>> +		for (const v of classes) {
>> +		    deviceClasses.push([v, v]);
>> +		}
>> +		me.down('field[name=crush-device-class]').setComboItems(deviceClasses);
> 
> Something like the following would be a bit more concise while also only changing
> the field if required, I did not test this at all besides verifying that eslint
> eats it though ^^
> 
> success: function({ result: { data } }) {
>     let classes = data.matchAll(/^device\s[0-9]*\sosd\.[0-9]*\sclass\s(.*)$/gim)
>         .filter(v => !['hdd', 'ssd', 'nvme'].includes(v))
>         .map(v => [v, v]);

Oh, forget to filter repeated clases here, so that would actually be something along
the lines of:

let classes = [...new Set(
    data.matchAll(/^device\s[0-9]*\sosd\.[0-9]*\sclass\s(.*)$/gim)
        .filter(v => !['hdd', 'ssd', 'nvme'].includes(v))
)].map(v => [v, v]);

> 
>     if (classes.length) {
>         let kvField = me.down('field[name=crush-device-class]').setComboItems(classes);
>         classes.unshift(kvField.comboItems);
> 
>         kvField.setComboItems(classes);
>     }
> },





      reply	other threads:[~2022-01-24 15:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 14:51 Aaron Lauterer
2022-01-24 15:32 ` Thomas Lamprecht
2022-01-24 15:39   ` Thomas Lamprecht [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=8e3db760-b373-fb75-f091-4be9ec9940c5@proxmox.com \
    --to=t.lamprecht@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 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