import React from 'react'; import { Button, Checkbox, FormGroup, Popover, Radio, Text, TextContent, TextVariants, Tile, } from '@patternfly/react-core'; import { HelpIcon } from '@patternfly/react-icons'; import { useFlag } from '@unleash/proxy-client-react'; import { useAppSelector, useAppDispatch } from '../../../../store/hooks'; import { ImageTypes, useGetArchitecturesQuery, } from '../../../../store/imageBuilderApi'; import { provisioningApi } from '../../../../store/provisioningApi'; import { addImageType, reinitializeAws, reinitializeAzure, reinitializeGcp, removeImageType, selectArchitecture, selectDistribution, selectImageTypes, } from '../../../../store/wizardSlice'; const TargetEnvironment = () => { const arch = useAppSelector(selectArchitecture); const environments = useAppSelector(selectImageTypes); const distribution = useAppSelector(selectDistribution); const wslFlag = useFlag('image-builder.wsl.enabled'); const { data } = useGetArchitecturesQuery({ distribution: distribution, }); // TODO: Handle isFetching state (add skeletons) // TODO: Handle isError state (very unlikely...) const hasVsphere = environments.includes('vsphere') || environments.includes('vsphere-ova'); const dispatch = useAppDispatch(); const prefetchSources = provisioningApi.usePrefetch('getSourceList'); const supportedEnvironments = data?.find( (elem) => elem.arch === arch )?.image_types; const handleToggleEnvironment = (environment: ImageTypes) => { if (environments.includes(environment)) { switch (environment) { case 'aws': dispatch(reinitializeAws()); break; case 'azure': dispatch(reinitializeAzure()); break; case 'gcp': dispatch(reinitializeGcp()); } dispatch(removeImageType(environment)); } else { dispatch(addImageType(environment)); } }; const handleKeyDown = (e: React.KeyboardEvent, env: ImageTypes) => { if (e.key === ' ') { e.preventDefault(); handleToggleEnvironment(env); } }; return ( Public cloud} data-testid="target-public" >
{supportedEnvironments?.includes('aws') && ( } onClick={() => { handleToggleEnvironment('aws'); }} onKeyDown={(e) => handleKeyDown(e, 'aws')} onMouseEnter={() => prefetchSources({ provider: 'aws' })} isSelected={environments.includes('aws')} isStacked isDisplayLarge /> )} {supportedEnvironments?.includes('gcp') && ( } onClick={() => { handleToggleEnvironment('gcp'); }} onKeyDown={(e) => handleKeyDown(e, 'gcp')} isSelected={environments.includes('gcp')} onMouseEnter={() => prefetchSources({ provider: 'gcp' })} isStacked isDisplayLarge /> )} {supportedEnvironments?.includes('azure') && ( } onClick={() => { handleToggleEnvironment('azure'); }} onKeyDown={(e) => handleKeyDown(e, 'azure')} onMouseEnter={() => prefetchSources({ provider: 'azure' })} isSelected={environments.includes('azure')} isStacked isDisplayLarge /> )} {supportedEnvironments?.includes('oci') && ( } onClick={() => { handleToggleEnvironment('oci'); }} onKeyDown={(e) => handleKeyDown(e, 'oci')} isSelected={environments.includes('oci')} isStacked isDisplayLarge /> )}
{supportedEnvironments?.includes('vsphere') && ( <> Private cloud} className="pf-u-mt-sm" data-testid="target-private" > { if (!hasVsphere) { dispatch(addImageType('vsphere-ova')); } else { if (environments.includes('vsphere')) { dispatch(removeImageType('vsphere')); } if (environments.includes('vsphere-ova')) { dispatch(removeImageType('vsphere-ova')); } } }} aria-label="VMware checkbox" id="checkbox-vmware" name="VMware" data-testid="checkbox-vmware" body={ <> {supportedEnvironments?.includes('vsphere-ova') && ( Open virtualization format (.ova) An OVA file is a virtual appliance used by virtualization platforms such as VMware vSphere. It is a package that contains files used to describe a virtual machine, which includes a VMDK image, OVF descriptor file and a manifest file. } > } onChange={() => { handleToggleEnvironment('vsphere-ova'); handleToggleEnvironment('vsphere'); }} isChecked={environments.includes('vsphere-ova')} isDisabled={ !( environments.includes('vsphere') || environments.includes('vsphere-ova') ) } /> )} Virtual disk (.vmdk) A VMDK file is a virtual disk that stores the contents of a virtual machine. This disk has to be imported into vSphere using govc import.vmdk, use the OVA version when using the vSphere UI. } > } onChange={() => { handleToggleEnvironment('vsphere-ova'); handleToggleEnvironment('vsphere'); }} isChecked={environments.includes('vsphere')} isDisabled={ !( environments.includes('vsphere') || environments.includes('vsphere-ova') ) } /> } /> )} Other} data-testid="target-other" > {supportedEnvironments?.includes('guest-image') && ( { handleToggleEnvironment('guest-image'); }} aria-label="Virtualization guest image checkbox" id="checkbox-guest-image" name="Virtualization guest image" data-testid="checkbox-guest-image" /> )} {supportedEnvironments?.includes('image-installer') && ( { handleToggleEnvironment('image-installer'); }} aria-label="Bare metal installer checkbox" id="checkbox-image-installer" name="Bare metal installer" data-testid="checkbox-image-installer" /> )} {supportedEnvironments?.includes('wsl') && wslFlag && ( { handleToggleEnvironment('wsl'); }} aria-label="windows subsystem for linux checkbox" id="checkbox-wsl" name="WSL" data-testid="checkbox-wsl" /> )}
); }; export default TargetEnvironment;