From f02074a25ee74eba3a31be3ff21e99ee5647fe12 Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Mon, 3 Mar 2025 16:50:43 +0800 Subject: [PATCH] Extract variables to utils/unit Signed-off-by: Andy Lee (cherry picked from commit 8db4de1c4a1200f4f303e4444b6435c581187d72) --- pkg/harvester/config/harvester-map.js | 1 + .../detail/harvesterhci.io.host/HarvesterHostBasic.vue | 3 ++- pkg/harvester/dialog/HarvesterQuotaDialog.vue | 5 +++-- pkg/harvester/edit/harvesterhci.io.host/index.vue | 6 +++--- pkg/harvester/edit/harvesterhci.io.volume.vue | 6 ++++-- .../VirtualMachineCpuMemory.vue | 6 ++++-- .../VirtualMachineReserved.vue | 6 +++--- .../VirtualMachineVolume/type/existing.vue | 4 +++- .../VirtualMachineVolume/type/vmImage.vue | 8 +++++--- .../VirtualMachineVolume/type/volume.vue | 6 ++++-- pkg/harvester/formatters/HarvesterMemoryUsed.vue | 4 ++-- pkg/harvester/formatters/HarvesterStorageUsed.vue | 5 +++-- pkg/harvester/list/harvesterhci.io.dashboard.vue | 5 +++-- pkg/harvester/mixins/harvester-vm/index.js | 7 ++++--- .../models/harvesterhci.io.virtualmachineimage.js | 9 +++++---- pkg/harvester/utils/unit.js | 3 +++ pkg/harvester/validators/vm.js | 3 ++- pkg/harvester/validators/volume.js | 4 +++- 18 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 pkg/harvester/utils/unit.js diff --git a/pkg/harvester/config/harvester-map.js b/pkg/harvester/config/harvester-map.js index 796ad222..75f2b5ad 100644 --- a/pkg/harvester/config/harvester-map.js +++ b/pkg/harvester/config/harvester-map.js @@ -1,3 +1,4 @@ +// TODO: delete this not used variable export const MemoryUnit = [{ label: 'Mi', value: 'Mi' diff --git a/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue b/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue index 55876ce6..8ff3d5b5 100644 --- a/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue +++ b/pkg/harvester/detail/harvesterhci.io.host/HarvesterHostBasic.vue @@ -4,6 +4,7 @@ import { formatSi, exponentNeeded, UNITS } from '@shell/utils/units'; import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations'; import { LONGHORN, METRIC } from '@shell/config/types'; import { Banner } from '@components/Banner'; +import { UNIT_SUFFIX } from '../../utils/unit'; import HarvesterCPUUsed from '../../formatters/HarvesterCPUUsed'; import HarvesterMemoryUsed from '../../formatters/HarvesterMemoryUsed'; import HarvesterStorageUsed from '../../formatters/HarvesterStorageUsed'; @@ -121,7 +122,7 @@ export default { memoryUnits() { const exponent = exponentNeeded(this.memoryTotal, 1024); - return `${ UNITS[exponent] }i`; + return `${ UNITS[exponent] }${ UNIT_SUFFIX }`; }, nodeType() { diff --git a/pkg/harvester/dialog/HarvesterQuotaDialog.vue b/pkg/harvester/dialog/HarvesterQuotaDialog.vue index 92da1e76..3129951b 100644 --- a/pkg/harvester/dialog/HarvesterQuotaDialog.vue +++ b/pkg/harvester/dialog/HarvesterQuotaDialog.vue @@ -5,6 +5,7 @@ import { Banner } from '@components/Banner'; import AsyncButton from '@shell/components/AsyncButton'; import UnitInput from '@shell/components/form/UnitInput'; import { exceptionToErrorsArray } from '@shell/utils/error'; +import { GIBIBYTE } from '../utils/unit'; export default { name: 'HarvesterVMQuotaDialog', @@ -29,6 +30,7 @@ export default { data() { return { + GIBIBYTE, totalSnapshotSize: '', errors: [] }; @@ -44,7 +46,6 @@ export default { }, methods: { - close() { this.totalSnapshotSize = ''; this.$emit('close'); @@ -92,7 +93,7 @@ export default { :input-exponent="3" :increment="1024" :output-modifier="true" - suffix="Gi" + :suffix="GIBIBYTE" class="mb-20" /> diff --git a/pkg/harvester/edit/harvesterhci.io.host/index.vue b/pkg/harvester/edit/harvesterhci.io.host/index.vue index 55832e48..6f65c402 100644 --- a/pkg/harvester/edit/harvesterhci.io.host/index.vue +++ b/pkg/harvester/edit/harvesterhci.io.host/index.vue @@ -20,7 +20,7 @@ import Loading from '@shell/components/Loading.vue'; import MessageLink from '@shell/components/MessageLink'; import { ADD_ONS } from '@pkg/harvester/config/harvester-map'; import { PRODUCT_NAME as HARVESTER_PRODUCT } from '@pkg/harvester/config/harvester'; - +import { UNIT_SUFFIX } from '../../utils/unit'; import { _EDIT } from '@shell/config/query-params'; import { sortBy } from '@shell/utils/sort'; import { Banner } from '@components/Banner'; @@ -185,7 +185,7 @@ export default { minExponent: 3, maxExponent: 3, maxPrecision: 2, - suffix: 'i', + suffix: UNIT_SUFFIX, }; const longhornDisks = Object.keys(diskStatus).map((key) => { @@ -457,7 +457,7 @@ export default { const devPath = d.spec?.devPath; const deviceType = d.status?.deviceStatus?.details?.deviceType; const sizeBytes = d.status?.deviceStatus?.capacity?.sizeBytes; - const size = formatSi(sizeBytes, { increment: 1024, suffix: 'i' }); + const size = formatSi(sizeBytes, { increment: 1024, suffix: UNIT_SUFFIX }); const parentDevice = d.status?.deviceStatus?.parentDevice; const isChildAdded = this.newDisks.find((newDisk) => newDisk.blockDevice?.status?.deviceStatus?.parentDevice === devPath); const name = d.displayName; diff --git a/pkg/harvester/edit/harvesterhci.io.volume.vue b/pkg/harvester/edit/harvesterhci.io.volume.vue index 5c8dc514..f9e36d84 100644 --- a/pkg/harvester/edit/harvesterhci.io.volume.vue +++ b/pkg/harvester/edit/harvesterhci.io.volume.vue @@ -21,6 +21,7 @@ import { InterfaceOption, VOLUME_DATA_SOURCE_KIND } from '../config/harvester-ma import { HCI, VOLUME_SNAPSHOT } from '../types'; import { LVM_DRIVER } from '../models/harvester/storage.k8s.io.storageclass'; import { DATA_ENGINE_V2 } from '../models/harvester/persistentvolumeclaim'; +import { GIBIBYTE } from '../utils/unit'; export default { name: 'HarvesterVolume', @@ -86,6 +87,7 @@ export default { imageId, snapshots: [], images: [], + GIBIBYTE }; }, @@ -288,7 +290,7 @@ export default { const imageSize = Math.max(imageResource?.status?.size, imageResource?.status?.virtualSize); if (imageSize) { - this.storage = `${ Math.ceil(imageSize / 1024 / 1024 / 1024) }Gi`; + this.storage = `${ Math.ceil(imageSize / 1024 / 1024 / 1024) }${ GIBIBYTE }`; } } this.update(); @@ -377,7 +379,7 @@ export default { :disabled="value?.isLonghornV2 && isEdit" required class="mb-20" - suffix="Gi" + :suffix="GIBIBYTE" @update:value="update" /> diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineCpuMemory.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineCpuMemory.vue index 54b71d9f..b71333aa 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineCpuMemory.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineCpuMemory.vue @@ -1,6 +1,7 @@