From c4e131164d8a88045781dc3ec346adcaccae01ae Mon Sep 17 00:00:00 2001 From: Sergio Betanzos Date: Tue, 30 Nov 2021 15:58:18 +0100 Subject: [PATCH] F #5637: Fix minor in proptypes & cypress atributes (#1623) --- .../ExtraConfiguration/booting/bootOrder.js | 8 - .../Steps/ExtraConfiguration/booting/index.js | 4 +- .../context/configurationSection.js | 6 +- .../context/filesSection.js | 2 +- .../context/userInputsSection.js | 2 +- .../Steps/ExtraConfiguration/index.js | 4 +- .../ExtraConfiguration/inputOutput/index.js | 2 +- .../inputOutput/inputsSection.js | 2 +- .../inputOutput/pciDevicesSection.js | 2 +- .../ExtraConfiguration/networking/NicItem.js | 115 ++++++------ .../ExtraConfiguration/networking/index.js | 2 +- .../Steps/ExtraConfiguration/numa/index.js | 4 +- .../ExtraConfiguration/placement/index.js | 2 +- .../Steps/ExtraConfiguration/schema.js | 41 ++-- .../ExtraConfiguration/storage/DiskItem.js | 177 +++++++++--------- .../Steps/ExtraConfiguration/storage/index.js | 2 +- .../CreateForm/Steps/General/index.js | 4 +- 17 files changed, 186 insertions(+), 193 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/bootOrder.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/bootOrder.js index 4f74d8e7be..279f5f32a2 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/bootOrder.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/bootOrder.js @@ -14,7 +14,6 @@ * limitations under the License. * * ------------------------------------------------------------------------- */ import { useMemo, useState, JSXElementConstructor } from 'react' -import PropTypes from 'prop-types' import { useFormContext } from 'react-hook-form' import { NetworkAlt as NetworkIcon, BoxIso as ImageIcon } from 'iconoir-react' @@ -224,13 +223,6 @@ const BootOrder = () => { ) } -BootOrder.propTypes = { - data: PropTypes.any, - setFormData: PropTypes.func, - hypervisor: PropTypes.string, - control: PropTypes.object, -} - BootOrder.displayName = 'BootOrder' export default BootOrder diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/index.js index f330f1bec2..41456ad378 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/index.js @@ -53,14 +53,14 @@ const Booting = ({ hypervisor, ...props }) => { sx={{ width: '100%', gridColumn: '1 / -1' }} > - + )} {sections.map(({ id, ...section }) => ( ))} diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/configurationSection.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/configurationSection.js index 09009e8e7b..d74b3472d3 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/configurationSection.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/configurationSection.js @@ -51,13 +51,13 @@ const ConfigurationSection = () => { sx={{ gridTemplateColumns: { sm: '1fr', md: '1fr 1fr' } }} >
@@ -71,7 +71,7 @@ const ConfigurationSection = () => {
( FILES_FIELDS(hypervisor)} id={EXTRA_ID} diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSection.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSection.js index daa7f7a815..7a0b8ddb38 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSection.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSection.js @@ -157,7 +157,7 @@ const UserInputsSection = () => { onSubmit={methods.handleSubmit(onSubmit)} > diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/index.js index 49aabb2c7e..6deda3e3b1 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/index.js @@ -21,7 +21,7 @@ import PropTypes from 'prop-types' import { useFormContext, FieldErrors } from 'react-hook-form' import { useAuth } from 'client/features/Auth' -import { Tr, Translate } from 'client/components/HOC' +import { Translate } from 'client/components/HOC' import Tabs from 'client/components/Tabs' import Storage from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage' @@ -96,7 +96,7 @@ const Content = ({ data, setFormData }) => { [totalErrors, view, control] ) - return tabs.length > 0 ? : {Tr(T.Empty)} + return } const ExtraConfiguration = () => ({ diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/index.js index 4af53014de..940a434604 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/index.js @@ -42,7 +42,7 @@ const InputOutput = ({ hypervisor }) => { sx={{ gridTemplateColumns: { sm: '1fr', md: '1fr 1fr' } }} > { onSubmit={methods.handleSubmit(onSubmit)} > diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSection.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSection.js index eb48cd2bae..e7bdec359a 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSection.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSection.js @@ -79,7 +79,7 @@ const PciDevicesSection = ({ fields }) => { onSubmit={methods.handleSubmit(onSubmit)} > diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/NicItem.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/NicItem.js index 9e668333a9..26b8e4f507 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/NicItem.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/NicItem.js @@ -33,67 +33,64 @@ import { T } from 'client/constants' * @param {string} props.handleUpdate - Update function * @returns {JSXElementConstructor} - NIC card */ -const NicItem = memo( - ({ item, nics, handleRemove, handleUpdate }) => { - const { id, NAME, RDP, SSH, NETWORK, PARENT, EXTERNAL } = item - const hasAlias = nics?.some((nic) => nic.PARENT === NAME) +const NicItem = memo(({ item, nics, handleRemove, handleUpdate }) => { + const { id, NAME, RDP, SSH, NETWORK, PARENT, EXTERNAL } = item + const hasAlias = nics?.some((nic) => nic.PARENT === NAME) - return ( - - {Object.entries({ - RDP: stringToBoolean(RDP), - SSH: stringToBoolean(SSH), - EXTERNAL: stringToBoolean(EXTERNAL), - [`PARENT: ${PARENT}`]: PARENT, - }) - .map(([k, v]) => (v ? `${k}` : '')) - .filter(Boolean) - .join(' | ')} - - } - action={ - <> - {!hasAlias && ( - } - handleClick={handleRemove} - color="error" - icon={} - /> - )} - , - tooltip: , - }} - options={[ - { - dialogProps: { - title: ( - - ), - }, - form: () => AttachNicForm({ nics }, item), - onSubmit: handleUpdate, - }, - ]} + return ( + + {Object.entries({ + RDP: stringToBoolean(RDP), + SSH: stringToBoolean(SSH), + EXTERNAL: stringToBoolean(EXTERNAL), + [`PARENT: ${PARENT}`]: PARENT, + }) + .map(([k, v]) => (v ? `${k}` : '')) + .filter(Boolean) + .join(' | ')} + + } + action={ + <> + {!hasAlias && ( + } + handleClick={handleRemove} + color="error" + icon={} /> - - } - /> - ) - }, - (prev, next) => prev.item?.NAME === next.item?.NAME -) + )} + , + tooltip: , + }} + options={[ + { + dialogProps: { + title: ( + + ), + }, + form: () => AttachNicForm({ nics }, item), + onSubmit: handleUpdate, + }, + ]} + /> + + } + /> + ) +}) NicItem.propTypes = { index: PropTypes.number, diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/index.js index 85fb139527..0fb38befca 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/index.js @@ -109,7 +109,7 @@ const Networking = () => { ))} { return ( <> diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement/index.js index 6aef468595..c0329d89ed 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement/index.js @@ -41,7 +41,7 @@ const Placement = () => { ))} diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/schema.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/schema.js index 5272564df5..1686506b5e 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/schema.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/schema.js @@ -13,18 +13,24 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -/* eslint-disable jsdoc/require-jsdoc */ -import { array, object } from 'yup' +import { array, object, ObjectSchema } from 'yup' -import { FIELDS as PLACEMENT_FIELDS } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement/schema' -import { FIELDS as OS_FIELDS } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/booting/schema' -import { FIELDS as NUMA_FIELDS } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/numa/schema' -import { SCHEMA as IO_SCHEMA } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/schema' -import { SCHEMA as CONTEXT_SCHEMA } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/schema' -import { SCHEMA as STORAGE_SCHEMA } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/schema' -import { SCHEMA as NETWORK_SCHEMA } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/networking/schema' +import { HYPERVISORS } from 'client/constants' import { getObjectSchemaFromFields } from 'client/utils' +import { FIELDS as PLACEMENT_FIELDS } from './placement/schema' +import { FIELDS as OS_FIELDS } from './booting/schema' +import { FIELDS as NUMA_FIELDS } from './numa/schema' +import { SCHEMA as IO_SCHEMA } from './inputOutput/schema' +import { SCHEMA as CONTEXT_SCHEMA } from './context/schema' +import { SCHEMA as STORAGE_SCHEMA } from './storage/schema' +import { SCHEMA as NETWORK_SCHEMA } from './networking/schema' +/** + * Map name attribute if not exists. + * + * @param {string} prefixName - Prefix to add in name + * @returns {object[]} Resource object + */ export const mapNameByIndex = (prefixName) => (resource, idx) => ({ ...resource, NAME: @@ -33,14 +39,19 @@ export const mapNameByIndex = (prefixName) => (resource, idx) => ({ : resource?.NAME, }) -export const SCHED_ACTION_SCHEMA = array() - .ensure() - .transform((actions) => actions.map(mapNameByIndex('SCHED_ACTION'))) +export const SCHED_ACTION_SCHEMA = object({ + SCHED_ACTION: array() + .ensure() + .transform((actions) => actions.map(mapNameByIndex('SCHED_ACTION'))), +}) +/** + * @param {HYPERVISORS} hypervisor - VM hypervisor + * @returns {ObjectSchema} Extra configuration schema + */ export const SCHEMA = (hypervisor) => - object({ - SCHED_ACTION: SCHED_ACTION_SCHEMA, - }) + object() + .concat(SCHED_ACTION_SCHEMA) .concat(NETWORK_SCHEMA) .concat(STORAGE_SCHEMA) .concat(CONTEXT_SCHEMA(hypervisor)) diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/DiskItem.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/DiskItem.js index 65498f8aec..7034503f26 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/DiskItem.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/DiskItem.js @@ -21,7 +21,7 @@ import { Edit, Trash } from 'iconoir-react' import ButtonToTriggerForm from 'client/components/Forms/ButtonToTriggerForm' import SelectCard, { Action } from 'client/components/Cards/SelectCard' import { ImageSteps, VolatileSteps } from 'client/components/Forms/Vm' -import { StatusCircle, StatusChip } from 'client/components/Status' +import { StatusCircle } from 'client/components/Status' import { Translate } from 'client/components/HOC' import { getState, getDiskType } from 'client/models/Image' @@ -40,102 +40,95 @@ import { T } from 'client/constants' * @param {string} props.handleUpdate - Update function * @returns {JSXElementConstructor} - Disk card */ -const DiskItem = memo( - ({ item, hypervisor, handleRemove, handleUpdate }) => { - const { - NAME, - TYPE, - IMAGE, - IMAGE_ID, - IMAGE_STATE, - ORIGINAL_SIZE, - SIZE = ORIGINAL_SIZE, - READONLY, - DATASTORE, - PERSISTENT, - } = item +const DiskItem = memo(({ item, hypervisor, handleRemove, handleUpdate }) => { + const { + NAME, + TYPE, + IMAGE, + IMAGE_ID, + IMAGE_STATE, + ORIGINAL_SIZE, + SIZE = ORIGINAL_SIZE, + READONLY, + DATASTORE, + PERSISTENT, + } = item - const isVolatile = !IMAGE && !IMAGE_ID - const isPersistent = stringToBoolean(PERSISTENT) - const state = !isVolatile && getState({ STATE: IMAGE_STATE }) - const type = isVolatile ? TYPE : getDiskType(item) - const originalSize = +ORIGINAL_SIZE - ? prettyBytes(+ORIGINAL_SIZE, 'MB') - : '-' - const size = prettyBytes(+SIZE, 'MB') + const isVolatile = !IMAGE && !IMAGE_ID + const state = !isVolatile && getState({ STATE: IMAGE_STATE }) + const type = isVolatile ? TYPE : getDiskType(item) + const originalSize = +ORIGINAL_SIZE ? prettyBytes(+ORIGINAL_SIZE, 'MB') : '-' + const size = prettyBytes(+SIZE, 'MB') - return ( - - {`${NAME} - `} - - - ) : ( - - - {`${NAME}: ${IMAGE}`} - {isPersistent && } - - ) - } - subheader={ + return ( + - {Object.entries({ - [DATASTORE]: DATASTORE, - READONLY: stringToBoolean(READONLY), - PERSISTENT: stringToBoolean(PERSISTENT), - [isVolatile || ORIGINAL_SIZE === SIZE - ? size - : `${originalSize}/${size}`]: true, - [type]: type, - }) - .map(([k, v]) => (v ? `${k}` : '')) - .filter(Boolean) - .join(' | ')} + {`${NAME} - `} + - } - action={ - <> - } - handleClick={handleRemove} - color="error" - icon={} - /> - , - tooltip: , - }} - options={[ - { - dialogProps: { - title: , - }, - form: () => - isVolatile - ? VolatileSteps({ hypervisor }, item) - : ImageSteps({ hypervisor }, item), - onSubmit: handleUpdate, + ) : ( + + + {`${NAME}: ${IMAGE}`} + + ) + } + subheader={ + <> + {Object.entries({ + [DATASTORE]: DATASTORE, + READONLY: stringToBoolean(READONLY), + PERSISTENT: stringToBoolean(PERSISTENT), + [isVolatile || ORIGINAL_SIZE === SIZE + ? size + : `${originalSize}/${size}`]: true, + [type]: type, + }) + .map(([k, v]) => (v ? `${k}` : '')) + .filter(Boolean) + .join(' | ')} + + } + action={ + <> + } + handleClick={handleRemove} + color="error" + icon={} + /> + , + tooltip: , + }} + options={[ + { + dialogProps: { + title: , }, - ]} - /> - - } - /> - ) - }, - (prev, next) => prev.item?.NAME === next.item?.NAME -) + form: () => + isVolatile + ? VolatileSteps({ hypervisor }, item) + : ImageSteps({ hypervisor }, item), + onSubmit: handleUpdate, + }, + ]} + /> + + } + /> + ) +}) DiskItem.propTypes = { index: PropTypes.number, diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/index.js index 1440418c5f..289a9760e4 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/storage/index.js @@ -117,7 +117,7 @@ const Storage = ({ hypervisor }) => { ))} { return (
{ key={id} id={STEP_ID} className={classes[id]} - cy={`create-vm-template-${STEP_ID}.${id}`} + cy={`${STEP_ID}.${id}`} {...section} /> ))}