[pve-devel] [PATCH manager] fix #3451 ui: ceph create osd: show custom device classes

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jan 24 16:39:06 CET 2022


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);
>     }
> },






More information about the pve-devel mailing list