From 79a4e98d0e2e9a35fd72aa515d4a9d7d93fb378d Mon Sep 17 00:00:00 2001 From: regexowl Date: Mon, 7 Oct 2024 14:17:30 +0200 Subject: [PATCH] Wizard: Fix VMware select and unselect This updates the behaviour of VMware checkbox to make it possible to unselect VMware as a target. How to reproduce: 1. select VMware vSphere checkbox 2. click on Virtual disk radio 3. try to unselect VMware vSphere checkbox Previous behaviour - the checkbox can't be unselected New behaviour - the checkbox can be unselected, removing relevant type of VMware target from imageTypes --- .../steps/ImageOutput/TargetEnvironment.tsx | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Components/CreateImageWizard/steps/ImageOutput/TargetEnvironment.tsx b/src/Components/CreateImageWizard/steps/ImageOutput/TargetEnvironment.tsx index 222254c9..fbb25fe6 100644 --- a/src/Components/CreateImageWizard/steps/ImageOutput/TargetEnvironment.tsx +++ b/src/Components/CreateImageWizard/steps/ImageOutput/TargetEnvironment.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import { Button, @@ -44,7 +44,8 @@ const TargetEnvironment = () => { // TODO: Handle isFetching state (add skeletons) // TODO: Handle isError state (very unlikely...) - const [hasVSphere, setHasVSphere] = useState(false); + const hasVsphere = + environments.includes('vsphere') || environments.includes('vsphere-ova'); const dispatch = useAppDispatch(); const prefetchSources = provisioningApi.usePrefetch('getSourceList'); @@ -191,13 +192,18 @@ const TargetEnvironment = () => { > { - setHasVSphere(!hasVSphere); - handleToggleEnvironment('vsphere-ova'); + 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"