1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

F #5422: Minor fix on slider component (#1956)

This commit is contained in:
Sergio Betanzos 2022-04-19 15:04:46 +02:00 committed by Ruben S. Montero
parent 3d5f29821e
commit 8fd3e9671e
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
4 changed files with 24 additions and 10 deletions

View File

@ -82,7 +82,13 @@ const AutocompleteController = memo(
InputProps={{ readOnly }}
error={Boolean(error)}
helperText={
Boolean(error) && <ErrorHelper label={error?.message} />
Boolean(error) && (
<ErrorHelper
label={
Array.isArray(error) ? error[0]?.message : error?.message
}
/>
)
}
FormHelperTextProps={{ 'data-cy': `${cy}-error` }}
{...inputParams}

View File

@ -33,6 +33,8 @@ const SliderController = memo(
fieldProps = {},
readOnly = false,
}) => {
const { min, max, step } = fieldProps ?? {}
const {
field: { value, onChange, ...inputProps },
fieldState: { error },
@ -68,14 +70,14 @@ const SliderController = memo(
inputProps={{
'data-cy': inputId,
'aria-labelledby': sliderId,
...fieldProps,
min,
max,
step,
}}
onChange={(evt) =>
onChange(!evt.target.value ? '0' : Number(evt.target.value))
}
onBlur={() => {
const { min, max } = fieldProps ?? {}
if (min && value < min) {
onChange(min)
} else if (max && value > max) {

View File

@ -173,13 +173,14 @@ const modificationOptionsInput = (fieldName, { type, options: optionsId }) => ({
.when(`$general.${type}`, {
is: (modificationType) => modificationType === list,
then: (schema) => schema.required().min(1),
otherwise: (schema) => schema.nullable(),
otherwise: (schema) => schema.notRequired().nullable(),
})
.default(() => {
const capacityUserInput = context.extra?.USER_INPUTS?.[fieldName]
const { options = [] } = getUserInputParams(capacityUserInput)
const numberOpts = options?.filter((opt) => opt !== ' ' && !isNaN(+opt))
return options
return numberOpts
})
),
fieldProps: { freeSolo: true },

View File

@ -21,7 +21,9 @@ import {
prettyBytes,
isDivisibleBy,
} from 'client/utils'
import { T, HYPERVISORS, VmTemplate } from 'client/constants'
import { T, HYPERVISORS, USER_INPUT_TYPES, VmTemplate } from 'client/constants'
const { number, numberFloat } = USER_INPUT_TYPES
const TRANSLATES = {
MEMORY: { name: 'MEMORY', label: T.Memory, tooltip: T.MemoryConcept },
@ -45,9 +47,9 @@ export const FIELDS = (vmTemplate) => {
} = vmTemplate?.TEMPLATE || {}
const {
MEMORY: memoryInput = `M|number|||${MEMORY}`,
CPU: cpuInput = `M|number-float|||${CPU}`,
VCPU: vcpuInput = `O|number|||${VCPU}`,
MEMORY: memoryInput = `M|${number}|| |${MEMORY}`,
CPU: cpuInput = `M|${numberFloat}|| |${CPU}`,
VCPU: vcpuInput = `O|${number}|| |${VCPU}`,
} = USER_INPUTS
return [
@ -59,6 +61,9 @@ export const FIELDS = (vmTemplate) => {
const isVCenter = HYPERVISOR === HYPERVISORS.vcenter
const divisibleBy4 = isVCenter && isMemory
// set default type to number
userInput.type ??= name === 'CPU' ? numberFloat : number
const ensuredOptions = divisibleBy4
? options?.filter((value) => isDivisibleBy(+value, 4))
: options