fix(ui): parse slider value correctly [EE-6225] (#10484)

pull/10631/head
Chaim Lev-Ari 2023-11-14 13:17:25 +02:00 committed by GitHub
parent 99b39da03d
commit 95d96e1164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -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);
}

View File

@ -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`}
/>

View File

@ -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'}
</FormError>
<FormControl
className="flex flex-row"