From 730554dc84afc6787dacb193d0e73d51f608057b Mon Sep 17 00:00:00 2001 From: regexowl Date: Tue, 29 Jul 2025 13:25:57 +0200 Subject: [PATCH] Wizard: Add fetch and error state or target environments This renders an empty state with a spinner when fetching target environments and alert when there's an issue. --- .../components/TargetEnvironment.tsx | 30 +++++++++++++++---- .../steps/Services/Services.test.tsx | 2 -- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Components/CreateImageWizard/steps/ImageOutput/components/TargetEnvironment.tsx b/src/Components/CreateImageWizard/steps/ImageOutput/components/TargetEnvironment.tsx index e6b121dc..029f7678 100644 --- a/src/Components/CreateImageWizard/steps/ImageOutput/components/TargetEnvironment.tsx +++ b/src/Components/CreateImageWizard/steps/ImageOutput/components/TargetEnvironment.tsx @@ -1,16 +1,19 @@ import React, { MouseEventHandler, useEffect } from 'react'; import { + Alert, Button, Card, CardHeader, Checkbox, Content, + EmptyState, Flex, FlexItem, FormGroup, Gallery, Popover, + Spinner, Title, } from '@patternfly/react-core'; import { ExternalLinkAltIcon, HelpIcon } from '@patternfly/react-icons'; @@ -92,11 +95,9 @@ const TargetEnvironment = () => { const environments = useAppSelector(selectImageTypes); const distribution = useAppSelector(selectDistribution); - const { data } = useGetArchitecturesQuery({ + const { data, isFetching, isError } = useGetArchitecturesQuery({ distribution: distribution, }); - // TODO: Handle isFetching state (add skeletons) - // TODO: Handle isError state (very unlikely...) const dispatch = useAppDispatch(); const prefetchSources = provisioningApi.usePrefetch('getSourceList'); @@ -104,6 +105,9 @@ const TargetEnvironment = () => { useEffect(() => { prefetchActivationKeys(); + // This useEffect hook should run *only* on mount and therefore has an empty + // dependency array. eslint's exhaustive-deps rule does not support this use. + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const supportedEnvironments = data?.find( @@ -137,6 +141,22 @@ const TargetEnvironment = () => { ); }; + if (isFetching) { + return + }; + + if (isError) { + return ( + + Target environments couldn't be loaded, please refresh the page or try again later. + + ) + }; + return ( { label={Private cloud} className="pf-v6-u-mt-sm" > - {supportedEnvironments?.includes('vsphere-ova') && ( + {supportedEnvironments.includes('vsphere-ova') && ( { isChecked={environments.includes('vsphere-ova')} /> )} - {supportedEnvironments?.includes('vsphere') && ( + {supportedEnvironments.includes('vsphere') && ( { expect(receivedRequest).toEqual(expectedRequest); }); }); - -// TO DO 'Services step' -> 'revisit step button on Review works'