[pve-devel] [PATCH widget-toolkit] StatusView: fix usage calculation for fields without valid values

Dominik Csapak d.csapak at proxmox.com
Fri Mar 11 10:52:46 CET 2022


On 3/11/22 10:13, Matthias Heiserer wrote:
> On 10.03.2022 15:31, Dominik Csapak wrote:
>> Sometimes, total can be zero (e.g. for swap when it's not used), which
>> leads to the usage being NaN. This led to the progressbar not being
>> updated for InfoWidgets, leaving a spurious '0%' as text.
>>
>> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
>> ---
>>   src/panel/StatusView.js | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/panel/StatusView.js b/src/panel/StatusView.js
>> index 4a60dae..e2e81e2 100644
>> --- a/src/panel/StatusView.js
>> +++ b/src/panel/StatusView.js
>> @@ -47,7 +47,7 @@ Ext.define('Proxmox.panel.StatusView', {
>>            */
>>           if (used.used !== undefined &&
>>           used.total !== undefined) {
>> -        return used.used/used.total;
>> +        return used.total > 0 ? used.used/used.total : 0;
>>           }
>>       }
> 
> When used.used or used.total is undefined, the function still returns NaN. Have you considered using 
> the or operator?

that can't happen because of the 'if' check:

'used.used !== undefined && used.total !== undefined'





More information about the pve-devel mailing list