diff --git a/app/kubernetes/helpers/resourceReservationHelper.js b/app/kubernetes/helpers/resourceReservationHelper.js index 2ed667595..1179a178c 100644 --- a/app/kubernetes/helpers/resourceReservationHelper.js +++ b/app/kubernetes/helpers/resourceReservationHelper.js @@ -11,7 +11,7 @@ class KubernetesResourceReservationHelper { (acc, container) => { if (container.Requests) { if (container.Requests.memory) { - acc.Memory += filesizeParser(container.Requests.memory, { base: 10 }); + acc.Memory += safeFilesizeParser(container.Requests.memory, { base: 10 }); } if (container.Requests.cpu) { @@ -36,11 +36,19 @@ class KubernetesResourceReservationHelper { } static megaBytesValue(value) { - return Math.floor(filesizeParser(value) / 1000 / 1000); + return Math.floor(safeFilesizeParser(value) / 1000 / 1000); } static bytesValue(mem) { - return filesizeParser(mem) * 1000 * 1000; + return safeFilesizeParser(mem) * 1000 * 1000; } } export default KubernetesResourceReservationHelper; + +function safeFilesizeParser(value, options) { + if (!value || Number.isNaN(value)) { + return 0; + } + + return filesizeParser(value, options); +} diff --git a/app/react/components/form-components/Slider/SliderWithInput.tsx b/app/react/components/form-components/Slider/SliderWithInput.tsx index 1be81ee77..b40d22d32 100644 --- a/app/react/components/form-components/Slider/SliderWithInput.tsx +++ b/app/react/components/form-components/Slider/SliderWithInput.tsx @@ -39,7 +39,9 @@ export function SliderWithInput({ min="0" max={max} value={value} - onChange={(e) => onChange(e.target.valueAsNumber)} + onChange={({ target: { valueAsNumber: value } }) => + onChange(Number.isNaN(value) ? 0 : value) + } className="w-32" data-cy={`${dataCy}Input`} /> diff --git a/app/react/kubernetes/namespaces/components/ResourceQuotaFormSection/ResourceQuotaFormSection.tsx b/app/react/kubernetes/namespaces/components/ResourceQuotaFormSection/ResourceQuotaFormSection.tsx index 9015aa923..dcf1c0600 100644 --- a/app/react/kubernetes/namespaces/components/ResourceQuotaFormSection/ResourceQuotaFormSection.tsx +++ b/app/react/kubernetes/namespaces/components/ResourceQuotaFormSection/ResourceQuotaFormSection.tsx @@ -62,7 +62,7 @@ export function ResourceQuotaFormSection({ className={typeof errors === 'string' ? 'visible' : 'invisible'} > {/* 'error' keeps the formerror the exact same height while hidden so there is no layout shift */} - {errors || 'error'} + {typeof errors === 'string' ? errors : 'error'}