import React, { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import useFormApi from '@data-driven-forms/react-form-renderer/use-form-api'; import useFieldApi from '@data-driven-forms/react-form-renderer/use-field-api'; import { Checkbox, FormGroup, Text, TextVariants, Tile } from '@patternfly/react-core'; import './TargetEnvironment.scss'; const TargetEnvironment = ({ label, isRequired, ...props }) => { const { getState, change } = useFormApi(); const { input } = useFieldApi({ label, isRequired, ...props }); const [ environment, setEnvironment ] = useState({ aws: false, azure: false, gcp: false, vsphere: false, 'guest-image': false, 'image-installer': false, }); useEffect(() => { if (getState()?.values?.[input.name]) { setEnvironment(getState().values[input.name]); } }, []); const handleSetEnvironment = (env) => setEnvironment((prevEnv) => { const newEnv = ({ ...prevEnv, [env]: !prevEnv[env] }); change(input.name, newEnv); return newEnv; }); return ( <> Public cloud } data-testid="target-public">
} onClick={ () => handleSetEnvironment('aws') } isSelected={ environment.aws } isStacked isDisplayLarge /> } onClick={ () => handleSetEnvironment('gcp') } isSelected={ environment.gcp } isStacked isDisplayLarge /> } onClick={ () => handleSetEnvironment('azure') } isSelected={ environment.azure } isStacked isDisplayLarge />
{ /* Disabled until default user or user customization is present */ /* Private cloud } data-testid="target-private"> handleSetEnvironment('vsphere') } aria-label="VMWare checkbox" id="checkbox-vmware" name="VMWare" data-testid="checkbox-vmware" /> */ } Other } data-testid="target-other"> handleSetEnvironment('guest-image') } aria-label="Virtualization guest image checkbox" id="checkbox-guest-image" name="Virtualization guest image" data-testid="checkbox-guest-image" /> { /* Disabled until default user or user customization is present */ /* handleSetEnvironment('image-installer') } aria-label="Bare metal installer checkbox" id="checkbox-image-installer" name="Bare metal installer" data-testid="checkbox-image-installer" /> */ }
); }; TargetEnvironment.propTypes = { label: PropTypes.node, isRequired: PropTypes.bool }; TargetEnvironment.defaultProps = { label: '', isRequired: false }; export default TargetEnvironment;