import React, { useState, useEffect } from 'react'; import { PageSection, Divider, Tabs, Tab, TabTitleText, } from '@patternfly/react-core'; import { translate as __ } from 'foremanReact/common/I18n'; import PropTypes from 'prop-types'; import { networkSelected } from './ProxmoxVmUtils'; import ProxmoxComputeSelectors from './ProxmoxComputeSelectors'; import ProxmoxServerStorage from './ProxmoxServer/ProxmoxServerStorage'; import ProxmoxServerOptions from './ProxmoxServer/ProxmoxServerOptions'; import ProxmoxServerNetwork from './ProxmoxServer/ProxmoxServerNetwork'; import ProxmoxServerHardware from './ProxmoxServer/ProxmoxServerHardware'; import ProxmoxContainerNetwork from './ProxmoxContainer/ProxmoxContainerNetwork'; import ProxmoxContainerOptions from './ProxmoxContainer/ProxmoxContainerOptions'; import ProxmoxContainerStorage from './ProxmoxContainer/ProxmoxContainerStorage'; import ProxmoxContainerHardware from './ProxmoxContainer/ProxmoxContainerHardware'; import InputField from './common/FormInputs'; import GeneralTabContent from './GeneralTabContent'; const ProxmoxVmType = ({ vmAttrs, nodes, images, pools, fromProfile, newVm, storages, bridges, registerComp, untemplatable, }) => { const nodesMap = nodes.length > 0 ? nodes.map(node => ({ value: node.node, label: node.node })) : []; const imagesMap = images.length > 0 ? [ { value: '', label: '' }, ...images.map(image => ({ value: image.uuid, label: image.name, })), ] : []; const poolsMap = pools.length > 0 ? [ { value: '', label: '' }, ...pools.map(pool => ({ value: pool.poolid, label: pool.poolid, })), ] : []; const [activeTabKey, setActiveTabKey] = useState(0); const handleTabClick = (event, tabIndex) => { setActiveTabKey(tabIndex); }; const [general, setGeneral] = useState(vmAttrs); const paramScope = fromProfile ? 'compute_attribute[vm_attrs]' : 'host[compute_attributes]'; const [filteredBridges, setFilteredBridges] = useState([]); useEffect(() => { if (!registerComp && !fromProfile) { networkSelected(general?.type?.value); } }, [general?.type?.value]); useEffect(() => { if (!registerComp) { const filtered = bridges.filter( bridge => bridge.node_id === general?.nodeId?.value ); setFilteredBridges(filtered); } }, [general?.nodeId?.value, bridges]); if (registerComp) { return null; } const componentMap = { qemu: { options: , hardware: , network: ( ), storage: ( ), }, lxc: { options: ( ), hardware: , network: ( ), storage: ( ), }, }; const handleChange = e => { const { name, type, checked, value: targetValue } = e.target; let value; if (type === 'checkbox') { value = checked ? '1' : '0'; } else { value = targetValue; } const updatedKey = Object.keys(general).find( key => general[key].name === name ); setGeneral(prevGeneral => ({ ...prevGeneral, [updatedKey]: { ...prevGeneral[updatedKey], value }, })); }; return (
{__('General')}} aria-label="Default content - general" > {__('Advanced Options')}} aria-label="advanced options" > {componentMap[general?.type?.value]?.options} {__('Hardware')}} aria-label="hardware" > {componentMap[general?.type?.value]?.hardware} {fromProfile && ( {__('Network Interfaces')}} aria-label="Network interface" > {componentMap[general?.type?.value]?.network} )} {__('Storage')}} aria-label="storage" > {componentMap[general?.type?.value]?.storage}
); }; ProxmoxVmType.propTypes = { vmAttrs: PropTypes.object, nodes: PropTypes.array, images: PropTypes.array, pools: PropTypes.array, fromProfile: PropTypes.bool, newVm: PropTypes.bool, storages: PropTypes.array, bridges: PropTypes.array, registerComp: PropTypes.bool, untemplatable: PropTypes.bool, }; ProxmoxVmType.defaultProps = { vmAttrs: {}, nodes: [], images: [], pools: [], fromProfile: false, newVm: false, storages: [], bridges: [], registerComp: false, untemplatable: false, }; export default ProxmoxVmType;