mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-04 21:26:08 +08:00
Add Dashboard page
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { formatSi, parseSi } from '@shell/utils/units';
|
||||
|
||||
export function dataVolumeSize(storage, getters, errors, validatorArgs) {
|
||||
const t = getters['i18n/t'];
|
||||
|
||||
if (!storage || storage === '') {
|
||||
const key = t('harvester.volume.size');
|
||||
|
||||
errors.push(t('validation.required', { key }));
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
const size = getSize(storage);
|
||||
const max = 999999;
|
||||
const integerRegex = /^[1-9]\d*$/;
|
||||
|
||||
if (!integerRegex.test(size) || size > max) {
|
||||
errors.push(t('harvester.validation.volume.sizeRange'));
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
function getSize(storage) {
|
||||
if (!storage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const kibUnitSize = parseSi(storage);
|
||||
|
||||
return formatSi(kibUnitSize, {
|
||||
addSuffix: false,
|
||||
increment: 1024,
|
||||
minExponent: 3,
|
||||
maxExponent: 3
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user