saurabhkushwaha438 commented on code in PR #14413:
URL: https://github.com/apache/cloudstack/pull/14413#discussion_r4548304243


##########
ui/src/views/compute/wizard/ComputeSelection.vue:
##########
@@ -224,40 +303,95 @@ export default {
       if (this.preFillContent.cpuspeed) {
         this.cpuSpeedInputValue = this.preFillContent.cpuspeed
       }
-      if (this.preFillContent.memory) {
-        this.memoryInputValue = this.preFillContent.memory
-      }
+
       this.updateComputeCpuNumber(this.preFillContent.cpunumber || 
this.cpuNumberInputValue)
       this.updateComputeCpuSpeed(this.preFillContent.cpuspeed || 
this.cpuSpeedInputValue)
-      this.updateComputeMemory(this.preFillContent.memory || 
this.memoryInputValue)
+      // Emit exact prefilled MiB without any conversion on load
+      this.$emit('update-compute-memory', this.memoryInputDecorator, 
this.memoryInputValue)
+    },
+    handleUnitChange (newUnit) {
+      if (newUnit === 'GiB') {
+        const currentMiB = this.memoryUnit === 'MiB' ? this.memoryDisplayValue 
: this.memoryInputValue
+        if (!this.isGiBAllowed || (currentMiB > 0 && currentMiB % 256 !== 0)) {
+          this.memoryUnit = 'MiB'
+          this.$nextTick(() => {
+            this.memoryUnit = 'MiB'
+          })
+          message.warning(
+            this.$t('message.memory.gib.not.supported') ||
+            'GiB unit is not available because memory limits or values must be 
multiples of 256 MiB (0.25 GiB). Please use MiB.'
+          )
+          return
+        }
+      }
+
+      if (newUnit === 'MiB') {
+        this.memoryDisplayValue = (this.memoryInputValue !== undefined && 
this.memoryInputValue !== null)
+          ? this.memoryInputValue
+          : (this.memoryDisplayValue ? Math.round(this.memoryDisplayValue * 
1024) : undefined)
+      } else {
+        this.memoryDisplayValue = (this.memoryInputValue !== undefined && 
this.memoryInputValue !== null)
+          ? this.memoryInputValue / 1024
+          : (this.memoryDisplayValue ? this.memoryDisplayValue : undefined)
+      }
+      if (this.isConstrained) {
+        if (this.memoryDisplayValue < this.minMemoryInUnit) {
+          this.memoryDisplayValue = this.minMemoryInUnit
+        } else if (this.maxMemoryInUnit > 0 && this.memoryDisplayValue > 
this.maxMemoryInUnit) {
+          this.memoryDisplayValue = this.maxMemoryInUnit
+        }
+      }
+      this.updateComputeMemory(this.memoryDisplayValue)
     },
     updateComputeCpuNumber (value) {
-      if (!value) this.cpuNumberInputValue = 0
+      this.cpuNumberInputValue = value
       if (!this.validateInput('cpu', value)) {
+        this.$emit('update-compute-cpunumber', this.cpuNumberInputDecorator, 
undefined)
         return
       }
       this.$emit('update-compute-cpunumber', this.cpuNumberInputDecorator, 
value)
     },
     updateComputeCpuSpeed (value) {
       this.$emit('update-compute-cpuspeed', this.cpuSpeedInputDecorator, value)
     },
-    updateComputeMemory (value) {
-      if (!value) this.memoryInputValue = 0
-      if (!this.validateInput('memory', value)) {
+    updateComputeMemory (displayValue) {
+      this.memoryDisplayValue = displayValue
+      if (!this.validateInput('memory', displayValue)) {
+        this.memoryInputValue = undefined
+        this.$emit('update-compute-memory', this.memoryInputDecorator, 
undefined)
         return
       }
-      this.$emit('update-compute-memory', this.memoryInputDecorator, value)
+      let memoryInMiB
+      if (this.memoryUnit === 'GiB') {
+        memoryInMiB = Math.round(displayValue * 1024)
+      } else {
+        memoryInMiB = Math.round(displayValue)
+      }
+

Review Comment:
   our new 0.25 GiB step (representing 256 MiB), every single step multiplied 
by 1024 is already an exact integer and in our design, since GiB is only 
enabled when limits are multiples of 256 MiB, 1.0 GiB×1024 already equals 1024



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to