From 556e3513da54e80215f15badb9a1ddb25cdf5759 Mon Sep 17 00:00:00 2001 From: Jorge Miguel Lobo Escalona Date: Thu, 5 Oct 2023 11:06:48 +0200 Subject: [PATCH] B #6337: Add decimals when resize capacity (#2770) --- .../client/components/Cards/VirtualMachineCard.js | 2 +- .../src/client/components/Tabs/Vm/Info/capacity.js | 2 +- src/fireedge/src/client/utils/helpers.js | 6 ++++-- src/sunstone/public/app/utils/user-inputs.js | 13 +++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/fireedge/src/client/components/Cards/VirtualMachineCard.js b/src/fireedge/src/client/components/Cards/VirtualMachineCard.js index 53c33a97e8..d0e3b4c341 100644 --- a/src/fireedge/src/client/components/Cards/VirtualMachineCard.js +++ b/src/fireedge/src/client/components/Cards/VirtualMachineCard.js @@ -121,7 +121,7 @@ const VirtualMachineCard = memo( const error = useMemo(() => getErrorMessage(vm), [vm]) const ips = useMemo(() => getIps(vm), [vm]) - const memValue = useMemo(() => prettyBytes(+MEMORY, 'MB'), [MEMORY]) + const memValue = useMemo(() => prettyBytes(+MEMORY, 'MB', 2), [MEMORY]) const labels = useMemo( () => diff --git a/src/fireedge/src/client/components/Tabs/Vm/Info/capacity.js b/src/fireedge/src/client/components/Tabs/Vm/Info/capacity.js index 94417debf9..58e6c3d947 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Info/capacity.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Info/capacity.js @@ -80,7 +80,7 @@ const CapacityPanel = ({ vm = {}, actions, oneConfig, adminGroup }) => { { icon: , name: T.Memory, - value: prettyBytes(+MEMORY, 'MB'), + value: prettyBytes(+MEMORY, 'MB', 2), dataCy: 'memory', }, ![CORES, SOCKETS].includes(undefined) && { diff --git a/src/fireedge/src/client/utils/helpers.js b/src/fireedge/src/client/utils/helpers.js index b8bf3b3e01..3a9bf3bf99 100644 --- a/src/fireedge/src/client/utils/helpers.js +++ b/src/fireedge/src/client/utils/helpers.js @@ -133,12 +133,14 @@ export const prettyBytes = (value, unit = UNITS.KB, fractionDigits = 0) => { let idxUnit = units.indexOf(unit) - while (ensuredValue > 1024) { + while (ensuredValue >= 1024) { ensuredValue /= 1024 idxUnit += 1 } - return `${ensuredValue.toFixed(fractionDigits)} ${units[idxUnit]}` + const decimals = fractionDigits && ensuredValue % 1 !== 0 ? fractionDigits : 0 + + return `${ensuredValue.toFixed(decimals)} ${units[idxUnit]}` } /** diff --git a/src/sunstone/public/app/utils/user-inputs.js b/src/sunstone/public/app/utils/user-inputs.js index 651dcd4914..9398e19486 100644 --- a/src/sunstone/public/app/utils/user-inputs.js +++ b/src/sunstone/public/app/utils/user-inputs.js @@ -737,6 +737,9 @@ define(function(require) { $("div.mb_input", context).on("change", "input.visor, select", function(e){ var element = $(this); + var step = '1' + var baseCal = 1; + var unit = "MB"; var min = parseInt(element.attr("data-min"),10); var max = parseInt(element.attr("data-max"),10); var value = element.val(); @@ -745,26 +748,24 @@ define(function(require) { switch (mb_input_unit_val) { case "TB": baseCal = base*base; + step = '0.001' unit = "TB"; break; case "GB": baseCal = base; + step = '0.01' unit = "GB"; break; - default: - baseCal = 1; - unit = "MB"; - break; } if (value >= 0) { valueInMB = value * baseCal; if(!isNaN(min) && parseInt(min, 10) > valueInMB ){ valueInMB = min; } - $("input, select", contextElement).val(valueInMB); + $("input, select", contextElement).val(Math.ceil(valueInMB)); valueInUnit = valueInMB / baseCal; } - $("input.visor", contextElement).val(valueInUnit); + $("input.visor", contextElement).attr('step', step).val(valueInUnit); var contextUnit = contextElement.siblings(".input-group-button"); $(".mb_input_unit", contextUnit).val(unit); });