Skip to content

Commit 4f7d0c0

Browse files
committed
Wizard: Swap release select
This replaces deprecated PF4 select with non-deprecated PF5 one.
1 parent a1a56e0 commit 4f7d0c0

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

src/Components/CreateImageWizard/steps/ImageOutput/ReleaseSelect.tsx

+44-23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { ReactElement, useState } from 'react';
22

3-
import { FormGroup } from '@patternfly/react-core';
43
import {
4+
FormGroup,
5+
MenuToggle,
6+
MenuToggleElement,
57
Select,
8+
SelectList,
69
SelectOption,
7-
SelectVariant,
8-
} from '@patternfly/react-core/deprecated';
10+
} from '@patternfly/react-core';
911

1012
import {
1113
RELEASES,
@@ -45,13 +47,15 @@ const ReleaseSelect = () => {
4547
const releases = process.env.IS_ON_PREMISE ? ON_PREM_RELEASES : RELEASES;
4648

4749
const handleSelect = (_event: React.MouseEvent, selection: Distributions) => {
48-
if (!isRhel(selection)) {
49-
dispatch(changeRegistrationType('register-later'));
50-
} else {
51-
dispatch(changeRegistrationType('register-now-rhc'));
50+
if (selection !== ('loader' as Distributions)) {
51+
if (!isRhel(selection)) {
52+
dispatch(changeRegistrationType('register-later'));
53+
} else {
54+
dispatch(changeRegistrationType('register-now-rhc'));
55+
}
56+
dispatch(changeDistribution(selection));
57+
setIsOpen(false);
5258
}
53-
dispatch(changeDistribution(selection));
54-
setIsOpen(false);
5559
};
5660

5761
const handleExpand = () => {
@@ -124,26 +128,43 @@ const ReleaseSelect = () => {
124128
return options;
125129
};
126130

131+
const onToggleClick = () => {
132+
setIsOpen(!isOpen);
133+
};
134+
135+
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
136+
<MenuToggle
137+
ref={toggleRef}
138+
onClick={onToggleClick}
139+
isExpanded={isOpen}
140+
isFullWidth
141+
data-testid="release_select"
142+
>
143+
{releases.get(distribution)}
144+
</MenuToggle>
145+
);
146+
127147
return (
128148
<FormGroup isRequired={true} label="Release">
129149
<Select
130150
ouiaId="release_select"
131-
variant={SelectVariant.single}
132-
onToggle={() => setIsOpen(!isOpen)}
133-
onSelect={handleSelect}
134-
selections={releases.get(distribution)}
135151
isOpen={isOpen}
136-
{...(!showDevelopmentOptions &&
137-
// Hide this for on-prem since the host
138-
// could be centos or fedora
139-
!process.env.IS_ON_PREMISE && {
140-
loadingVariant: {
141-
text: 'Show options for further development of RHEL',
142-
onClick: handleExpand,
143-
},
144-
})}
152+
selected={releases.get(distribution)}
153+
onSelect={handleSelect}
154+
toggle={toggle}
155+
shouldFocusToggleOnSelect
145156
>
146-
{setSelectOptions()}
157+
<SelectList>
158+
{setSelectOptions()}
159+
{!showDevelopmentOptions &&
160+
// Hide this for on-prem since the host
161+
// could be centos or fedora
162+
!process.env.IS_ON_PREMISE && (
163+
<SelectOption onClick={handleExpand} value="loader" isLoadButton>
164+
Show options for further development of RHEL
165+
</SelectOption>
166+
)}
167+
</SelectList>
147168
</Select>
148169
</FormGroup>
149170
);

src/test/Components/CreateImageWizard/steps/ImageOutput/ImageOutput.test.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@ let router: RemixRouter | undefined = undefined;
4545

4646
const openReleaseMenu = async () => {
4747
const user = userEvent.setup();
48-
const releaseMenu = screen.getAllByRole('button', {
49-
name: /options menu/i,
50-
})[0];
48+
const releaseMenu = screen.getByTestId('release_select');
5149
await waitFor(() => user.click(releaseMenu));
5250
};
5351

5452
const clickShowOptions = async () => {
5553
const user = userEvent.setup();
56-
const showOptions = await screen.findByRole('button', {
54+
const showOptions = await screen.findByRole('option', {
5755
name: /show options for further development of rhel/i,
5856
});
5957
await waitFor(() => user.click(showOptions));
@@ -220,7 +218,7 @@ describe('Step Image output', () => {
220218
await screen.findAllByRole('option', {
221219
name: /Red Hat Enterprise Linux \(RHEL\) 9/,
222220
});
223-
await screen.findByRole('button', {
221+
await screen.findByRole('option', {
224222
name: 'Show options for further development of RHEL',
225223
});
226224
});
@@ -229,7 +227,7 @@ describe('Step Image output', () => {
229227
await renderCreateMode();
230228
await openReleaseMenu();
231229

232-
const showOptionsButton = await screen.findByRole('button', {
230+
const showOptionsButton = await screen.findByRole('option', {
233231
name: 'Show options for further development of RHEL',
234232
});
235233
user.click(showOptionsButton);

0 commit comments

Comments
 (0)