diff --git a/src/fireedge/.eslintrc b/src/fireedge/.eslintrc index 2d7b7d7e3b..615bbf2607 100644 --- a/src/fireedge/.eslintrc +++ b/src/fireedge/.eslintrc @@ -19,10 +19,24 @@ }, "plugins": ["jsdoc", "react", "header", "prettier"], "rules": { - "prettier/prettier": ["error", { - "singleQuote": true, - "semi": false, - "trailingComma": "es5", + "default-case": "off", + "prefer-const": ["error", { + "destructuring": "all" + }], + "arrow-body-style": ["error", "as-needed"], + "no-restricted-syntax": [ + "error", + "ForInStatement", + "LabeledStatement", + "WithStatement" + ], + "no-return-assign": ["error", "except-parens"], + "no-param-reassign": ["error", { + "props": false + }], + "no-shadow": ["error", { + "hoist": "all", + "allow": ["resolve", "reject", "done", "next", "err", "error", "children"] }], "import/no-extraneous-dependencies": ["error", { "devDependencies": ["*.js"] @@ -34,7 +48,15 @@ }], "react/jsx-uses-react": "off", "react/react-in-jsx-scope": "off", - "default-case": 0, + "react/display-name": "warn", + "react/no-array-index-key": "off", + "react/require-default-props": "off", + "react/forbid-prop-types": "off", + "prettier/prettier": ["error", { + "singleQuote": true, + "semi": false, + "trailingComma": "es5" + }], "jsdoc/require-jsdoc": ["error", { "publicOnly": true, "require": { diff --git a/src/fireedge/src/client/components/Cards/SelectCard/SelectCard.js b/src/fireedge/src/client/components/Cards/SelectCard/SelectCard.js index dbcc882e43..a6567a7a41 100644 --- a/src/fireedge/src/client/components/Cards/SelectCard/SelectCard.js +++ b/src/fireedge/src/client/components/Cards/SelectCard/SelectCard.js @@ -147,8 +147,8 @@ const SelectCard = memo( {/* CARD ACTIONS */} {actions?.length > 0 && ( - {actions?.map((action) => ( - + {actions?.map((actionProps) => ( + ))} )} diff --git a/src/fireedge/src/client/components/Charts/SingleBar.js b/src/fireedge/src/client/components/Charts/SingleBar.js index b3f1c21040..0f199caeb2 100644 --- a/src/fireedge/src/client/components/Charts/SingleBar.js +++ b/src/fireedge/src/client/components/Charts/SingleBar.js @@ -53,7 +53,7 @@ const useStyles = makeStyles((theme) => ({ * @returns {JSXElementConstructor} Chart bar component */ const SingleBar = ({ legend, data, total = 0 }) => { - const fragments = data.map((data) => Math.floor((data * 10) / (total || 1))) + const fragments = data.map((frag) => Math.floor((frag * 10) / (total || 1))) const classes = useStyles({ fragments }) diff --git a/src/fireedge/src/client/components/DebugLog/ansiHtml.js b/src/fireedge/src/client/components/DebugLog/ansiHtml.js index d9c70aaa4c..8b3cc9856a 100644 --- a/src/fireedge/src/client/components/DebugLog/ansiHtml.js +++ b/src/fireedge/src/client/components/DebugLog/ansiHtml.js @@ -120,14 +120,15 @@ ansiHTML.setColors = function (colors) { } const _finalColors = {} - for (const key in _defColors) { + Object.entries(_defColors).forEach(([key, defHexColor]) => { let hex = Object.prototype.hasOwnProperty.call(colors, key) ? colors[key] : null if (!hex) { - _finalColors[key] = _defColors[key] - continue + _finalColors[key] = defHexColor + + return } if (key === 'reset') { @@ -138,17 +139,13 @@ ansiHTML.setColors = function (colors) { if ( !Array.isArray(hex) || hex.length === 0 || - hex.some(function (h) { - return typeof h !== 'string' - }) + hex.some((h) => typeof h !== 'string') ) { throw new Error( `The value of '${key}' property must be an Array and each item could only be a hex string, e.g.: FF0000` ) } - const defHexColor = _defColors[key] - if (!hex[0]) { hex[0] = defHexColor[0] } @@ -166,7 +163,8 @@ ansiHTML.setColors = function (colors) { } _finalColors[key] = hex - } + }) + _setTags(_finalColors) } @@ -208,12 +206,11 @@ const _setTags = (colors) => { // dark grey _openTags[90] = `color:#${colors.darkgrey}` - for (const code in _styles) { - const color = _styles[code] + Object.entries(_styles).forEach(([code, color]) => { const oriColor = colors[color] || '000' _openTags[code] = `color:#${oriColor}` _openTags[(parseInt(code) + 10).toString()] = `background:#${oriColor}` - } + }) } ansiHTML.reset() diff --git a/src/fireedge/src/client/components/FormControl/TimeController-TODO.js b/src/fireedge/src/client/components/FormControl/TimeController-TODO.js index 593f276826..96f1a40b29 100644 --- a/src/fireedge/src/client/components/FormControl/TimeController-TODO.js +++ b/src/fireedge/src/client/components/FormControl/TimeController-TODO.js @@ -27,7 +27,7 @@ const WrapperToLoadLib = ({ children, id, lib }) => { const [loading, setLoading] = useState(true) useEffect(() => { - const loadLib = async (lib) => { + const loadLib = async () => { try { await import(lib) } finally { diff --git a/src/fireedge/src/client/components/FormStepper/index.js b/src/fireedge/src/client/components/FormStepper/index.js index 5a927752a3..c349cff7df 100644 --- a/src/fireedge/src/client/components/FormStepper/index.js +++ b/src/fireedge/src/client/components/FormStepper/index.js @@ -87,19 +87,22 @@ const FormStepper = ({ steps = [], schema, onSubmit }) => { const totalErrors = Object.keys(errorsByPath).length totalErrors > 0 - ? setError(id, { + ? setError(stepId, { type: 'manual', message: [T.ErrorsOcurred, totalErrors], }) - : setError(id, rest) + : setError(stepId, rest) inner?.forEach(({ path, type, errors: message }) => { if (isDevelopment()) { // the package @hookform/devtools requires message as string const [key, ...values] = [message].flat() - setError(`${id}.${path}`, { type, message: sprintf(key, ...values) }) + setError(`${stepId}.${path}`, { + type, + message: sprintf(key, ...values), + }) } else { - setError(`${id}.${path}`, { type, message }) + setError(`${stepId}.${path}`, { type, message }) } }) } @@ -160,7 +163,7 @@ const FormStepper = ({ steps = [], schema, onSubmit }) => { [activeStep] ) - const { id, content: Content } = useMemo( + const { id: stepId, content: Content } = useMemo( () => steps[activeStep], [formData, activeStep] ) @@ -195,10 +198,10 @@ const FormStepper = ({ steps = [], schema, onSubmit }) => { errors={errors} /> ), - [isLoading, isMobile, activeStep, errors[id]] + [isLoading, isMobile, activeStep, errors[stepId]] )} {/* FORM CONTENT */} - {Content && } + {Content && } {isDevelopment() && } diff --git a/src/fireedge/src/client/components/Forms/Legend.js b/src/fireedge/src/client/components/Forms/Legend.js index 19124b42df..e62b83336b 100644 --- a/src/fireedge/src/client/components/Forms/Legend.js +++ b/src/fireedge/src/client/components/Forms/Legend.js @@ -33,14 +33,12 @@ const StyledLegend = styled((props) => ( })) const Legend = memo( - ({ title, tooltip }) => { - return ( - - {labelCanBeTranslated(title) ? Tr(title) : title} - {!!tooltip && } - - ) - }, + ({ title, tooltip }) => ( + + {labelCanBeTranslated(title) ? Tr(title) : title} + {!!tooltip && } + + ), (prev, next) => prev.title === next.title && prev.tooltip === next.tooltip ) diff --git a/src/fireedge/src/client/components/Forms/MarketplaceApp/CreateForm/Steps/index.js b/src/fireedge/src/client/components/Forms/MarketplaceApp/CreateForm/Steps/index.js index d0887ca46a..62d4608eaa 100644 --- a/src/fireedge/src/client/components/Forms/MarketplaceApp/CreateForm/Steps/index.js +++ b/src/fireedge/src/client/components/Forms/MarketplaceApp/CreateForm/Steps/index.js @@ -22,9 +22,8 @@ import MarketplacesTable, { import { createSteps } from 'client/utils' const Steps = createSteps([BasicConfiguration, MarketplacesTable], { - transformInitialValue: (initialValues, schema) => { - return schema.cast({ [BASIC_ID]: initialValues }, { stripUnknown: true }) - }, + transformInitialValue: (initialValues, schema) => + schema.cast({ [BASIC_ID]: initialValues }, { stripUnknown: true }), transformBeforeSubmit: (formData) => { const { [BASIC_ID]: configuration, [MARKET_ID]: [market] = [] } = formData diff --git a/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/BasicConfiguration/index.js b/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/BasicConfiguration/index.js index 2936e022e0..7e42628dde 100644 --- a/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/BasicConfiguration/index.js +++ b/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/BasicConfiguration/index.js @@ -25,15 +25,13 @@ import { T } from 'client/constants' export const STEP_ID = 'configuration' -const Content = ({ isUpdate }) => { - return ( - - ) -} +const Content = ({ isUpdate }) => ( + +) const BasicConfiguration = ({ isUpdate }) => ({ id: STEP_ID, diff --git a/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/Template/index.js b/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/Template/index.js index ba190d031c..b055218123 100644 --- a/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/Template/index.js +++ b/src/fireedge/src/client/components/Forms/Provider/CreateForm/Steps/Template/index.js @@ -75,7 +75,7 @@ const Content = ({ data, setFormData }) => { () => templateSelected?.plain?.provision_type ?? provisionTypes[0] ) - const [templatesByProvisionSelected, providerTypes, description] = + const [templatesByProvisionSelected, providerTypes, providerDescription] = useMemo(() => { const templates = Object.values( provisionTemplates[provisionSelected]?.providers @@ -194,8 +194,11 @@ const Content = ({ data, setFormData }) => { {/* -- DESCRIPTION -- */} {useMemo( - () => description && , - [description] + () => + providerDescription && ( + + ), + [providerDescription] )} diff --git a/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Inputs/index.js b/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Inputs/index.js index 96e09b1adc..b5ffebd10c 100644 --- a/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Inputs/index.js +++ b/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Inputs/index.js @@ -71,12 +71,11 @@ const Inputs = () => ({ // MERGE INPUTS provision template + PROVISION_BODY.inputs (provider fetch) inputs = templateInputs.map((templateInput) => { - const providerInput = - PROVISION_BODY.inputs?.find( - (providerInput) => providerInput.name === templateInput.name - ) ?? {} + const providerInput = PROVISION_BODY.inputs?.find( + (input) => input.name === templateInput.name + ) - return deepmerge(templateInput, providerInput) + return deepmerge(templateInput, providerInput ?? {}) }) setFields(FORM_FIELDS(inputs)) diff --git a/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Template/index.js b/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Template/index.js index ce12d47342..151fe32a1b 100644 --- a/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Template/index.js +++ b/src/fireedge/src/client/components/Forms/Provision/CreateForm/Steps/Template/index.js @@ -78,7 +78,7 @@ const Template = () => ({ () => templateSelected?.provision_type ?? provisionTypes[0] ) - const [templatesByProvisionSelected, providerTypes, description] = + const [templatesByProvisionSelected, providerTypes, providerDescription] = useMemo(() => { const templates = Object.values( provisionTemplates[provisionSelected]?.provisions @@ -209,8 +209,11 @@ const Template = () => ({ {/* -- DESCRIPTION -- */} {useMemo( - () => description && , - [description] + () => + providerDescription && ( + + ), + [providerDescription] )} diff --git a/src/fireedge/src/client/components/Forms/Vm/CreateSchedActionForm/RelativeForm/schema.js b/src/fireedge/src/client/components/Forms/Vm/CreateSchedActionForm/RelativeForm/schema.js index 44d72d3b41..4162b5df44 100644 --- a/src/fireedge/src/client/components/Forms/Vm/CreateSchedActionForm/RelativeForm/schema.js +++ b/src/fireedge/src/client/components/Forms/Vm/CreateSchedActionForm/RelativeForm/schema.js @@ -69,38 +69,34 @@ export const FIELDS = (vm) => [...COMMON_FIELDS(vm), ...RELATIVE_FIELDS] export const SCHEMA = yup .object(getValidationFromFields(RELATIVE_FIELDS)) .concat(COMMON_SCHEMA) - .transform((value) => { - const { - [PERIOD_FIELD.name]: PERIOD, - [TIME_FIELD.name]: TIME, - ...rest - } = value + .transform( + ({ [PERIOD_FIELD.name]: PERIOD, [TIME_FIELD.name]: TIME, ...rest }) => { + if (String(TIME).includes('+')) { + const allPeriods = { + [PERIOD_TYPES.YEARS]: TIME / 365 / 24 / 3600, + [PERIOD_TYPES.MONTHS]: TIME / 30 / 24 / 3600, + [PERIOD_TYPES.WEEKS]: TIME / 7 / 24 / 3600, + [PERIOD_TYPES.DAYS]: TIME / 24 / 3600, + [PERIOD_TYPES.HOURS]: TIME / 3600, + [PERIOD_TYPES.MINUTES]: TIME / 60, + } - if (String(TIME).includes('+')) { - const allPeriods = { - [PERIOD_TYPES.YEARS]: TIME / 365 / 24 / 3600, - [PERIOD_TYPES.MONTHS]: TIME / 30 / 24 / 3600, - [PERIOD_TYPES.WEEKS]: TIME / 7 / 24 / 3600, - [PERIOD_TYPES.DAYS]: TIME / 24 / 3600, - [PERIOD_TYPES.HOURS]: TIME / 3600, - [PERIOD_TYPES.MINUTES]: TIME / 60, + const [period, time] = Object.entries(allPeriods).find( + ([_, value]) => value >= 1 + ) + + return { ...rest, [PERIOD_FIELD.name]: period, [TIME_FIELD.name]: time } } - const [period, time] = Object.entries(allPeriods).find( - ([_, time]) => time >= 1 - ) + const timeInMilliseconds = { + [PERIOD_TYPES.YEARS]: TIME * 365 * 24 * 3600, + [PERIOD_TYPES.MONTHS]: TIME * 30 * 24 * 3600, + [PERIOD_TYPES.WEEKS]: TIME * 7 * 24 * 3600, + [PERIOD_TYPES.DAYS]: TIME * 24 * 3600, + [PERIOD_TYPES.HOURS]: TIME * 3600, + [PERIOD_TYPES.MINUTES]: TIME * 60, + }[PERIOD] - return { ...rest, [PERIOD_FIELD.name]: period, [TIME_FIELD.name]: time } + return { ...rest, [TIME_FIELD.name]: timeInMilliseconds } } - - const timeInMilliseconds = { - [PERIOD_TYPES.YEARS]: TIME * 365 * 24 * 3600, - [PERIOD_TYPES.MONTHS]: TIME * 30 * 24 * 3600, - [PERIOD_TYPES.WEEKS]: TIME * 7 * 24 * 3600, - [PERIOD_TYPES.DAYS]: TIME * 24 * 3600, - [PERIOD_TYPES.HOURS]: TIME * 3600, - [PERIOD_TYPES.MINUTES]: TIME * 60, - }[PERIOD] - - return { ...rest, [TIME_FIELD.name]: timeInMilliseconds } - }) + ) 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 279f5f32a2..8b027283a1 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 @@ -70,7 +70,9 @@ const BootItemDraggable = styled('div')(({ theme, disabled }) => ({ */ export const reorderBootAfterRemove = (id, list, currentBootOrder) => { const type = String(id).toLowerCase().replace(/\d+/g, '') // nic | disk - const getIndexFromId = (id) => String(id).toLowerCase().replace(type, '') + + const getIndexFromId = (bootId) => `${bootId}`.toLowerCase().replace(type, '') + const idxToRemove = getIndexFromId(id) const otherIds = list @@ -195,12 +197,16 @@ const BootOrder = () => { draggableId={ID} index={idx} > - {({ draggableProps, dragHandleProps, innerRef }) => ( + {({ + draggableProps, + dragHandleProps, + innerRef: dragRef, + }) => ( { - return ( - <> - - - - - ) -} +const Context = (props) => ( + <> + + + + +) Context.propTypes = { data: PropTypes.any, diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSchema.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSchema.js index f294bf8a39..ba56bb10c8 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSchema.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/context/userInputsSchema.js @@ -40,7 +40,7 @@ const { boolean: uiBoolean, } = USER_INPUT_TYPES -const { array: _, ...userInputTypes } = USER_INPUT_TYPES +const { array: __, ...userInputTypes } = USER_INPUT_TYPES /** @type {UserInputType[]} User inputs types */ const valuesOfUITypes = Object.values(userInputTypes) @@ -169,17 +169,17 @@ const DEFAULT_VALUE = { validation: string() .trim() .default(() => undefined) - .when([TYPE.name, OPTIONS.name], (type, options = [], schema) => { - return ( - { + .when( + [TYPE.name, OPTIONS.name], + (type, options = [], schema) => + ({ [uiList]: schema.oneOf(options).notRequired(), [uiListMultiple]: schema.includesInOptions(options), [uiRange]: number().min(ref(MIN.name)).max(ref(MAX.name)).integer(), [uiRangeFloat]: number().min(ref(MIN.name)).max(ref(MAX.name)), [uiPassword]: schema.strip().notRequired(), - }[type] ?? schema - ) - }), + }[type] ?? schema) + ), grid: { sm: 6, md: 4 }, } diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSchema.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSchema.js index fcee542266..4da3e9ca4b 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSchema.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/pciDevicesSchema.js @@ -40,7 +40,7 @@ const getPciAttributes = (pciDevice = '') => { } /** @type {Field} Name PCI device field */ -const DEVICE_NAME = { +const NAME_FIELD = { name: 'DEVICE_NAME', label: T.DeviceName, notOnHypervisors: [vcenter, lxc, firecracker], @@ -63,7 +63,7 @@ const commonFieldProps = (name) => ({ name, notOnHypervisors: [vcenter, lxc, firecracker], type: INPUT_TYPES.TEXT, - dependOf: DEVICE_NAME.name, + dependOf: NAME_FIELD.name, watcher: (pciDevice) => { if (pciDevice) { const { [name]: attribute } = getPciAttributes(pciDevice) @@ -77,23 +77,30 @@ const commonFieldProps = (name) => ({ }) /** @type {Field} PCI device field */ -const DEVICE = { label: T.Device, ...commonFieldProps('DEVICE') } +const DEVICE_FIELD = { label: T.Device, ...commonFieldProps('DEVICE') } /** @type {Field} PCI device field */ -const VENDOR = { label: T.Vendor, ...commonFieldProps('VENDOR') } +const VENDOR_FIELD = { label: T.Vendor, ...commonFieldProps('VENDOR') } /** @type {Field} PCI device field */ -const CLASS = { label: T.Class, ...commonFieldProps('CLASS') } +const CLASS_FIELD = { label: T.Class, ...commonFieldProps('CLASS') } /** * @param {string} [hypervisor] - VM hypervisor * @returns {Field[]} List of Graphic inputs fields */ export const PCI_FIELDS = (hypervisor) => - filterFieldsByHypervisor([DEVICE_NAME, DEVICE, VENDOR, CLASS], hypervisor) + filterFieldsByHypervisor( + [NAME_FIELD, DEVICE_FIELD, VENDOR_FIELD, CLASS_FIELD], + hypervisor + ) /** @type {ObjectSchema} PCI devices object schema */ -export const PCI_SCHEMA = getObjectSchemaFromFields([DEVICE, VENDOR, CLASS]) +export const PCI_SCHEMA = getObjectSchemaFromFields([ + DEVICE_FIELD, + VENDOR_FIELD, + CLASS_FIELD, +]) /** @type {ObjectSchema} PCI devices schema */ export const PCI_DEVICES_SCHEMA = object({ diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/numa/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/numa/index.js index 1945f46866..475306810d 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/numa/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/numa/index.js @@ -28,22 +28,20 @@ import { T } from 'client/constants' export const TAB_ID = 'NUMA' -const Numa = ({ hypervisor }) => { - return ( - <> - - - - ) -} +const Numa = ({ hypervisor }) => ( + <> + + + +) Numa.propTypes = { data: PropTypes.any, 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 c0329d89ed..b97745bc24 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 @@ -28,26 +28,24 @@ import { } from 'client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/placement/schema' import { T } from 'client/constants' -const Placement = () => { +const Placement = () => ( // TODO - Host requirements: add button to select HOST in list => ID="" // TODO - Host policy options: Packing|Stripping|Load-aware // TODO - DS requirements: add button to select DATASTORE in list => ID="" // TODO - DS policy options: Packing|Stripping - return ( - <> - {SECTIONS.map(({ id, ...section }) => ( - - ))} - - ) -} + <> + {SECTIONS.map(({ id, ...section }) => ( + + ))} + +) Placement.propTypes = { data: PropTypes.any, diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/Steps/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/Steps/index.js index 086b3cc8bd..b7f6b0cab0 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/Steps/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/Steps/index.js @@ -43,7 +43,7 @@ const Steps = createSteps( { stripUnknown: true } ), }), - transformBeforeSubmit: (formData) => { + transformBeforeSubmit: (formData, vmTemplate) => { const { [TEMPLATE_ID]: [templateSelected] = [], [BASIC_ID]: { name, instances, hold, persistent, ...restOfConfig } = {}, @@ -59,7 +59,7 @@ const Steps = createSteps( ...data, })) - return [templateSelected, templates] + return [templateSelected ?? vmTemplate, templates] }, } ) diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/index.js b/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/index.js index 58c725c8a5..1e7f3dffd2 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/index.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/InstantiateForm/index.js @@ -44,7 +44,9 @@ const InstantiateForm = ({ template, onSubmit }) => { onSubmit(transformBeforeSubmit?.(data) ?? data)} + onSubmit={(data) => + onSubmit(transformBeforeSubmit?.(data, template) ?? data) + } /> ) diff --git a/src/fireedge/src/client/components/Header/Group.js b/src/fireedge/src/client/components/Header/Group.js index 9ea1979ede..4dd9a90f62 100644 --- a/src/fireedge/src/client/components/Header/Group.js +++ b/src/fireedge/src/client/components/Header/Group.js @@ -70,9 +70,8 @@ const ButtonGroup = memo( const Group = () => { const { user, groups } = useAuth() - const sortGroupAsMainFirst = (a, b) => { - return a.ID === user?.GUID ? -1 : b.ID === user?.GUID ? 1 : 0 - } + const sortGroupAsMainFirst = (a, b) => + a.ID === user?.GUID ? -1 : b.ID === user?.GUID ? 1 : 0 const sortMainGroupFirst = useMemo( () => diff --git a/src/fireedge/src/client/components/Icons/DockerIcon.js b/src/fireedge/src/client/components/Icons/DockerIcon.js index 6d9c4e09dd..0a9d60b5f5 100644 --- a/src/fireedge/src/client/components/Icons/DockerIcon.js +++ b/src/fireedge/src/client/components/Icons/DockerIcon.js @@ -16,16 +16,14 @@ import { memo } from 'react' import { number, string, oneOfType } from 'prop-types' -const DockerLogo = memo(({ viewBox, width, height, color, ...props }) => { - return ( - - - - ) -}) +const DockerLogo = memo(({ viewBox, width, height, color, ...props }) => ( + + + +)) DockerLogo.propTypes = { width: oneOfType([number, string]).isRequired, diff --git a/src/fireedge/src/client/components/Sidebar/SidebarCollapseItem.js b/src/fireedge/src/client/components/Sidebar/SidebarCollapseItem.js index 1ff1781144..5125e70f26 100644 --- a/src/fireedge/src/client/components/Sidebar/SidebarCollapseItem.js +++ b/src/fireedge/src/client/components/Sidebar/SidebarCollapseItem.js @@ -75,8 +75,8 @@ const SidebarCollapseItem = ({ label = '', routes = [], icon: Icon }) => { {routes ?.filter( - ({ sidebar = false, label }) => - sidebar && typeof label === 'string' + ({ sidebar = false, ...route }) => + sidebar && typeof route.label === 'string' ) ?.map((subItem, index) => ( diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/CategoryFilter.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/CategoryFilter.js index b0e7674f7c..217cbbe77d 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/CategoryFilter.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/CategoryFilter.js @@ -57,18 +57,18 @@ const CategoryFilter = ({ // Calculate the options for filtering using the preFilteredRows const options = useMemo(() => { - const options = {} + const filteredOptions = {} preFilteredRows?.forEach((row) => { const value = row.values[id] if (!value) return - const count = options[value[accessorOption] ?? value] || 0 - options[value[accessorOption] ?? value] = count + 1 + const count = filteredOptions[value[accessorOption] ?? value] || 0 + filteredOptions[value[accessorOption] ?? value] = count + 1 }) - return options + return filteredOptions }, [id, preFilteredRows]) const handleSelect = (value) => { diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalActions/Action.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalActions/Action.js index e0c3994d20..e54e7f4398 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalActions/Action.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalActions/Action.js @@ -92,7 +92,7 @@ const ActionItem = memo( buttonProps={buttonProps} options={options?.map((option) => { const { - accessor, + accessor: optionAccessor, form, onSubmit, dialogProps, @@ -102,7 +102,7 @@ const ActionItem = memo( return { ...option, - cy: accessor && `action.${accessor}`, + cy: optionAccessor && `action-${optionAccessor}`, disabled: typeof optionDisabled === 'function' ? optionDisabled(selectedRows) diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalFilter.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalFilter.js index 470f0c3c5d..613e8d048c 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalFilter.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalFilter.js @@ -78,8 +78,8 @@ const GlobalFilter = ({ useTableProps, className }) => { const handleChange = useCallback( // Set undefined to remove the filter entirely - debounce((value) => { - setGlobalFilter(value || undefined) + debounce((newFilter) => { + setGlobalFilter(newFilter || undefined) }, 200) ) diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/LabelFilter.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/LabelFilter.js index 799f721b90..7ae6d98b34 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/LabelFilter.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/LabelFilter.js @@ -65,15 +65,15 @@ const LabelFilter = ({ title, column }) => { useEffect(() => () => setFilter([]), []) const labels = useMemo(() => { - const labels = new Set() + const uniqueLabels = new Set() preFilteredRows?.forEach((row) => { const labelsFromTemplate = row.values[id] - labelsFromTemplate.forEach(labels.add, labels) + labelsFromTemplate.forEach(uniqueLabels.add, uniqueLabels) }) - return [...labels.values()] + return [...uniqueLabels.values()] }, [id, preFilteredRows]) const tree = useMemo(() => buildTree(labels), [labels]) @@ -87,8 +87,8 @@ const LabelFilter = ({ title, column }) => { const isFiltered = useMemo(() => filterValue?.length > 0, [filterValue]) - const renderTree = ({ id, name, children }) => ( - + const renderTree = ({ id: treeId, name, children }) => ( + {Array.isArray(children) ? children.map((node) => renderTree(node)) : null} diff --git a/src/fireedge/src/client/components/Tabs/Common/Attribute/Attribute.js b/src/fireedge/src/client/components/Tabs/Common/Attribute/Attribute.js index 05547d81a3..d092f10cf0 100644 --- a/src/fireedge/src/client/components/Tabs/Common/Attribute/Attribute.js +++ b/src/fireedge/src/client/components/Tabs/Common/Attribute/Attribute.js @@ -72,7 +72,7 @@ const Attribute = memo( const handleActiveEditForm = async () => { const response = (await handleGetOptionList?.()) ?? [] const isFormatValid = response?.every?.( - ({ text, value } = {}) => !!text && !!value + ({ text, value: optionValue } = {}) => !!text && !!optionValue ) if (!handleGetOptionList || isFormatValid) { diff --git a/src/fireedge/src/client/components/Tabs/Vm/Log.js b/src/fireedge/src/client/components/Tabs/Vm/Log.js index 411064bd37..12d2e7d427 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Log.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Log.js @@ -15,13 +15,11 @@ * ------------------------------------------------------------------------- */ /* eslint-disable jsdoc/require-jsdoc */ -const VmLogTab = (data) => { - return ( -
-

WIP - LOG

-
- ) -} +const VmLogTab = (data) => ( +
+

WIP - LOG

+
+) VmLogTab.displayName = 'VmLogTab' diff --git a/src/fireedge/src/client/components/Tabs/Vm/Network/Alias.js b/src/fireedge/src/client/components/Tabs/Vm/Network/Alias.js new file mode 100644 index 0000000000..89d1b581cc --- /dev/null +++ b/src/fireedge/src/client/components/Tabs/Vm/Network/Alias.js @@ -0,0 +1,90 @@ +/* ------------------------------------------------------------------------- * + * Copyright 2002-2021, OpenNebula Project, OpenNebula Systems * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); you may * + * not use this file except in compliance with the License. You may obtain * + * a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * + * See the License for the specific language governing permissions and * + * limitations under the License. * + * ------------------------------------------------------------------------- */ +import { memo } from 'react' +import PropTypes from 'prop-types' + +import { styled, useMediaQuery } from '@mui/material' +import Typography from '@mui/material/Typography' + +import MultipleTags from 'client/components/MultipleTags' + +import { Translate } from 'client/components/HOC' +import { T } from 'client/constants' + +const DATACY_ALIAS = 'alias-' + +const Row = styled('div')({ + display: 'flex', + width: '100%', + gap: '0.5em', + alignItems: 'center', + flexWrap: 'nowrap', +}) + +const Labels = styled('span')({ + display: 'inline-flex', + gap: '0.5em', + alignItems: 'center', +}) + +const Alias = memo(({ alias, isPciDevice, detachAction }) => { + const isMobile = useMediaQuery((theme) => theme.breakpoints.down('md')) + const { NIC_ID, NETWORK, IP, MAC, BRIDGE } = alias + + const tags = [ + { + text: IP, + dataCy: `${DATACY_ALIAS}ip`, + }, + { + text: MAC, + dataCy: `${DATACY_ALIAS}mac`, + }, + { + text: BRIDGE && `BRIDGE - ${BRIDGE}`, + dataCy: `${DATACY_ALIAS}bridge`, + }, + ].filter(({ text } = {}) => Boolean(text)) + + return ( + + + + {`${NIC_ID} | ${NETWORK}`} + + + + + {!isMobile && !isPciDevice && detachAction(NIC_ID, true)} + + ) +}) + +Alias.displayName = 'Alias' + +Alias.propTypes = { + alias: PropTypes.shape({ + NIC_ID: PropTypes.string, + NETWORK: PropTypes.string, + IP: PropTypes.string, + MAC: PropTypes.string, + BRIDGE: PropTypes.string, + }), + isPciDevice: PropTypes.bool, + detachAction: PropTypes.func, +} + +export default Alias diff --git a/src/fireedge/src/client/components/Tabs/Vm/Network/Item.js b/src/fireedge/src/client/components/Tabs/Vm/Network/Item.js index 079cf664bf..ba05f63e1b 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Network/Item.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Network/Item.js @@ -33,13 +33,13 @@ import { TabContext } from 'client/components/Tabs/TabProvider' import { Action } from 'client/components/Cards/SelectCard' import { DialogConfirmation } from 'client/components/Dialogs' import MultipleTags from 'client/components/MultipleTags' +import Alias from 'client/components/Tabs/Vm/Network/Alias' +import SecGroup from 'client/components/Tabs/Vm/Network/SecGroup' import { Translate } from 'client/components/HOC' import { T, VM_ACTIONS } from 'client/constants' -const DATACYSECURITY = 'securitygroup-' -const DATACYNETWORK = 'network-' -const DATACYALIAS = 'alias-' +const DATACY_NETWORK = 'network-' const Accordion = styled((props) => ( @@ -133,24 +133,24 @@ const NetworkItem = ({ nic = {}, actions }) => { const tags = [ { text: IP, - dataCy: `${DATACYNETWORK}ip`, + dataCy: `${DATACY_NETWORK}ip`, }, { text: MAC, - dataCy: `${DATACYNETWORK}mac`, + dataCy: `${DATACY_NETWORK}mac`, }, { text: ADDRESS, - dataCy: `${DATACYNETWORK}address`, + dataCy: `${DATACY_NETWORK}address`, }, ].filter(({ text } = {}) => Boolean(text)) return ( <> - + })}> - + {`${NIC_ID} | ${NETWORK}`} @@ -165,108 +165,27 @@ const NetworkItem = ({ nic = {}, actions }) => { {hasDetails && (
- {ALIAS?.map(({ NIC_ID, NETWORK = '-', BRIDGE, IP, MAC }) => { - const tags = [ - { - text: IP, - dataCy: `${DATACYALIAS}ip`, - }, - { - text: MAC, - dataCy: `${DATACYALIAS}mac`, - }, - { - text: BRIDGE && `BRIDGE - ${BRIDGE}`, - dataCy: `${DATACYALIAS}bridge`, - }, - ].filter(({ text } = {}) => Boolean(text)) - - return ( - - - - {`${NIC_ID} | ${NETWORK}`} - - - - - {!isMobile && !isPciDevice && detachAction(NIC_ID, true)} - - ) - })} + {ALIAS?.map((alias) => ( + + ))} {!!SECURITY_GROUPS?.length && ( - {SECURITY_GROUPS?.map( - ( - { - ID, - SECURITY_GROUP_ID, - NAME, - PROTOCOL, - RULE_TYPE, - ICMP_TYPE, - RANGE, - NETWORK_ID, - }, - idx - ) => { - const tags = [ - { - text: PROTOCOL, - dataCy: `${DATACYSECURITY}protocol`, - }, - { - text: RULE_TYPE, - dataCy: `${DATACYSECURITY}ruletype`, - }, - { - text: RANGE, - dataCy: `${DATACYSECURITY}range`, - }, - { - text: NETWORK_ID, - dataCy: `${DATACYSECURITY}networkid`, - }, - { - text: ICMP_TYPE, - dataCy: `${DATACYSECURITY}icmp_type`, - }, - ].filter(({ text } = {}) => Boolean(text)) - - return ( - - - {`${ID} | ${NAME}`} - - - - - - ) - } - )} + {SECURITY_GROUPS?.map((securityGroup, idx) => ( + + ))} )}
diff --git a/src/fireedge/src/client/components/Tabs/Vm/Network/SecGroup.js b/src/fireedge/src/client/components/Tabs/Vm/Network/SecGroup.js new file mode 100644 index 0000000000..3455f03943 --- /dev/null +++ b/src/fireedge/src/client/components/Tabs/Vm/Network/SecGroup.js @@ -0,0 +1,97 @@ +/* ------------------------------------------------------------------------- * + * Copyright 2002-2021, OpenNebula Project, OpenNebula Systems * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); you may * + * not use this file except in compliance with the License. You may obtain * + * a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * + * See the License for the specific language governing permissions and * + * limitations under the License. * + * ------------------------------------------------------------------------- */ +import { memo } from 'react' +import PropTypes from 'prop-types' + +import { styled, useMediaQuery } from '@mui/material' +import Typography from '@mui/material/Typography' + +import MultipleTags from 'client/components/MultipleTags' + +const DATACY_SECGROUP = 'securitygroup-' + +const Row = styled('div')({ + display: 'flex', + width: '100%', + gap: '0.5em', + alignItems: 'center', + flexWrap: 'nowrap', +}) + +const Labels = styled('span')({ + display: 'inline-flex', + gap: '0.5em', + alignItems: 'center', +}) + +const SecGroup = memo(({ index, securityGroup }) => { + const isMobile = useMediaQuery((theme) => theme.breakpoints.down('md')) + + const { ID, NAME, PROTOCOL, RULE_TYPE, ICMP_TYPE, RANGE, NETWORK_ID } = + securityGroup + + const tags = [ + { + text: PROTOCOL, + dataCy: `${DATACY_SECGROUP}protocol`, + }, + { + text: RULE_TYPE, + dataCy: `${DATACY_SECGROUP}ruletype`, + }, + { + text: RANGE, + dataCy: `${DATACY_SECGROUP}range`, + }, + { + text: NETWORK_ID, + dataCy: `${DATACY_SECGROUP}networkid`, + }, + { + text: ICMP_TYPE, + dataCy: `${DATACY_SECGROUP}icmp_type`, + }, + ].filter(({ text } = {}) => Boolean(text)) + + return ( + + + {`${ID} | ${NAME}`} + + + + + + ) +}) + +SecGroup.displayName = 'SecGroup' + +SecGroup.propTypes = { + index: PropTypes.number, + securityGroup: PropTypes.shape({ + ID: PropTypes.string, + SECURITY_GROUP_ID: PropTypes.string, + NAME: PropTypes.string, + PROTOCOL: PropTypes.string, + RULE_TYPE: PropTypes.string, + ICMP_TYPE: PropTypes.string, + RANGE: PropTypes.string, + NETWORK_ID: PropTypes.string, + }), +} + +export default SecGroup diff --git a/src/fireedge/src/client/components/Tabs/Vm/SchedActions/Actions.js b/src/fireedge/src/client/components/Tabs/Vm/SchedActions/Actions.js index 5df2072e9d..3dc0a7c5b0 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/SchedActions/Actions.js +++ b/src/fireedge/src/client/components/Tabs/Vm/SchedActions/Actions.js @@ -196,7 +196,7 @@ const CharterAction = memo(() => { } const [period, parsedTime] = Object.entries(allPeriods).find( - ([_, time]) => time >= 1 + ([_, value]) => value >= 1 ) return ( diff --git a/src/fireedge/src/client/components/Tabs/index.js b/src/fireedge/src/client/components/Tabs/index.js index 62cf781aaa..91ed445c19 100644 --- a/src/fireedge/src/client/components/Tabs/index.js +++ b/src/fireedge/src/client/components/Tabs/index.js @@ -73,18 +73,16 @@ const Tabs = ({ }} {...tabsProps} > - {tabs.map(({ value, name, label, error, icon: Icon }, idx) => { - return ( - : Icon && } - value={value ?? idx} - label={label ?? name} - data-cy={`tab-${name}`} - /> - ) - })} + {tabs.map(({ value, name, label, error, icon: Icon }, idx) => ( + : Icon && } + value={value ?? idx} + label={label ?? name} + data-cy={`tab-${name}`} + /> + ))} ), [tabs, tabSelected] diff --git a/src/fireedge/src/client/containers/ApplicationsInstances/DialogInfo/index.js b/src/fireedge/src/client/containers/ApplicationsInstances/DialogInfo/index.js index 4255136e2b..fb72219a91 100644 --- a/src/fireedge/src/client/containers/ApplicationsInstances/DialogInfo/index.js +++ b/src/fireedge/src/client/containers/ApplicationsInstances/DialogInfo/index.js @@ -50,13 +50,13 @@ const DialogInfo = ({ info, handleClose }) => { scrollButtons="auto" onChange={(_, tab) => setTab(tab)} > - {TABS.map(({ name, icon: Icon }, idx) => ( + {TABS.map(({ name: tabName, icon: Icon }, idx) => ( } value={idx} - label={String(name).toUpperCase()} + label={String(tabName).toUpperCase()} /> ))} @@ -70,18 +70,18 @@ const DialogInfo = ({ info, handleClose }) => { {renderTabs} {useMemo( () => - TABS.map(({ name, content: Content }, idx) => ( + TABS.map(({ name: tabName, content: Content }, idx) => ( )), diff --git a/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Deploy/Steps/Tiers/index.js b/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Deploy/Steps/Tiers/index.js index 4b361234b9..09809d9741 100644 --- a/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Deploy/Steps/Tiers/index.js +++ b/src/fireedge/src/client/containers/ApplicationsTemplates/Form/Deploy/Steps/Tiers/index.js @@ -23,7 +23,7 @@ import { WarningCircledOutline as WarningIcon } from 'iconoir-react' import FormWithSchema from 'client/components/Forms/FormWithSchema' import { T } from 'client/constants' -import { ID, FORM_FIELDS, STEP_FORM_SCHEMA } from './schema' +import { ID_FIELD, FORM_FIELDS, STEP_FORM_SCHEMA } from './schema' export const STEP_ID = 'tiers' @@ -78,7 +78,7 @@ const Tiers = ({ tiers, vmTemplates }) => {