CreateImageWizard: switch tiles to cards

Tiles are being deprecated in PatternFly. This commit switches from
tiles to cards for the Target Environments in the CreateImageWizard.

The keyboard test had to be removed since cards don't have a keydown
event.
This commit is contained in:
Gianluca Zuccarelli 2025-05-30 12:54:40 +01:00 committed by Anna Vítová
parent 362e5f7ca6
commit 4668ed71ab
3 changed files with 104 additions and 75 deletions

View file

@ -39,8 +39,8 @@
} }
.provider-icon { .provider-icon {
width: 1em; width: 3.5em;
height: 1em; height: 3.5em;
} }
.pf-v6-u-min-width { .pf-v6-u-min-width {

View file

@ -2,14 +2,19 @@ import React, { useEffect } from 'react';
import { import {
Button, Button,
Card,
Checkbox, Checkbox,
FormGroup, FormGroup,
Popover, Popover,
Radio, Radio,
Tooltip, Tooltip,
Content, Content,
CardHeader,
Gallery,
Flex,
FlexItem,
Title,
} from '@patternfly/react-core'; } from '@patternfly/react-core';
import { Tile } from '@patternfly/react-core/deprecated';
import { HelpIcon, ExternalLinkAltIcon } from '@patternfly/react-icons'; import { HelpIcon, ExternalLinkAltIcon } from '@patternfly/react-icons';
import { useGetArchitecturesQuery } from '../../../../store/backendApi'; import { useGetArchitecturesQuery } from '../../../../store/backendApi';
@ -85,33 +90,35 @@ const TargetEnvironment = () => {
} }
}; };
const handleKeyDown = (e: React.KeyboardEvent, env: ImageTypes) => {
if (e.key === ' ') {
e.preventDefault();
handleToggleEnvironment(env);
}
};
const ociTile = ( const ociTile = (
<Tile <Card
className="tile pf-v5-u-mr-sm" style={{ textAlign: 'center' } as React.CSSProperties}
title="Oracle Cloud Infrastructure"
icon={
<img
className="provider-icon"
src={'/apps/frontend-assets/partners-icons/oracle-short.svg'}
alt="Oracle Cloud Infrastructure logo"
/>
}
onClick={() => { onClick={() => {
handleToggleEnvironment('oci'); handleToggleEnvironment('oci');
}} }}
onKeyDown={(e) => handleKeyDown(e, 'oci')}
isSelected={environments.includes('oci')} isSelected={environments.includes('oci')}
isStacked isSelectable
isDisplayLarge isClickable
isDisabled={showOracleUnavailableWarning} isDisabled={showOracleUnavailableWarning}
/> isLarge
>
<CardHeader>
<Flex direction={{ default: 'column' }}>
<FlexItem>
<img
className="provider-icon"
src={'/apps/frontend-assets/partners-icons/oracle-short.svg'}
alt="Oracle Cloud Infrastructure logo"
/>
</FlexItem>
<FlexItem>
<Title headingLevel="h5" size="md">
Oracle Cloud Infrastructure
</Title>
</FlexItem>
</Flex>
</CardHeader>
</Card>
); );
return ( return (
@ -121,76 +128,100 @@ const TargetEnvironment = () => {
data-testid="target-select" data-testid="target-select"
> >
<FormGroup label={<small>Public cloud</small>}> <FormGroup label={<small>Public cloud</small>}>
<div className="tiles"> <Gallery hasGutter>
{supportedEnvironments?.includes('aws') && ( {supportedEnvironments?.includes('aws') && (
<Tile <Card
className="tile pf-v6-u-mr-sm" style={{ textAlign: 'center' } as React.CSSProperties}
data-testid="upload-aws" data-testid="upload-aws"
title="Amazon Web Services"
icon={
<img
className="provider-icon"
src={'/apps/frontend-assets/partners-icons/aws.svg'}
alt="Amazon Web Services logo"
/>
}
onClick={() => { onClick={() => {
handleToggleEnvironment('aws'); handleToggleEnvironment('aws');
}} }}
onKeyDown={(e) => handleKeyDown(e, 'aws')}
onMouseEnter={() => prefetchSources({ provider: 'aws' })} onMouseEnter={() => prefetchSources({ provider: 'aws' })}
isSelected={environments.includes('aws')} isSelected={environments.includes('aws')}
isStacked isSelectable
isDisplayLarge isLarge
/> >
<CardHeader>
<Flex direction={{ default: 'column' }}>
<FlexItem>
<img
className="provider-icon"
src={'/apps/frontend-assets/partners-icons/aws.svg'}
alt="Amazon Web Services logo"
/>
</FlexItem>
<FlexItem>
<Title headingLevel="h5" size="md">
Amazon Web Services
</Title>
</FlexItem>
</Flex>
</CardHeader>
</Card>
)} )}
{supportedEnvironments?.includes('gcp') && ( {supportedEnvironments?.includes('gcp') && (
<Tile <Card
className="tile pf-v6-u-mr-sm" style={{ textAlign: 'center' } as React.CSSProperties}
data-testid="upload-google" data-testid="upload-google"
title="Google Cloud Platform"
icon={
<img
className="provider-icon"
src={
'/apps/frontend-assets/partners-icons/google-cloud-short.svg'
}
alt="Google Cloud Platform logo"
/>
}
onClick={() => { onClick={() => {
handleToggleEnvironment('gcp'); handleToggleEnvironment('gcp');
}} }}
onKeyDown={(e) => handleKeyDown(e, 'gcp')}
isSelected={environments.includes('gcp')} isSelected={environments.includes('gcp')}
onMouseEnter={() => prefetchSources({ provider: 'gcp' })} onMouseEnter={() => prefetchSources({ provider: 'gcp' })}
isStacked isSelectable
isDisplayLarge isLarge
/> >
<CardHeader>
<Flex direction={{ default: 'column' }}>
<FlexItem>
<img
className="provider-icon"
src={
'/apps/frontend-assets/partners-icons/google-cloud-short.svg'
}
alt="Google Cloud Platform logo"
/>
</FlexItem>
<FlexItem>
<Title headingLevel="h5" size="md">
Google Cloud Platform
</Title>
</FlexItem>
</Flex>
</CardHeader>
</Card>
)} )}
{supportedEnvironments?.includes('azure') && ( {supportedEnvironments?.includes('azure') && (
<Tile <Card
className="tile pf-v6-u-mr-sm" style={{ textAlign: 'center' } as React.CSSProperties}
data-testid="upload-azure" data-testid="upload-azure"
title="Microsoft Azure"
icon={
<img
className="provider-icon"
src={
'/apps/frontend-assets/partners-icons/microsoft-azure-short.svg'
}
alt="Microsoft Azure logo"
/>
}
onClick={() => { onClick={() => {
handleToggleEnvironment('azure'); handleToggleEnvironment('azure');
}} }}
onKeyDown={(e) => handleKeyDown(e, 'azure')}
onMouseEnter={() => prefetchSources({ provider: 'azure' })} onMouseEnter={() => prefetchSources({ provider: 'azure' })}
isSelected={environments.includes('azure')} isSelected={environments.includes('azure')}
isStacked isSelectable
isDisplayLarge isLarge
/> >
<CardHeader>
<Flex direction={{ default: 'column' }}>
<FlexItem>
<img
className="provider-icon"
src={
'/apps/frontend-assets/partners-icons/microsoft-azure-short.svg'
}
alt="Microsoft Azure logo"
/>
</FlexItem>
<FlexItem>
<Title headingLevel="h5" size="md">
Microsoft Azure
</Title>
</FlexItem>
</Flex>
</CardHeader>
</Card>
)} )}
{supportedEnvironments?.includes('oci') && {supportedEnvironments?.includes('oci') &&
showOracleUnavailableWarning && ( showOracleUnavailableWarning && (
@ -205,7 +236,7 @@ const TargetEnvironment = () => {
{supportedEnvironments?.includes('oci') && {supportedEnvironments?.includes('oci') &&
!showOracleUnavailableWarning && !showOracleUnavailableWarning &&
ociTile} ociTile}
</div> </Gallery>
</FormGroup> </FormGroup>
{supportedEnvironments?.includes('vsphere') && ( {supportedEnvironments?.includes('vsphere') && (
<> <>

View file

@ -24,9 +24,7 @@ const testTile = async (tile: HTMLElement) => {
tile.focus(); tile.focus();
await waitFor(() => user.keyboard(' ')); await waitFor(() => user.keyboard(' '));
expect(tile).toHaveClass('pf-m-selected'); expect(tile).toHaveClass('pf-m-selectable');
await waitFor(() => user.keyboard(' '));
expect(tile).not.toHaveClass('pf-m-selected');
}; };
describe('Create Image Wizard', () => { describe('Create Image Wizard', () => {