diff --git a/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js b/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js index f35a713537..7f5707b0f5 100644 --- a/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js +++ b/src/fireedge/src/client/components/Dialogs/DialogConfirmation.js @@ -46,8 +46,8 @@ const useStyles = makeStyles({ const DialogConfirmation = memo( ({ - open, - title, + open = true, + title = '', subheader, contentProps, handleAccept, @@ -105,7 +105,7 @@ const DialogConfirmation = memo( } ) -DialogConfirmation.propTypes = { +export const DialogPropTypes = { open: PropTypes.bool.isRequired, title: PropTypes.string.isRequired, subheader: PropTypes.string, @@ -121,18 +121,7 @@ DialogConfirmation.propTypes = { ]) } -DialogConfirmation.defaultProps = { - open: true, - title: 'Confirmation dialog', - subheader: undefined, - contentProps: undefined, - handleAccept: undefined, - acceptButtonProps: undefined, - handleCancel: undefined, - cancelButtonProps: undefined, - handleEntering: undefined, - children: undefined -} +DialogConfirmation.propTypes = DialogPropTypes DialogConfirmation.displayName = 'DialogConfirmation' diff --git a/src/fireedge/src/client/components/Dialogs/DialogForm.js b/src/fireedge/src/client/components/Dialogs/DialogForm.js index fea3317cc6..17e41c2f60 100644 --- a/src/fireedge/src/client/components/Dialogs/DialogForm.js +++ b/src/fireedge/src/client/components/Dialogs/DialogForm.js @@ -13,113 +13,78 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -import React, { memo } from 'react' +/* eslint-disable jsdoc/require-jsdoc */ +import * as React from 'react' import PropTypes from 'prop-types' -import { - useMediaQuery, - Button, - Dialog, - DialogTitle, - DialogContent, - DialogActions -} from '@material-ui/core' +import clsx from 'clsx' +import { makeStyles } from '@material-ui/core' import { useForm, FormProvider } from 'react-hook-form' import { yupResolver } from '@hookform/resolvers' -import { SubmitButton } from 'client/components/FormControl' -import { Tr } from 'client/components/HOC' -import { T } from 'client/constants' +import DialogConfirmation, { DialogPropTypes } from 'client/components/Dialogs/DialogConfirmation' -const DialogForm = memo( - ({ - open, - title, - values, - resolver, - onSubmit, - onCancel, - submitButtonProps, - children - }) => { - const isMobile = useMediaQuery(theme => theme.breakpoints.only('xs')) - - const methods = useForm({ - mode: 'onBlur', - reValidateMode: 'onSubmit', - defaultValues: values, - resolver: yupResolver(resolver()) - }) - - return ( - - {Tr(title)} - - {children} - - {(onCancel || onSubmit) && ( - - {onCancel && ( - - )} - {onSubmit && ( - - )} - - )} - - ) +const useStyles = makeStyles(theme => ({ + content: { + width: '80vw', + height: '60vh', + maxWidth: '100%', + maxHeight: '100%', + overflow: 'hidden', + display: 'flex', + flexDirection: 'column', + [theme.breakpoints.only('xs')]: { + width: '100vw', + height: '100vh' + } } -) +})) -export const DialogFormPropTypes = { - open: PropTypes.bool.isRequired, - title: PropTypes.string.isRequired, +const DialogForm = ({ values, resolver, handleSubmit, dialogProps, children }) => { + const classes = useStyles() + + const { className, ...contentProps } = dialogProps.contentProps ?? {} + + dialogProps.contentProps = { + className: clsx(classes.content, className), + ...contentProps + } + + const methods = useForm({ + mode: 'onBlur', + reValidateMode: 'onSubmit', + defaultValues: values, + resolver: yupResolver(resolver()) + }) + + return ( + + + {children} + + + ) +} + +DialogForm.propTypes = { values: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.any), PropTypes.objectOf(PropTypes.any) ]), resolver: PropTypes.func.isRequired, - onSubmit: PropTypes.func, - onCancel: PropTypes.func, - submitButtonProps: PropTypes.objectOf(PropTypes.any), + handleSubmit: PropTypes.func, + dialogProps: DialogPropTypes, children: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), - PropTypes.node + PropTypes.node, + PropTypes.func ]) } -DialogForm.propTypes = DialogFormPropTypes - -DialogForm.defaultProps = { - open: true, - title: 'Title dialog form', - values: {}, - resolver: {}, - onSubmit: undefined, - onCancel: undefined, - submitButtonProps: undefined, - children: null -} - export default DialogForm diff --git a/src/fireedge/src/client/components/Dialogs/DialogRequest.js b/src/fireedge/src/client/components/Dialogs/DialogRequest.js index 58776bc508..93ad088b49 100644 --- a/src/fireedge/src/client/components/Dialogs/DialogRequest.js +++ b/src/fireedge/src/client/components/Dialogs/DialogRequest.js @@ -17,11 +17,11 @@ import React, { useEffect } from 'react' import PropTypes from 'prop-types' +import clsx from 'clsx' import { makeStyles, Backdrop, CircularProgress } from '@material-ui/core' import { useFetch } from 'client/hooks' import { DialogConfirmation } from 'client/components/Dialogs' -import clsx from 'clsx' const useStyles = makeStyles(theme => ({ backdrop: { diff --git a/src/fireedge/src/client/components/Dialogs/index.js b/src/fireedge/src/client/components/Dialogs/index.js index 164dabdd06..5da6efaf79 100644 --- a/src/fireedge/src/client/components/Dialogs/index.js +++ b/src/fireedge/src/client/components/Dialogs/index.js @@ -13,13 +13,13 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -import DialogForm, { DialogFormPropTypes } from 'client/components/Dialogs/DialogForm' +import DialogForm from 'client/components/Dialogs/DialogForm' import DialogRequest from 'client/components/Dialogs/DialogRequest' -import DialogConfirmation from 'client/components/Dialogs/DialogConfirmation' +import DialogConfirmation, { DialogPropTypes } from 'client/components/Dialogs/DialogConfirmation' export { DialogForm, - DialogFormPropTypes, DialogRequest, - DialogConfirmation + DialogConfirmation, + DialogPropTypes } diff --git a/src/fireedge/src/client/components/FormControl/AutocompleteController.js b/src/fireedge/src/client/components/FormControl/AutocompleteController.js index 05e8905af3..c89a1b8dd1 100644 --- a/src/fireedge/src/client/components/FormControl/AutocompleteController.js +++ b/src/fireedge/src/client/components/FormControl/AutocompleteController.js @@ -68,6 +68,8 @@ const AutocompleteController = memo( label={Tr(label)} inputProps={{ ...inputProps, 'data-cy': cy }} error={Boolean(error)} + variant='outlined' + margin='dense' helperText={ Boolean(error) && } diff --git a/src/fireedge/src/client/components/FormControl/CheckboxController.js b/src/fireedge/src/client/components/FormControl/CheckboxController.js index f60152f18a..ac232b8118 100644 --- a/src/fireedge/src/client/components/FormControl/CheckboxController.js +++ b/src/fireedge/src/client/components/FormControl/CheckboxController.js @@ -32,7 +32,7 @@ const CheckboxController = memo( ( - + { + ({ control, cy, name, label, multiple, values, error, fieldProps }) => { const defaultValue = multiple ? [values?.[0]?.value] : values?.[0]?.value return ( @@ -36,7 +36,9 @@ const SelectController = memo( color='secondary' select fullWidth - SelectProps={{ displayEmpty: true, multiple, native }} + variant='outlined' + margin='dense' + SelectProps={{ native: true, multiple }} label={Tr(label)} inputProps={{ 'data-cy': cy }} error={Boolean(error)} @@ -44,11 +46,11 @@ const SelectController = memo( FormHelperTextProps={{ 'data-cy': `${cy}-error` }} {...fieldProps} > - {values?.map(({ text, value = '' }) => createElement( - native ? 'option' : MenuItem, - { key: `${name}-${value}`, value }, - text - ))} + {values?.map(({ text, value = '' }) => + + )} )} name={name} @@ -67,7 +69,6 @@ SelectController.propTypes = { name: PropTypes.string.isRequired, label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), multiple: PropTypes.bool, - native: PropTypes.bool, values: PropTypes.arrayOf(PropTypes.object).isRequired, error: PropTypes.oneOfType([ PropTypes.bool, @@ -82,7 +83,6 @@ SelectController.defaultProps = { name: '', label: '', multiple: false, - native: false, values: [], error: false, fieldProps: undefined diff --git a/src/fireedge/src/client/components/FormControl/SliderController.js b/src/fireedge/src/client/components/FormControl/SliderController.js index 653f186fb8..a9951093a5 100644 --- a/src/fireedge/src/client/components/FormControl/SliderController.js +++ b/src/fireedge/src/client/components/FormControl/SliderController.js @@ -33,7 +33,6 @@ const SliderController = memo( - diff --git a/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js b/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js new file mode 100644 index 0000000000..f5d61d1c9d --- /dev/null +++ b/src/fireedge/src/client/components/Forms/ButtonToTriggerForm.js @@ -0,0 +1,139 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import * as React from 'react' +import PropTypes from 'prop-types' + +import { + Button, + ClickAwayListener, + Grow, + Paper, + Popper, + MenuItem, + MenuList +} from '@material-ui/core' +import { NavArrowDown } from 'iconoir-react' + +import { useDialog } from 'client/hooks' +import { DialogForm } from 'client/components/Dialogs' +import { FormWithSchema } from 'client/components/Forms' +import FormStepper from 'client/components/FormStepper' +import { Translate } from 'client/components/HOC' + +const ButtonToTriggerForm = ({ buttonProps = {}, title, options = [] }) => { + const isGroupButton = options.length > 1 + + const [anchorEl, setAnchorEl] = React.useState(null) + const open = Boolean(anchorEl) + + const { display, show, hide, values: Form } = useDialog() + const { steps, defaultValues, resolver, fields, onSubmit: handleSubmit } = Form ?? {} + + const handleTriggerSubmit = async formData => { + await handleSubmit(formData) + hide() + } + + const openDialogForm = form => { + show(form) + handleClose() + } + + const handleToggle = evt => setAnchorEl(prev => prev ? null : evt.currentTarget) + const handleClose = () => setAnchorEl(null) + + return ( + <> + + + {isGroupButton && ( + + {({ TransitionProps }) => ( + + + + + {options.map(({ cy, name, form = {}, onSubmit }) => ( + openDialogForm({ ...form, onSubmit })} + > + + + ))} + + + + + )} + + )} + + {display && ( + + {steps ? ( + + ) : ( + + )} + + )} + + ) +} + +ButtonToTriggerForm.propTypes = { + buttonProps: PropTypes.object, + title: PropTypes.string, + options: PropTypes.arrayOf( + PropTypes.shape({ + cy: PropTypes.string, + name: PropTypes.string, + form: PropTypes.object + }) + ), + handleSubmit: PropTypes.func +} + +ButtonToTriggerForm.displayName = 'VmStorageTab' + +export default ButtonToTriggerForm diff --git a/src/fireedge/src/client/components/Forms/FormWithSchema.js b/src/fireedge/src/client/components/Forms/FormWithSchema.js index 6c29f18c03..7da488381a 100644 --- a/src/fireedge/src/client/components/Forms/FormWithSchema.js +++ b/src/fireedge/src/client/components/Forms/FormWithSchema.js @@ -42,7 +42,7 @@ const FormWithSchema = ({ id, cy, fields }) => { return ( - {fields?.map( + {fields?.map?.( ({ name, type, htmlType, values, dependOf, grid, ...restOfProps }) => { const dataCy = `${cy}-${name}` const inputName = id ? `${id}.${name}` : name diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js new file mode 100644 index 0000000000..d8b3d3666e --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/CommonFields.js @@ -0,0 +1,162 @@ +/* ------------------------------------------------------------------------- * + * 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 * as yup from 'yup' +import { INPUT_TYPES, T, HYPERVISORS } from 'client/constants' + +const { kvm, vcenter, firecracker, lxc } = HYPERVISORS + +export const TARGET = { + name: 'TARGET', + label: 'Target device', + notOnHypervisors: [vcenter, firecracker, lxc], + tooltip: ` + Device to map image disk. + If set, it will overwrite the default device mapping.`, + type: INPUT_TYPES.TEXT, + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const READONLY = { + name: 'READONLY', + label: 'Read only', + notOnHypervisors: [vcenter], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: T.Yes, value: 'YES' }, + { text: T.No, value: 'NO' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const DEV_PREFIX = { + name: 'DEV_PREFIX', + label: 'BUS', + notOnHypervisors: [vcenter, firecracker, lxc], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: 'Virtio', value: 'vd' }, + { text: 'CSI/SATA', value: 'sd' }, + { text: 'Parallel ATA (IDE)', value: 'hd' }, + { text: 'Custom', value: 'custom' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const VCENTER_ADAPTER_TYPE = { + name: 'VCENTER_ADAPTER_TYPE', + label: 'Bus adapter controller', + notOnHypervisors: [kvm, firecracker], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: 'lsiLogic', value: 'lsiLogic' }, + { text: 'ide', value: 'ide' }, + { text: 'busLogic', value: 'busLogic' }, + { text: 'Custom', value: 'custom' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const VCENTER_DISK_TYPE = { + name: 'VCENTER_DISK_TYPE', + label: 'Disk provisioning type', + notOnHypervisors: [kvm, firecracker], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: 'Thin', value: 'thin' }, + { text: 'Thick', value: 'thick' }, + { text: 'Eager Zeroed Thick', value: 'eagerZeroedThick' }, + { text: 'Custom', value: 'custom' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const CACHE = { + name: 'CACHE', + label: 'Cache', + notOnHypervisors: [vcenter, firecracker, lxc], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: 'Default', value: 'default' }, + { text: 'Writethrough', value: 'writethrough' }, + { text: 'Writeback', value: 'writeback' }, + { text: 'Directsync', value: 'directsync' }, + { text: 'Unsafe', value: 'unsafe' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const IO = { + name: 'IO', + label: 'IO Policy', + notOnHypervisors: [vcenter, firecracker, lxc], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: 'Threads', value: 'threads' }, + { text: 'Native', value: 'native' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} + +export const DISCARD = { + name: 'DISCARD', + label: 'Discard', + notOnHypervisors: [vcenter, firecracker, lxc], + type: INPUT_TYPES.SELECT, + values: [ + { text: '', value: '' }, + { text: 'Ignore', value: 'ignore' }, + { text: 'Unmap', value: 'unmap' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +} diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js new file mode 100644 index 0000000000..142a7272b5 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/index.js @@ -0,0 +1,46 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import React, { useCallback } from 'react' + +import FormWithSchema from 'client/components/Forms/FormWithSchema' + +import { + SCHEMA, + FIELDS +} from 'client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/schema' +import { T } from 'client/constants' + +export const STEP_ID = 'advanced' + +const AdvancedOptions = ({ hypervisor } = {}) => ({ + id: STEP_ID, + label: T.AdvancedOptions, + resolver: () => SCHEMA(hypervisor), + optionsValidate: { abortEarly: false }, + content: useCallback( + () => ( + + ), + [hypervisor] + ) +}) + +export default AdvancedOptions diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/schema.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/schema.js new file mode 100644 index 0000000000..3ed528e1cd --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions/schema.js @@ -0,0 +1,49 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import * as yup from 'yup' + +import * as COMMON_FIELDS from 'client/components/Forms/Vm/AttachDiskForm/CommonFields' +import { INPUT_TYPES, HYPERVISORS } from 'client/constants' +import { getValidationFromFields } from 'client/utils' + +const { vcenter } = HYPERVISORS + +const SIZE = { + name: 'SIZE', + label: 'Size on instantiate', + tooltip: ` + The size of the disk will be modified to match + this size when the template is instantiated`, + notOnHypervisors: [vcenter], + type: INPUT_TYPES.TEXT, + htmlType: 'number', + validation: yup + .number() + .typeError('Size value must be a number') + .notRequired() + .default(undefined) +} + +export const FIELDS = hypervisor => [ + SIZE, + ...Object.values(COMMON_FIELDS) +] + .map(field => typeof field === 'function' ? field(hypervisor) : field) + .filter(({ notOnHypervisors } = {}) => !notOnHypervisors?.includes?.(hypervisor)) + +export const SCHEMA = hypervisor => + yup.object(getValidationFromFields(FIELDS(hypervisor))) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/index.js new file mode 100644 index 0000000000..2bf04e64fa --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/index.js @@ -0,0 +1,68 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import React, { useCallback } from 'react' + +import { useListForm } from 'client/hooks' +import { ImagesTable } from 'client/components/Tables' + +import { + SCHEMA +} from 'client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/schema' +import { T } from 'client/constants' + +export const STEP_ID = 'image' + +const ImageStep = () => ({ + id: STEP_ID, + label: T.Image, + resolver: () => SCHEMA, + content: useCallback( + ({ data, setFormData }) => { + const selectedImage = data?.[0] + + const { + handleSelect, + handleClear + } = useListForm({ key: STEP_ID, setList: setFormData }) + + const handleSelectedRows = rows => { + const { original } = rows?.[0] ?? {} + const { ID, NAME, UID, UNAME } = original ?? {} + + const image = { + IMAGE_ID: ID, + IMAGE: NAME, + IMAGE_UID: UID, + IMAGE_UNAME: UNAME + } + + ID !== undefined ? handleSelect(image) : handleClear() + } + + return ( + + ) + }, []) +}) + +export default ImageStep diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/schema.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/schema.js new file mode 100644 index 0000000000..866b07ca12 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable/schema.js @@ -0,0 +1,23 @@ +/* ------------------------------------------------------------------------- * + * 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 * as yup from 'yup' + +export const SCHEMA = yup + .array(yup.object()) + .min(1, 'Select image') + .max(1, 'Max. one image selected') + .required('Image field is required') + .default([]) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/index.js new file mode 100644 index 0000000000..0c5a992590 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/ImageSteps/index.js @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import * as yup from 'yup' + +import ImagesTable from 'client/components/Forms/Vm/AttachDiskForm/ImageSteps/ImagesTable' +import AdvancedOptions from 'client/components/Forms/Vm/AttachDiskForm/ImageSteps/AdvancedOptions' + +const Steps = stepProps => { + const image = ImagesTable(stepProps) + const advanced = AdvancedOptions(stepProps) + + const steps = [image, advanced] + + const resolver = () => yup.object({ + [image.id]: image.resolver(), + [advanced.id]: advanced.resolver() + }) + + const defaultValues = resolver().default() + + return { steps, defaultValues, resolver } +} + +export default Steps diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js new file mode 100644 index 0000000000..32351a53e0 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/index.js @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import React, { useCallback } from 'react' + +import FormWithSchema from 'client/components/Forms/FormWithSchema' + +import { + SCHEMA, + FIELDS +} from 'client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/schema' +import { T } from 'client/constants' + +export const STEP_ID = 'advanced' + +const AdvancedOptions = ({ hypervisor } = {}) => ({ + id: STEP_ID, + label: T.AdvancedOptions, + resolver: () => SCHEMA(hypervisor), + optionsValidate: { abortEarly: false }, + content: useCallback( + () => , + [hypervisor] + ) +}) + +export default AdvancedOptions diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/schema.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/schema.js new file mode 100644 index 0000000000..2736100a8c --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions/schema.js @@ -0,0 +1,29 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import * as yup from 'yup' + +import { + TARGET, READONLY, CACHE, IO, DISCARD, DEV_PREFIX, VCENTER_DISK_TYPE +} from 'client/components/Forms/Vm/AttachDiskForm/CommonFields' +import { getValidationFromFields } from 'client/utils' + +export const FIELDS = hypervisor => [ + TARGET, READONLY, CACHE, IO, DISCARD, DEV_PREFIX, VCENTER_DISK_TYPE +].filter(({ notOnHypervisors } = {}) => !notOnHypervisors?.includes?.(hypervisor)) + +export const SCHEMA = hypervisor => + yup.object(getValidationFromFields(FIELDS(hypervisor))) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js new file mode 100644 index 0000000000..5fafc4b18f --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/index.js @@ -0,0 +1,44 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import React, { useCallback } from 'react' + +import FormWithSchema from 'client/components/Forms/FormWithSchema' + +import { + SCHEMA, + FIELDS +} from 'client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/schema' +import { T } from 'client/constants' + +export const STEP_ID = 'configuration' + +const BasicConfiguration = ({ hypervisor } = {}) => ({ + id: STEP_ID, + label: T.Configuration, + resolver: () => SCHEMA(hypervisor), + optionsValidate: { abortEarly: false }, + content: useCallback( + () => , + [hypervisor] + ) +}) + +export default BasicConfiguration diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/schema.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/schema.js new file mode 100644 index 0000000000..7e0c913687 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration/schema.js @@ -0,0 +1,110 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import * as yup from 'yup' + +import { INPUT_TYPES, HYPERVISORS } from 'client/constants' +import { getValidationFromFields } from 'client/utils' + +const { vcenter } = HYPERVISORS + +const SIZE = { + name: 'SIZE', + label: 'Size', + type: INPUT_TYPES.TEXT, + htmlType: 'number', + validation: yup + .number() + .typeError('Size value must be a number') + .required('Size field is required') + .default(undefined) +} + +const TYPE = hypervisor => ({ + name: 'TYPE', + label: 'Disk type', + type: INPUT_TYPES.SELECT, + values: hypervisor === vcenter + ? [{ text: 'FS', value: 'fs' }] + : [ + { text: 'FS', value: 'fs' }, + { text: 'Swap', value: 'swap' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default('fs') +}) + +const FORMAT = hypervisor => { + const typeFieldName = TYPE(hypervisor).name + + return { + name: 'FORMAT', + label: 'Format', + type: INPUT_TYPES.SELECT, + dependOf: typeFieldName, + htmlType: type => type === 'swap' ? INPUT_TYPES.HIDDEN : undefined, + values: hypervisor === vcenter + ? [{ text: 'Raw', value: 'raw' }] + : [ + { text: 'Raw', value: 'raw' }, + { text: 'qcow2', value: 'qcow2' } + ], + validation: yup + .string() + .trim() + .when(typeFieldName, (type, schema) => type === 'swap' + ? schema.notRequired() + : schema.required('Format field is required') + ) + .default('raw') + } +} + +const FILESYSTEM = hypervisor => ({ + name: 'FS', + label: 'Filesystem', + notOnHypervisors: [vcenter], + type: INPUT_TYPES.SELECT, + dependOf: TYPE(hypervisor).name, + htmlType: type => type === 'swap' ? INPUT_TYPES.HIDDEN : undefined, + values: [ // TODO: sunstone-config => support_fs ??? + { text: '', value: '' }, + { text: 'ext4', value: 'ext4' }, + { text: 'ext3', value: 'ext3' }, + { text: 'ext2', value: 'ext2' }, + { text: 'xfs', value: 'xfs' } + ], + validation: yup + .string() + .trim() + .notRequired() + .default(undefined) +}) + +export const FIELDS = hypervisor => [ + SIZE, + TYPE, + FORMAT, + FILESYSTEM +] + .map(field => typeof field === 'function' ? field(hypervisor) : field) + .filter(({ notOnHypervisors } = {}) => !notOnHypervisors?.includes?.(hypervisor)) + +export const SCHEMA = hypervisor => + yup.object(getValidationFromFields(FIELDS(hypervisor))) diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/index.js new file mode 100644 index 0000000000..b97f726625 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/VolatileSteps/index.js @@ -0,0 +1,38 @@ +/* ------------------------------------------------------------------------- * + * 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. * + * ------------------------------------------------------------------------- */ +/* eslint-disable jsdoc/require-jsdoc */ +import * as yup from 'yup' + +import BasicConfiguration from 'client/components/Forms/Vm/AttachDiskForm/VolatileSteps/BasicConfiguration' +import AdvancedOptions from 'client/components/Forms/Vm/AttachDiskForm/VolatileSteps/AdvancedOptions' + +const Steps = stepProps => { + const configuration = BasicConfiguration(stepProps) + const advancedOptions = AdvancedOptions(stepProps) + + const steps = [configuration, advancedOptions] + + const resolver = () => yup.object({ + [configuration.id]: configuration.resolver(), + [advancedOptions.id]: advancedOptions.resolver() + }) + + const defaultValues = resolver().default() + + return { steps, defaultValues, resolver } +} + +export default Steps diff --git a/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/index.js b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/index.js new file mode 100644 index 0000000000..11e7f0ac8e --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/AttachDiskForm/index.js @@ -0,0 +1,22 @@ +/* ------------------------------------------------------------------------- * + * 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 ImageSteps from 'client/components/Forms/Vm/AttachDiskForm/ImageSteps' +import VolatileSteps from 'client/components/Forms/Vm/AttachDiskForm/VolatileSteps' + +export { + ImageSteps, + VolatileSteps +} diff --git a/src/fireedge/src/client/components/Tables/Vms/detail.js b/src/fireedge/src/client/components/Forms/Vm/ResizeCapacityForm/index.js similarity index 56% rename from src/fireedge/src/client/components/Tables/Vms/detail.js rename to src/fireedge/src/client/components/Forms/Vm/ResizeCapacityForm/index.js index e7f32b7fe5..eb069034fe 100644 --- a/src/fireedge/src/client/components/Tables/Vms/detail.js +++ b/src/fireedge/src/client/components/Forms/Vm/ResizeCapacityForm/index.js @@ -13,47 +13,24 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -import * as React from 'react' +/* eslint-disable jsdoc/require-jsdoc */ import PropTypes from 'prop-types' -import { LinearProgress } from '@material-ui/core' +import { SCHEMA, FIELDS } from 'client/components/Forms/Vm/ResizeCapacityForm/schema' -import { useFetch, useSocket } from 'client/hooks' -import { useVmApi } from 'client/features/One' +const ResizeCapacityForm = ({ vm } = {}) => { + const { TEMPLATE = {} } = vm ?? {} -import VmTabs from 'client/components/Tabs/Vm' - -const VmDetail = React.memo(({ id }) => { - const { getHooksSocket } = useSocket() - const { getVm } = useVmApi() - - const { - data, - fetchRequest, - loading, - error - } = useFetch(getVm, getHooksSocket({ resource: 'vm', id })) - - const handleRefetch = () => fetchRequest(id, { reload: true }) - - React.useEffect(() => { - fetchRequest(id) - }, [id]) - - if ((!data && !error) || loading) { - return + return { + resolver: () => SCHEMA, + defaultValues: SCHEMA.cast(TEMPLATE, { stripUnknown: true }), + fields: FIELDS } - - if (error) { - return
{error || 'Error'}
- } - - return -}) - -VmDetail.propTypes = { - id: PropTypes.string.isRequired } -VmDetail.displayName = 'VmDetail' +ResizeCapacityForm.propTypes = { + vm: PropTypes.object +} -export default VmDetail +ResizeCapacityForm.displayName = 'ResizeCapacityForm' + +export default ResizeCapacityForm diff --git a/src/fireedge/src/client/formSchema/Vm/resize.js b/src/fireedge/src/client/components/Forms/Vm/ResizeCapacityForm/schema.js similarity index 95% rename from src/fireedge/src/client/formSchema/Vm/resize.js rename to src/fireedge/src/client/components/Forms/Vm/ResizeCapacityForm/schema.js index 4bf8bab909..9fcf527081 100644 --- a/src/fireedge/src/client/formSchema/Vm/resize.js +++ b/src/fireedge/src/client/components/Forms/Vm/ResizeCapacityForm/schema.js @@ -65,7 +65,6 @@ const PHYSICAL_CPU = { .required('Physical CPU field is required') .positive() .default(undefined) - .resolve() } const VIRTUAL_CPU = { @@ -74,8 +73,8 @@ const VIRTUAL_CPU = { type: INPUT_TYPES.TEXT, htmlType: 'number', tooltip: ` - Number of virtual cpus. This value is optional, the default - hypervisor behavior is used, usually one virtual CPU.`, + Number of virtual cpus. This value is optional, the default + hypervisor behavior is used, usually one virtual CPU.`, validation: yup .number() .typeError('Virtual CPU value must be a number') diff --git a/src/fireedge/src/client/components/Forms/Vm/index.js b/src/fireedge/src/client/components/Forms/Vm/index.js new file mode 100644 index 0000000000..25a5654699 --- /dev/null +++ b/src/fireedge/src/client/components/Forms/Vm/index.js @@ -0,0 +1,21 @@ +/* ------------------------------------------------------------------------- * + * 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 ResizeCapacityForm from 'client/components/Forms/Vm/ResizeCapacityForm' +export * from 'client/components/Forms/Vm/AttachDiskForm' + +export { + ResizeCapacityForm +} diff --git a/src/fireedge/src/client/components/Header/Group.js b/src/fireedge/src/client/components/Header/Group.js index 166682c9a2..ddac8fc55e 100644 --- a/src/fireedge/src/client/components/Header/Group.js +++ b/src/fireedge/src/client/components/Header/Group.js @@ -75,7 +75,7 @@ const Group = () => { } - buttonProps={{ 'data-cy': 'header-group-button', variant: 'outlined' }} + buttonProps={{ 'data-cy': 'header-group-button' }} headerTitle="Switch group" > {({ handleClose }) => ( diff --git a/src/fireedge/src/client/components/Header/Popover.js b/src/fireedge/src/client/components/Header/Popover.js index 25d3e1d4ea..4b4ce79142 100644 --- a/src/fireedge/src/client/components/Header/Popover.js +++ b/src/fireedge/src/client/components/Header/Popover.js @@ -59,7 +59,9 @@ const HeaderPopover = React.memo(({ aria-controls={anchorId} aria-describedby={anchorId} aria-haspopup='true' + variant='outlined' onClick={handleOpen} + size='small' {...buttonProps} style={{ margin: '0 2px' }} > diff --git a/src/fireedge/src/client/components/Header/User.js b/src/fireedge/src/client/components/Header/User.js index 4535cb833f..5bba942d3b 100644 --- a/src/fireedge/src/client/components/Header/User.js +++ b/src/fireedge/src/client/components/Header/User.js @@ -34,7 +34,7 @@ const User = React.memo(() => { id='user-menu' buttonLabel={user?.NAME} icon={} - buttonProps={{ 'data-cy': 'header-user-button', variant: 'outlined' }} + buttonProps={{ 'data-cy': 'header-user-button' }} disablePadding > {() => ( diff --git a/src/fireedge/src/client/components/Header/View.js b/src/fireedge/src/client/components/Header/View.js index e5bd1411d9..0268f05ed7 100644 --- a/src/fireedge/src/client/components/Header/View.js +++ b/src/fireedge/src/client/components/Header/View.js @@ -55,7 +55,7 @@ const View = () => { } - buttonProps={{ 'data-cy': 'header-view-button', variant: 'outlined' }} + buttonProps={{ 'data-cy': 'header-view-button' }} headerTitle='Switch view' > {({ handleClose }) => ( diff --git a/src/fireedge/src/client/components/Header/Zone.js b/src/fireedge/src/client/components/Header/Zone.js index a3841bab07..8ed3e33980 100644 --- a/src/fireedge/src/client/components/Header/Zone.js +++ b/src/fireedge/src/client/components/Header/Zone.js @@ -27,8 +27,7 @@ const Zone = memo(() => ( id='zone-menu' icon={} buttonProps={{ - 'data-cy': 'header-zone-button', - variant: 'outlined' + 'data-cy': 'header-zone-button' }} disablePadding > diff --git a/src/fireedge/src/client/components/SplitPane/index.js b/src/fireedge/src/client/components/SplitPane/index.js index ccb2f7f35b..fdb6c7bf9c 100644 --- a/src/fireedge/src/client/components/SplitPane/index.js +++ b/src/fireedge/src/client/components/SplitPane/index.js @@ -25,6 +25,9 @@ const useStyles = makeStyles(theme => ({ flexDirection: 'column', height: '100%' }, + topPane: { + flex: 1 + }, separator: { position: 'relative', cursor: 'row-resize', @@ -103,24 +106,28 @@ const SplitPane = ({ children, containerProps }) => { }) React.useEffect(() => { - if (!topHeight) { + if (!topHeight && children[1]) { setTopHeight(document.body.clientHeight / 2) topRef.current.style.flex = 'none' } - topRef.current.style.height = `${topHeight}px` - }, [topHeight]) + topRef.current.style.height = children[1] + ? `${topHeight}px` + : `${splitPaneRef.current?.clientHeight}px` + }, [topHeight, children[1]]) return (
-
+
{children[0]}
- + {!!children[1] && ( + + )} {children[1]}
) diff --git a/src/fireedge/src/client/components/Tables/Datastores/columns.js b/src/fireedge/src/client/components/Tables/Datastores/columns.js index e32757bae7..33e2c11944 100644 --- a/src/fireedge/src/client/components/Tables/Datastores/columns.js +++ b/src/fireedge/src/client/components/Tables/Datastores/columns.js @@ -14,7 +14,7 @@ * limitations under the License. * * ------------------------------------------------------------------------- */ /* eslint-disable jsdoc/require-jsdoc */ -import CategoryFilter from 'client/components/Tables/Enhanced/Utils/CategoryFilter' +import { CategoryFilter } from 'client/components/Tables/Enhanced/Utils' import * as DatastoreModel from 'client/models/Datastore' export default [ 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 28210553ea..a018fa873b 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/CategoryFilter.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/CategoryFilter.js @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -/* eslint-disable jsdoc/require-jsdoc */ import * as React from 'react' import PropTypes from 'prop-types' @@ -23,8 +22,17 @@ import { UseFiltersInstanceProps } from 'react-table' import { Tr } from 'client/components/HOC' -const CategoryFilter = ({ title, column, accessorOption, multiple }) => { - /** @type {UseFiltersInstanceProps} */ +/** + * Render category filter to table. + * + * @param {object} props - Props + * @param {string} props.title - Title category + * @param {UseFiltersInstanceProps} props.column - Column to filter by + * @param {string} [props.accessorOption] - Name of property option + * @param {boolean} [props.multiple] - If `true`, can be more than one filter + * @returns {React.JSXElementConstructor} Component JSX + */ +const CategoryFilter = ({ title, column, accessorOption, multiple = false }) => { const { setFilter, id, 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 10de15525f..35bd907068 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalFilter.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalFilter.js @@ -13,14 +13,13 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -/* eslint-disable jsdoc/require-jsdoc */ -/* eslint-disable jsdoc/check-types */ -/* eslint-disable jsdoc/valid-types */ import * as React from 'react' import PropTypes from 'prop-types' +import clsx from 'clsx' import { makeStyles, fade, debounce, InputBase } from '@material-ui/core' import { Search as SearchIcon } from 'iconoir-react' +import { UseGlobalFiltersInstanceProps, UseGlobalFiltersState } from 'react-table' const useStyles = makeStyles(({ spacing, palette, shape, breakpoints }) => ({ search: { @@ -55,14 +54,21 @@ const useStyles = makeStyles(({ spacing, palette, shape, breakpoints }) => ({ } })) -const GlobalFilter = ({ useTableProps }) => { +/** + * Render search input. + * + * @param {object} props - Props + * @param {string} props.className - Class to wrapper root + * @param {UseGlobalFiltersInstanceProps} props.useTableProps - Table props + * @returns {React.JSXElementConstructor} Component JSX + */ +const GlobalFilter = ({ useTableProps, className }) => { const classes = useStyles() - /** - * @type {import('react-table').UseGlobalFiltersInstanceProps & - * { state: import('react-table').UseGlobalFiltersState }} - */ - const { setGlobalFilter, state: { globalFilter } } = useTableProps + const { setGlobalFilter, state } = useTableProps + + /** @type {UseGlobalFiltersState} */ + const { globalFilter } = state const [value, setValue] = React.useState(() => globalFilter) @@ -72,7 +78,7 @@ const GlobalFilter = ({ useTableProps }) => { ) return ( -
+
@@ -94,6 +100,7 @@ const GlobalFilter = ({ useTableProps }) => { } GlobalFilter.propTypes = { + className: PropTypes.string, useTableProps: PropTypes.object.isRequired } diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSelectedRows.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSelectedRows.js new file mode 100644 index 0000000000..694cd69d30 --- /dev/null +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSelectedRows.js @@ -0,0 +1,65 @@ +/* ------------------------------------------------------------------------- * + * 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 * as React from 'react' +import PropTypes from 'prop-types' + +import { TableProps } from 'react-table' +import { makeStyles, Chip } from '@material-ui/core' + +const useStyles = makeStyles({ + root: { + display: 'flex', + flexWrap: 'wrap', + gap: 6, + alignItems: 'center' + } +}) + +/** + * Render all selected rows. + * + * @param {object} props - Props + * @param {TableProps} props.useTableProps - Table props + * @returns {React.JSXElementConstructor} Component JSX + */ +const GlobalSelectedRows = ({ useTableProps }) => { + const classes = useStyles() + + const { preFilteredRows, state: { selectedRowIds } } = useTableProps + const selectedRows = preFilteredRows.filter(row => !!selectedRowIds[row.id]) + + return ( +
+ {React.useMemo(() => + selectedRows?.map(({ original, id, toggleRowSelected }) => ( + toggleRowSelected(false)} + /> + )), + [selectedRows[0]?.id] + )} +
+ ) +} + +GlobalSelectedRows.propTypes = { + useTableProps: PropTypes.object.isRequired +} + +GlobalSelectedRows.displayName = ' GlobalSelectedRows' + +export default GlobalSelectedRows diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSort.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSort.js index 99568612cd..bc077ddaaa 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSort.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/GlobalSort.js @@ -21,6 +21,7 @@ import PropTypes from 'prop-types' import { makeStyles, MenuItem, MenuList, Chip } from '@material-ui/core' import { SortDown, ArrowDown, ArrowUp } from 'iconoir-react' +import { TableInstance, UseSortByInstanceProps, UseSortByState } from 'react-table' import HeaderPopover from 'client/components/Header/Popover' import { T } from 'client/constants' @@ -34,19 +35,25 @@ const useStyles = makeStyles({ } }) +/** + * Render all selected sorters. + * + * @param {object} props - Props + * @param {TableInstance} props.useTableProps - Table props + * @returns {React.JSXElementConstructor} Component JSX + */ const GlobalSort = ({ useTableProps }) => { const classes = useStyles() - React.useEffect(() => () => setSortBy([]), []) + const { headers, state } = useTableProps - /** - * @type { - * import('react-table').UseSortByInstanceProps & - * import('react-table').TableInstance & - * { state: import('react-table').UseSortByState } - * } - */ - const { headers, setSortBy, state: { sortBy } } = useTableProps + /** @type {UseSortByInstanceProps} */ + const { setSortBy } = useTableProps + + /** @type {UseSortByState} */ + const { sortBy } = state + + React.useEffect(() => () => setSortBy([]), []) const headersNotSorted = React.useMemo(() => headers.filter(({ isSorted, canSort, isVisible }) => @@ -74,8 +81,7 @@ const GlobalSort = ({ useTableProps }) => { buttonLabel={T.SortBy} buttonProps={{ 'data-cy': 'sort-by-button', - disabled: headersNotSorted.length === 0, - variant: 'outlined' + disabled: headersNotSorted.length === 0 }} popoverProps= {{ anchorOrigin: { diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/index.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/index.js index ed7d5fb790..2a03bd71e5 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/index.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/index.js @@ -15,6 +15,7 @@ * ------------------------------------------------------------------------- */ import CategoryFilter from 'client/components/Tables/Enhanced/Utils/CategoryFilter' import GlobalFilter from 'client/components/Tables/Enhanced/Utils/GlobalFilter' +import GlobalSelectedRows from 'client/components/Tables/Enhanced/Utils/GlobalSelectedRows' import GlobalSort from 'client/components/Tables/Enhanced/Utils/GlobalSort' import LabelFilter from 'client/components/Tables/Enhanced/Utils/LabelFilter' @@ -23,6 +24,7 @@ export * from 'client/components/Tables/Enhanced/Utils/utils' export { CategoryFilter, GlobalFilter, + GlobalSelectedRows, GlobalSort, LabelFilter } diff --git a/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js b/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js index 66985f5796..d9a39c6b38 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/Utils/utils.js @@ -13,9 +13,18 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -/* eslint-disable jsdoc/require-jsdoc */ +import { Column } from 'react-table' import { CategoryFilter } from 'client/components/Tables/Enhanced/Utils' +/** + * Add filters defined in view yaml to columns. + * + * @param {object} config - + * @param {object[]} config.filters + * - List of criteria to filter the columns. + * @param {Column[]} config.columns - Columns + * @returns {object} Column with filters + */ export const createColumns = ({ filters = {}, columns = [] }) => { if (Object.keys(filters).length === 0) return columns @@ -25,18 +34,23 @@ export const createColumns = ({ filters = {}, columns = [] }) => { const filterById = !!filters[String(id.toLowerCase())] const filterByAccessor = - typeof accessor === 'string' && - !!filters[String(accessor.toLowerCase())] + typeof accessor === 'string' && + !!filters[String(accessor.toLowerCase())] return { ...column, - ...((filterById || filterByAccessor) && - createCategoryFilter(Header) + ...((filterById || filterByAccessor) && createCategoryFilter(Header) ) } }) } +/** + * Create category filter as column. + * + * @param {string} title - Title + * @returns {Column} - Category filter + */ export const createCategoryFilter = title => ({ disableFilters: false, Filter: ({ column }) => CategoryFilter({ diff --git a/src/fireedge/src/client/components/Tables/Enhanced/filters.js b/src/fireedge/src/client/components/Tables/Enhanced/filters.js index 5bd569fd22..c1edc52e39 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/filters.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/filters.js @@ -21,16 +21,16 @@ import clsx from 'clsx' import { makeStyles, useMediaQuery, Card, CardContent } from '@material-ui/core' import { UseTableInstanceProps } from 'react-table' -import GlobalFilter from 'client/components/Tables/Enhanced/Utils/GlobalFilter' +import { GlobalFilter } from 'client/components/Tables/Enhanced/Utils' const useToolbarStyles = makeStyles({ root: { display: 'flex' }, rootNoFilters: { - gridColumn: '1/3', + gridColumn: '1 / -1', '& ~ div': { - gridColumn: '1/3' + gridColumn: '1 / -1' } }, content: { @@ -47,7 +47,7 @@ const useToolbarStyles = makeStyles({ } }) -const Filters = ({ useTableProps }) => { +const Filters = ({ onlyGlobalSearch, useTableProps }) => { const classes = useToolbarStyles() const isMobile = useMediaQuery(theme => theme.breakpoints.down('sm')) @@ -64,8 +64,13 @@ const Filters = ({ useTableProps }) => { ) : null) ), [rows]) - if (isMobile) { - return + if (isMobile || onlyGlobalSearch) { + return ( + + ) } const noFilters = filters.length === 0 @@ -86,10 +91,12 @@ const Filters = ({ useTableProps }) => { } Filters.propTypes = { + onlyGlobalSearch: PropTypes.bool, useTableProps: PropTypes.object } Filters.defaultProps = { + onlyGlobalSearch: false, useTableProps: {} } diff --git a/src/fireedge/src/client/components/Tables/Enhanced/index.js b/src/fireedge/src/client/components/Tables/Enhanced/index.js index 126734bf53..dcb239fb65 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/index.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/index.js @@ -26,17 +26,17 @@ import { useRowSelect, useSortBy, useTable, + useMountedLayoutEffect, // types UseRowSelectRowProps } from 'react-table' -import SplitPane from 'client/components/SplitPane' import Toolbar from 'client/components/Tables/Enhanced/toolbar' import Pagination from 'client/components/Tables/Enhanced/pagination' import Filters from 'client/components/Tables/Enhanced/filters' import EnhancedTableStyles from 'client/components/Tables/Enhanced/styles' -import { Translate, ConditionalWrap } from 'client/components/HOC' +import { Translate } from 'client/components/HOC' import { T } from 'client/constants' const EnhancedTable = ({ @@ -45,12 +45,15 @@ const EnhancedTable = ({ data, fetchMore, getRowId, + initialState, isLoading, + onlyGlobalSearch, + onlyGlobalSelectedRows, + onSelectedRowsChange, pageSize = 10, - renderAllSelected = true, - renderDetail, RowComponent, - showPageCount + showPageCount, + singleSelect = false }) => { const classes = EnhancedTableStyles() @@ -85,7 +88,8 @@ const EnhancedTable = ({ autoResetSortBy: false, // ------------------------------------- initialState: { - pageSize + pageSize, + ...initialState } }, useGlobalFilter, @@ -98,6 +102,7 @@ const EnhancedTable = ({ const { getTableProps, prepareRow, + toggleAllRowsSelected, preFilteredRows, rows, page, @@ -106,10 +111,11 @@ const EnhancedTable = ({ state: { pageIndex, selectedRowIds } } = useTableProps - const selectedRows = React.useMemo( - () => preFilteredRows.filter(row => !!selectedRowIds[row.id]), - [preFilteredRows, selectedRowIds] - ) + useMountedLayoutEffect(() => { + const selectedRows = preFilteredRows.filter(row => !!selectedRowIds[row.id]) + + onSelectedRowsChange?.(selectedRows) + }, [selectedRowIds]) const handleChangePage = newPage => { gotoPage(newPage) @@ -120,98 +126,100 @@ const EnhancedTable = ({ } return ( - 0} - wrap={children => {children}} - > - -
- {!isFetching && } -
- {page?.length > 0 && ( - - )} -
-
- - {isLoading && ( - + +
+ {/* TOOLBAR */} + {!isFetching && ( + )} -
- {!isFetching && } - -
- {/* NO DATA MESSAGE */} - {!isFetching && page?.length === 0 && ( - - - - - )} - - {/* DATALIST PER PAGE */} - {page.map(row => { - prepareRow(row) - - /** @type {UseRowSelectRowProps} */ - const { getRowProps, original, values, toggleRowSelected, isSelected } = row - const { key, ...rowProps } = getRowProps() - - return ( - toggleRowSelected(!isSelected)} - /> - ) - })} -
+ {/* PAGINATION */} +
+ {page?.length > 0 && ( + + )}
- +
- {selectedRows?.length > 0 && ( -
- {selectedRows?.length === 1 && renderDetail - ? renderDetail?.(selectedRows[0]?.values) - : renderAllSelected && ( -
-                
-                  {JSON.stringify(Object.keys(selectedRowIds)?.join(', '), null, 2)}
-                
-              
- ) - } -
+ {isLoading && ( + )} - + +
+ {/* FILTERS */} + {!isFetching && ( + + )} + +
+ {/* NO DATA MESSAGE */} + {!isFetching && page?.length === 0 && ( + + + + + )} + + {/* DATALIST PER PAGE */} + {page.map(row => { + prepareRow(row) + + /** @type {UseRowSelectRowProps} */ + const { getRowProps, original, values, toggleRowSelected, isSelected } = row + const { key, ...rowProps } = getRowProps() + + return ( + { + singleSelect && toggleAllRowsSelected(false) + toggleRowSelected(!isSelected) + }} + /> + ) + })} +
+
+ ) } -EnhancedTable.propTypes = { +export const EnhancedTableProps = { canFetchMore: PropTypes.bool, columns: PropTypes.array, data: PropTypes.array, fetchMore: PropTypes.func, getRowId: PropTypes.func, + initialState: PropTypes.object, isLoading: PropTypes.bool, + onlyGlobalSearch: PropTypes.bool, + onlyGlobalSelectedRows: PropTypes.bool, + onSelectedRowsChange: PropTypes.func, pageSize: PropTypes.number, - renderAllSelected: PropTypes.bool, - renderDetail: PropTypes.func, RowComponent: PropTypes.oneOfType([ PropTypes.arrayOf(PropTypes.node), PropTypes.node, PropTypes.func ]), - showPageCount: PropTypes.bool + showPageCount: PropTypes.bool, + singleSelect: PropTypes.bool } +EnhancedTable.propTypes = EnhancedTableProps + export default EnhancedTable diff --git a/src/fireedge/src/client/components/Tables/Enhanced/pagination.js b/src/fireedge/src/client/components/Tables/Enhanced/pagination.js index 5af651566e..a04a2e95ee 100644 --- a/src/fireedge/src/client/components/Tables/Enhanced/pagination.js +++ b/src/fireedge/src/client/components/Tables/Enhanced/pagination.js @@ -45,9 +45,10 @@ const Pagination = ({ return ( <> { +const VmsTable = props => { const vms = useVm() const { getVms } = useVmApi() const { view, getResourceView, filterPool } = useAuth() @@ -75,9 +74,12 @@ const VmsTable = () => { isLoading={loading || reloading} getRowId={row => String(row.ID)} RowComponent={VmRow} - renderDetail={row => } + {...props} /> ) } +VmsTable.propTypes = EnhancedTableProps +VmsTable.displayName = 'VmsTable' + export default VmsTable diff --git a/src/fireedge/src/client/components/Tables/Zones/columns.js b/src/fireedge/src/client/components/Tables/Zones/columns.js index 34cc7ce719..58635b5062 100644 --- a/src/fireedge/src/client/components/Tables/Zones/columns.js +++ b/src/fireedge/src/client/components/Tables/Zones/columns.js @@ -14,7 +14,7 @@ * limitations under the License. * * ------------------------------------------------------------------------- */ /* eslint-disable jsdoc/require-jsdoc */ -import CategoryFilter from 'client/components/Tables/Enhanced/Utils/CategoryFilter' +import { CategoryFilter } from 'client/components/Tables/Enhanced/Utils' import * as ZoneModel from 'client/models/Zone' export default [ diff --git a/src/fireedge/src/client/components/Tables/index.js b/src/fireedge/src/client/components/Tables/index.js index b1212be73c..ed4f43aa5c 100644 --- a/src/fireedge/src/client/components/Tables/index.js +++ b/src/fireedge/src/client/components/Tables/index.js @@ -15,7 +15,7 @@ * ------------------------------------------------------------------------- */ import ClustersTable from 'client/components/Tables/Clusters' import DatastoresTable from 'client/components/Tables/Datastores' -import EnhancedTable from 'client/components/Tables/Enhanced' +import EnhancedTable, { EnhancedTableProps } from 'client/components/Tables/Enhanced' import GroupsTable from 'client/components/Tables/Groups' import HostsTable from 'client/components/Tables/Hosts' import ImagesTable from 'client/components/Tables/Images' @@ -34,6 +34,7 @@ import ZonesTable from 'client/components/Tables/Zones' export { SkeletonTable, EnhancedTable, + EnhancedTableProps, VirtualizedTable, ClustersTable, diff --git a/src/fireedge/src/client/components/Tabs/Common/Attribute/Inputs.js b/src/fireedge/src/client/components/Tabs/Common/Attribute/Inputs.js index f1797c473a..8848d4c083 100644 --- a/src/fireedge/src/client/components/Tabs/Common/Attribute/Inputs.js +++ b/src/fireedge/src/client/components/Tabs/Common/Attribute/Inputs.js @@ -61,7 +61,7 @@ const Select = React.forwardRef( margin='dense' onChange={handleChange} select - SelectProps={{ displayEmpty: true, native: true }} + SelectProps={{ native: true }} value={newValue} variant='outlined' > diff --git a/src/fireedge/src/client/components/Tabs/Common/AttributePanel.js b/src/fireedge/src/client/components/Tabs/Common/AttributePanel.js index d7321fdfb5..6d15adc4d4 100644 --- a/src/fireedge/src/client/components/Tabs/Common/AttributePanel.js +++ b/src/fireedge/src/client/components/Tabs/Common/AttributePanel.js @@ -30,6 +30,7 @@ * ------------------------------------------------------------------------- */ import * as React from 'react' import PropTypes from 'prop-types' +import { makeStyles } from '@material-ui/core' import { List } from 'client/components/Tabs/Common' import { ACTIONS } from 'client/constants' @@ -44,6 +45,17 @@ const SPECIAL_ATTRIBUTES = { VCENTER_VERSION: { edit: false, delete: false } } +const useStyles = makeStyles({ + container: { + gridColumn: '1 / -1' + }, + item: { + '& > *:first-child': { + flex: '1 1 20%' + } + } +}) + const AttributePanel = React.memo(({ title, attributes = {}, @@ -52,6 +64,8 @@ const AttributePanel = React.memo(({ handleAdd, actions }) => { + const classes = useStyles() + const formatAttributes = Object.entries(attributes) .map(([name, value]) => ({ name, @@ -68,9 +82,9 @@ const AttributePanel = React.memo(({ return ( renderList(attr))} {/* ADD ACTION */} {handleAdd && ( - + )} diff --git a/src/fireedge/src/client/components/Tabs/Vm/Capacity/index.js b/src/fireedge/src/client/components/Tabs/Vm/Capacity/index.js index 5796e8b2f1..e05cea7127 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Capacity/index.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Capacity/index.js @@ -18,56 +18,35 @@ import * as React from 'react' import PropTypes from 'prop-types' import { useVmApi } from 'client/features/One' -import { useDialog } from 'client/hooks' import { TabContext } from 'client/components/Tabs/TabProvider' -import { DialogForm } from 'client/components/Dialogs' -import FormWithSchema from 'client/components/Forms/FormWithSchema' -import { SCHEMA, FIELDS } from 'client/formSchema/Vm/resize' - import InformationPanel from 'client/components/Tabs/Vm/Capacity/information' import * as VirtualMachine from 'client/models/VirtualMachine' import * as Helper from 'client/models/Helper' -import { T } from 'client/constants' const VmCapacityTab = ({ tabProps: { actions = [] } = {} }) => { - const { display, show, hide } = useDialog() const { resize } = useVmApi() const { handleRefetch, data: vm = {} } = React.useContext(TabContext) - const { ID, TEMPLATE } = vm + const { ID } = vm const hypervisor = VirtualMachine.getHypervisor(vm) const actionsAvailable = Helper.getActionsAvailable(actions, hypervisor) - const handleResize = async formData => { + const handleResizeCapacity = async formData => { const { enforce, ...restOfData } = formData - const template = Helper.jsonToXml({ ROOT: restOfData }) + const template = Helper.jsonToXml(restOfData) const response = await resize(ID, { enforce, template }) String(response) === String(ID) && await handleRefetch?.() - hide() } return ( - <> - - {display && ( - SCHEMA} - values={SCHEMA.cast(TEMPLATE, { stripUnknown: true })} - onCancel={hide} - onSubmit={handleResize} - > - - - )} - + ) } diff --git a/src/fireedge/src/client/components/Tabs/Vm/Capacity/information.js b/src/fireedge/src/client/components/Tabs/Vm/Capacity/information.js index 4d2a547871..b7b1f1b10d 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Capacity/information.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Capacity/information.js @@ -16,51 +16,19 @@ /* eslint-disable jsdoc/require-jsdoc */ import * as React from 'react' import PropTypes from 'prop-types' -import { makeStyles, Paper, Typography, Button } from '@material-ui/core' +import { Paper, Typography } from '@material-ui/core' +import ButtonToTriggerForm from 'client/components/Forms/ButtonToTriggerForm' +import { ResizeCapacityForm } from 'client/components/Forms/Vm' import { Tr } from 'client/components/HOC' +import useCapacityTabStyles from 'client/components/Tabs/Vm/Capacity/styles' import * as VirtualMachine from 'client/models/VirtualMachine' import { prettyBytes } from 'client/utils' import { T, VM_ACTIONS } from 'client/constants' -const useStyles = makeStyles(theme => ({ - root: { - marginBlock: '0.8em', - padding: '1em', - display: 'grid', - gap: '1em', - gridAutoFlow: 'column', - [theme.breakpoints.down('sm')]: { - gridAutoFlow: 'initial' - } - }, - item: { - [theme.breakpoints.down('sm')]: { - display: 'flex', - gap: '1em', - '& > *': { - width: '50%' - } - } - }, - actions: { - [theme.breakpoints.down('sm')]: { - borderBottom: `1px solid ${theme.palette.divider}`, - padding: '1em' - }, - [theme.breakpoints.up('md')]: { - order: 1, - textAlign: 'end' - } - }, - title: { - fontWeight: theme.typography.fontWeightBold - } -})) - -const InformationPanel = ({ actions, vm = {}, handleOpenResizeDialog }) => { - const classes = useStyles() +const InformationPanel = ({ actions, vm = {}, handleResizeCapacity }) => { + const classes = useCapacityTabStyles() const { TEMPLATE } = vm const isVCenter = VirtualMachine.isVCenter(vm) @@ -101,15 +69,12 @@ const InformationPanel = ({ actions, vm = {}, handleOpenResizeDialog }) => {
{actions?.includes?.(VM_ACTIONS.RESIZE_CAPACITY) && ( - + )}
{capacity.map(({ name, value }) => ( @@ -127,7 +92,7 @@ const InformationPanel = ({ actions, vm = {}, handleOpenResizeDialog }) => { } InformationPanel.propTypes = { - handleOpenResizeDialog: PropTypes.function, + handleResizeCapacity: PropTypes.func, actions: PropTypes.array, vm: PropTypes.object } diff --git a/src/fireedge/src/client/components/Tabs/Vm/Capacity/styles.js b/src/fireedge/src/client/components/Tabs/Vm/Capacity/styles.js new file mode 100644 index 0000000000..bf33e6cb61 --- /dev/null +++ b/src/fireedge/src/client/components/Tabs/Vm/Capacity/styles.js @@ -0,0 +1,51 @@ +/* ------------------------------------------------------------------------- * + * 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 { makeStyles } from '@material-ui/core' + +export default makeStyles(theme => ({ + root: { + marginBlock: '0.8em', + padding: '1em', + display: 'grid', + gap: '1em', + gridAutoFlow: 'column', + [theme.breakpoints.down('sm')]: { + gridAutoFlow: 'initial' + } + }, + item: { + [theme.breakpoints.down('sm')]: { + display: 'flex', + gap: '1em', + '& > *': { + width: '50%' + } + } + }, + actions: { + [theme.breakpoints.down('sm')]: { + borderBottom: `1px solid ${theme.palette.divider}`, + padding: '1em' + }, + [theme.breakpoints.up('md')]: { + order: 1, + textAlign: 'end' + } + }, + title: { + fontWeight: theme.typography.fontWeightBold + } +})) diff --git a/src/fireedge/src/client/components/Tabs/Vm/Configuration.js b/src/fireedge/src/client/components/Tabs/Vm/Configuration.js index bb49cb7444..3a54db7c0d 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Configuration.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Configuration.js @@ -21,8 +21,9 @@ import { TabContext } from 'client/components/Tabs/TabProvider' const NavArrowDown = {'>'} -const VmConfigurationTab = data => { - const { data: { TEMPLATE, USER_TEMPLATE } = {} } = React.useContext(TabContext) +const VmConfigurationTab = () => { + const { data: vm = {} } = React.useContext(TabContext) + const { TEMPLATE, USER_TEMPLATE } = vm return (
@@ -44,7 +45,7 @@ const VmConfigurationTab = data => {
-            
+            
               {JSON.stringify(TEMPLATE, null, 2)}
             
           
diff --git a/src/fireedge/src/client/components/Tabs/Vm/Info/index.js b/src/fireedge/src/client/components/Tabs/Vm/Info/index.js index d7da97ab68..bc652a2dcd 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Info/index.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Info/index.js @@ -64,9 +64,9 @@ const VmInfoTab = ({ tabProps = {} }) => { } const handleAttributeInXml = async (newValue, path) => { - const newTemplate = cloneObject({ USER_TEMPLATE }) + const newTemplate = cloneObject(USER_TEMPLATE) - set(newTemplate, `USER_TEMPLATE.${path}`, newValue) + set(newTemplate, path, newValue) const xml = Helper.jsonToXml(newTemplate) diff --git a/src/fireedge/src/client/components/Tabs/Vm/Storage/index.js b/src/fireedge/src/client/components/Tabs/Vm/Storage/index.js index b1eab1bd7e..e3ff073f52 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/Storage/index.js +++ b/src/fireedge/src/client/components/Tabs/Vm/Storage/index.js @@ -16,53 +16,62 @@ /* eslint-disable jsdoc/require-jsdoc */ import * as React from 'react' import PropTypes from 'prop-types' -import { Button } from '@material-ui/core' -import { useDialog } from 'client/hooks' +import { useVmApi } from 'client/features/One' import { TabContext } from 'client/components/Tabs/TabProvider' -import { DialogConfirmation } from 'client/components/Dialogs' + import StorageList from 'client/components/Tabs/Vm/Storage/List' -import { Tr } from 'client/components/HOC' +import ButtonToTriggerForm from 'client/components/Forms/ButtonToTriggerForm' +import { ImageSteps, VolatileSteps } from 'client/components/Forms/Vm' import * as VirtualMachine from 'client/models/VirtualMachine' import * as Helper from 'client/models/Helper' import { T, VM_ACTIONS } from 'client/constants' -const VmStorageTab = ({ tabProps = {} }) => { - const { display, show, hide } = useDialog() - const { data: vm } = React.useContext(TabContext) - const { actions = [] } = tabProps +const VmStorageTab = ({ tabProps: { actions = [] } = {} }) => { + const { attachDisk } = useVmApi() + + const { handleRefetch, data: vm = {} } = React.useContext(TabContext) + const { ID } = vm const disks = VirtualMachine.getDisks(vm) - const hypervisor = VirtualMachine.getHypervisor(vm) const actionsAvailable = Helper.getActionsAvailable(actions, hypervisor) + const handleAttachDisk = async ({ image, advanced, configuration }) => { + const imageSelected = image?.[0] + const root = { ...imageSelected, ...advanced, ...configuration } + + const template = Helper.jsonToXml({ DISK: root }) + + const response = await attachDisk(ID, template) + String(response) === String(ID) && await handleRefetch?.() + } + return ( <> {actionsAvailable?.includes?.(VM_ACTIONS.ATTACH_DISK) && ( - + )} - - {display && ( - -

TODO: should define in view yaml ??

-
- )} ) } diff --git a/src/fireedge/src/client/components/Tabs/Vm/index.js b/src/fireedge/src/client/components/Tabs/Vm/index.js index e42a540c8e..b981829824 100644 --- a/src/fireedge/src/client/components/Tabs/Vm/index.js +++ b/src/fireedge/src/client/components/Tabs/Vm/index.js @@ -16,8 +16,11 @@ /* eslint-disable jsdoc/require-jsdoc */ import * as React from 'react' import PropTypes from 'prop-types' +import { LinearProgress } from '@material-ui/core' +import { useFetch, useSocket } from 'client/hooks' import { useAuth } from 'client/features/Auth' +import { useVmApi } from 'client/features/One' import Tabs from 'client/components/Tabs' import { stringToCamelCase, stringToCamelSpace } from 'client/utils' @@ -45,10 +48,26 @@ const loadTab = tabName => ({ storage: Storage }[tabName]) -const VmTabs = ({ data, handleRefetch }) => { +const VmTabs = React.memo(({ id }) => { + const { getHooksSocket } = useSocket() + const { getVm } = useVmApi() + + const { + data, + fetchRequest, + loading, + error + } = useFetch(getVm, getHooksSocket({ resource: 'vm', id })) + + const handleRefetch = () => fetchRequest(id, { reload: true }) + const [tabsAvailable, setTabs] = React.useState(() => []) const { view, getResourceView } = useAuth() + React.useEffect(() => { + fetchRequest(id) + }, [id]) + React.useEffect(() => { const infoTabs = getResourceView('VM')?.['info-tabs'] ?? {} @@ -66,16 +85,19 @@ const VmTabs = ({ data, handleRefetch }) => { ?.filter(Boolean)) }, [view]) + if ((!data && !error) || loading) { + return + } + return ( ) -} +}) VmTabs.propTypes = { - data: PropTypes.object.isRequired, - handleRefetch: PropTypes.func + id: PropTypes.string.isRequired } VmTabs.displayName = 'VmTabs' diff --git a/src/fireedge/src/client/constants/translates.js b/src/fireedge/src/client/constants/translates.js index 60381e11ed..9ead41bb28 100644 --- a/src/fireedge/src/client/constants/translates.js +++ b/src/fireedge/src/client/constants/translates.js @@ -20,6 +20,7 @@ module.exports = { Next: 'Next', SortBy: 'Sort by', Filter: 'Filter', + Filters: 'Filters', All: 'All', On: 'On', @@ -54,6 +55,8 @@ module.exports = { AddAction: 'Add action', /* questions */ + Yes: 'Yes', + No: 'No', DoYouWantProceed: 'Do you want proceed?', /* Scheduling */ @@ -101,6 +104,7 @@ module.exports = { NoDataAvailable: 'There is no data available', /* steps form */ + AdvancedOptions: 'Advanced options', /* steps form - flow */ ApplicationOverview: 'Application overview', WhereWillItRun: 'Where will it run?', @@ -237,6 +241,8 @@ module.exports = { Memory: 'Memory', CostCpu: 'Cost / CPU', CostMByte: 'Cost / MByte', + /* VM schema - storage */ + Volatile: 'Volatile', /* VM schema - network */ NIC: 'NIC', Alias: 'Alias', diff --git a/src/fireedge/src/client/constants/vm.js b/src/fireedge/src/client/constants/vm.js index eddd3f2986..08746a4dd2 100644 --- a/src/fireedge/src/client/constants/vm.js +++ b/src/fireedge/src/client/constants/vm.js @@ -502,6 +502,14 @@ export const VM_ACTIONS = { UPDATE_CONF: 'update_configuration' } +/** @enum {string} Hypervisors */ +export const HYPERVISORS = { + kvm: 'kvm', + vcenter: 'vcenter', + firecracker: 'firecracker', + lxc: 'lxc' +} + /** * @enum {( * 'none' | diff --git a/src/fireedge/src/client/containers/Images/index.js b/src/fireedge/src/client/containers/Images/index.js index 7ec0660112..838719a275 100644 --- a/src/fireedge/src/client/containers/Images/index.js +++ b/src/fireedge/src/client/containers/Images/index.js @@ -18,9 +18,18 @@ import * as React from 'react' import { Container, Box } from '@material-ui/core' -import * as Tables from 'client/components/Tables' +import { ImagesTable } from 'client/components/Tables' +import Detail from 'client/components/Tables/Images/detail' +import SplitPane from 'client/components/SplitPane' function Images () { + const [selectedRows, onSelectedRowsChange] = React.useState() + + const selectedRowIds = React.useMemo( + () => selectedRows?.map(row => row.id), + [selectedRows] + ) + return ( - + + + + {selectedRows?.length > 0 && ( +
+ {selectedRows?.length === 1 + ? + : ( +
+                  
+                    {JSON.stringify(Object.keys(selectedRowIds)?.join(', '), null, 2)}
+                  
+                
+ ) + } +
+ )} +
) } diff --git a/src/fireedge/src/client/containers/Login/schema.js b/src/fireedge/src/client/containers/Login/schema.js index 3a6bed3e33..2805355fcd 100644 --- a/src/fireedge/src/client/containers/Login/schema.js +++ b/src/fireedge/src/client/containers/Login/schema.js @@ -37,7 +37,7 @@ export const USERNAME = { autoFocus: true, required: true, autoComplete: 'username', - variant: 'outlined' + margin: 'normal' } } @@ -54,7 +54,7 @@ export const PASSWORD = { fieldProps: { required: true, autoComplete: 'current-password', - variant: 'outlined' + margin: 'normal' } } @@ -81,7 +81,7 @@ export const TOKEN = { fieldProps: { autoFocus: true, required: true, - variant: 'outlined' + margin: 'normal' } } @@ -116,7 +116,9 @@ export const GROUP = { .nullable() .default(FILTER_POOL.ALL_RESOURCES), grid: { md: 12 }, - fieldProps: { variant: 'outlined' } + fieldProps: { + margin: 'normal' + } } export const FORM_USER_FIELDS = [USERNAME, PASSWORD, REMEMBER] diff --git a/src/fireedge/src/client/containers/Settings/schema.js b/src/fireedge/src/client/containers/Settings/schema.js index aa5cff26e6..a32fbc8c72 100644 --- a/src/fireedge/src/client/containers/Settings/schema.js +++ b/src/fireedge/src/client/containers/Settings/schema.js @@ -31,9 +31,7 @@ const SCHEME = { .trim() .required('Scheme field is required') .default(DEFAULT_SCHEME), - grid: { md: 12 }, - native: true, - fieldProps: { variant: 'outlined' } + grid: { md: 12 } } const LANGUAGES = { @@ -47,9 +45,7 @@ const LANGUAGES = { .trim() .required('Language field is required') .default(DEFAULT_LANGUAGE), - grid: { md: 12 }, - native: true, - fieldProps: { variant: 'outlined' } + grid: { md: 12 } } const DISABLE_ANIMATIONS = { diff --git a/src/fireedge/src/client/containers/VirtualMachines/index.js b/src/fireedge/src/client/containers/VirtualMachines/index.js index 4d6f148de4..8266be02ea 100644 --- a/src/fireedge/src/client/containers/VirtualMachines/index.js +++ b/src/fireedge/src/client/containers/VirtualMachines/index.js @@ -18,9 +18,16 @@ import * as React from 'react' import { Container, Box } from '@material-ui/core' -import * as Tables from 'client/components/Tables' +import { VmsTable } from 'client/components/Tables' +import VmTabs from 'client/components/Tabs/Vm' +import SplitPane from 'client/components/SplitPane' function VirtualMachines () { + const [selectedRows, onSelectedRowsChange] = React.useState([]) + + const getRowIds = () => + JSON.stringify(selectedRows?.map(row => row.id).join(', '), null, 2) + return ( - + + + + {selectedRows?.length > 0 && ( +
+ {selectedRows?.length === 1 + ? + :
{getRowIds()}
+ } +
+ )} +
) } diff --git a/src/fireedge/src/client/features/One/vm/actions.js b/src/fireedge/src/client/features/One/vm/actions.js index 8399100344..afb54df343 100644 --- a/src/fireedge/src/client/features/One/vm/actions.js +++ b/src/fireedge/src/client/features/One/vm/actions.js @@ -45,4 +45,5 @@ export const rename = createAction('vm/rename', vmService.rename) export const resize = createAction('vm/resize', vmService.resize) export const changePermissions = createAction('vm/chmod', vmService.changePermissions) export const changeOwnership = createAction('vm/chown', vmService.changeOwnership) +export const attachDisk = createAction('vm/attach/disk', vmService.attachDisk) export const detachNic = createAction('vm/detach/nic', vmService.detachNic) diff --git a/src/fireedge/src/client/features/One/vm/hooks.js b/src/fireedge/src/client/features/One/vm/hooks.js index e3ab269b4c..faa0ecebaa 100644 --- a/src/fireedge/src/client/features/One/vm/hooks.js +++ b/src/fireedge/src/client/features/One/vm/hooks.js @@ -44,6 +44,7 @@ export const useVmApi = () => { unwrapDispatch(actions.changePermissions({ id, permissions })), changeOwnership: (id, ownership) => unwrapDispatch(actions.changeOwnership({ id, ownership })), + attachDisk: (id, template) => unwrapDispatch(actions.attachDisk({ id, template })), detachNic: (id, nic) => unwrapDispatch(actions.detachNic({ id, nic })) } } diff --git a/src/fireedge/src/client/features/One/vm/services.js b/src/fireedge/src/client/features/One/vm/services.js index 5559d19a4c..14462773ef 100644 --- a/src/fireedge/src/client/features/One/vm/services.js +++ b/src/fireedge/src/client/features/One/vm/services.js @@ -220,6 +220,28 @@ export const vmService = ({ return res?.data }, + /** + * Attaches a new disk to the virtual machine. + * + * @param {object} params - Request parameters + * @param {string|number} params.id - Virtual machine id + * @param {string} params.template + * - A string containing a single DISK vector attribute + * @returns {number} Virtual machine id + * @throws Fails when response isn't code 200 + */ + attachDisk: async ({ id, template }) => { + const name = Actions.VM_DISK_ATTACH + const command = { name, ...Commands[name] } + const config = requestConfig({ id, template }, command) + + const res = await RestClient.request(config) + + if (!res?.id || res?.id !== httpCodes.ok.id) throw res?.data + + return res?.data + }, + /** * Detaches a network interface from a virtual machine. * diff --git a/src/fireedge/src/client/models/Helper.js b/src/fireedge/src/client/models/Helper.js index f9099bbc64..7884b012f7 100644 --- a/src/fireedge/src/client/models/Helper.js +++ b/src/fireedge/src/client/models/Helper.js @@ -19,11 +19,12 @@ import { j2xParser as Parser } from 'fast-xml-parser' /** * @param {object} json - JSON + * @param {boolean} [addRoot] - Add ROOT element as parent * @returns {string} Xml in string format */ -export const jsonToXml = json => { +export const jsonToXml = (json, addRoot = true) => { const parser = new Parser() - return parser.parse(json) + return parser.parse(addRoot ? { ROOT: json } : json) } /** diff --git a/src/fireedge/src/client/models/VirtualMachine.js b/src/fireedge/src/client/models/VirtualMachine.js index 0eef8de902..27a7f99db1 100644 --- a/src/fireedge/src/client/models/VirtualMachine.js +++ b/src/fireedge/src/client/models/VirtualMachine.js @@ -23,6 +23,7 @@ import { VM_LCM_STATES, NIC_ALIAS_IP_ATTRS, HISTORY_ACTIONS, + HYPERVISORS, T, StateInfo } from 'client/constants' @@ -77,7 +78,7 @@ export const getHypervisor = vm => String(getLastHistory(vm)?.VM_MAD).toLowerCas * @param {object} vm - Virtual machine * @returns {boolean} If the hypervisor is vCenter */ -export const isVCenter = vm => getHypervisor(vm) === 'vcenter' +export const isVCenter = vm => getHypervisor(vm) === HYPERVISORS.vcenter /** * @param {object} vm - Virtual machine