Extract variables to utils/unit

Signed-off-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
Andy Lee
2025-03-03 16:57:25 +08:00
parent 8f76d5ad30
commit 8db4de1c4a
18 changed files with 57 additions and 34 deletions
@@ -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;
@@ -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"
/>
@@ -1,6 +1,7 @@
<script>
import UnitInput from '@shell/components/form/UnitInput';
import InputOrDisplay from '@shell/components/InputOrDisplay';
import { GIBIBYTE } from '../../utils/unit';
export default {
name: 'HarvesterEditCpuMemory',
@@ -30,6 +31,7 @@ export default {
data() {
return {
GIBIBYTE,
localCpu: this.cpu,
localMemory: this.memory
};
@@ -63,7 +65,7 @@ export default {
if (String(this.localMemory).includes('Gi')) {
memory = this.localMemory;
} else {
memory = `${ this.localMemory }Gi`;
memory = `${ this.localMemory }${ GIBIBYTE }`;
}
if (memory.includes('null')) {
memory = null;
@@ -113,7 +115,7 @@ export default {
:output-modifier="true"
:disabled="disabled"
required
suffix="Gi"
:suffix="GIBIBYTE"
class="mb-20"
@update:value="change"
/>
@@ -1,6 +1,6 @@
<script>
import UnitInput from '@shell/components/form/UnitInput';
import { MEBIBYTE } from '../../utils/unit';
export default {
name: 'HarvesterReserved',
@@ -20,7 +20,7 @@ export default {
},
data() {
return { memory: this.reservedMemory };
return { MEBIBYTE, memory: this.reservedMemory };
},
watch: {
@@ -47,7 +47,7 @@ export default {
:input-exponent="2"
:increment="1024"
:output-modifier="true"
suffix="Mi"
:suffix="MEBIBYTE"
@update:value="change"
/>
</template>
@@ -11,6 +11,7 @@ import { _CREATE } from '@shell/config/query-params';
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
import { HCI } from '../../../../types';
import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
import { GIBIBYTE } from '../../../../utils/unit';
export default {
name: 'HarvesterEditExisting',
@@ -59,6 +60,7 @@ export default {
}
return {
GIBIBYTE,
VOLUME_TYPE,
InterfaceOption,
loading: false,
@@ -254,7 +256,7 @@ export default {
:label="t('harvester.fields.size')"
:mode="mode"
:disabled="true"
suffix="Gi"
:suffix="GIBIBYTE"
@update:value="update"
/>
</InputOrDisplay>
@@ -12,6 +12,7 @@ import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
import { _VIEW } from '@shell/config/query-params';
import LabelValue from '@shell/components/LabelValue';
import { ucFirst } from '@shell/utils/string';
import { GIBIBYTE } from '../../../../utils/unit';
export default {
name: 'HarvesterEditVMImage',
@@ -67,6 +68,7 @@ export default {
data() {
return {
GIBIBYTE,
VOLUME_TYPE,
InterfaceOption,
loading: false,
@@ -187,7 +189,7 @@ export default {
minExponent: 3,
});
this.value.size = `${ formatSize }Gi`;
this.value.size = `${ formatSize }${ GIBIBYTE }`;
}
},
deep: true,
@@ -229,7 +231,7 @@ export default {
if (!isIsoImage) {
imageSizeGiB = Math.max(imageSizeGiB, 10);
}
this.value['size'] = `${ imageSizeGiB }Gi`;
this.value['size'] = `${ imageSizeGiB }${ GIBIBYTE }`;
}
this.update();
@@ -336,7 +338,7 @@ export default {
:mode="mode"
:required="validateRequired"
:disable="isLonghornV2"
suffix="Gi"
:suffix="GIBIBYTE"
@update:value="update"
/>
</InputOrDisplay>
@@ -12,6 +12,7 @@ import LabelValue from '@shell/components/LabelValue';
import { ucFirst } from '@shell/utils/string';
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: 'HarvesterEditVolume',
@@ -58,6 +59,7 @@ export default {
data() {
return {
GIBIBYTE,
VOLUME_TYPE,
InterfaceOption,
loading: false,
@@ -140,7 +142,7 @@ export default {
minExponent: 3,
});
this.value.size = `${ formatSize }Gi`;
this.value.size = `${ formatSize }${ GIBIBYTE }`;
}
},
deep: true,
@@ -258,7 +260,7 @@ export default {
:required="validateRequired"
:label="t('harvester.fields.size')"
:disabled="isLonghornV2"
suffix="Gi"
:suffix="GIBIBYTE"
@update:value="update"
/>
</InputOrDisplay>