Skip to content

Commit e10546a

Browse files
committed
Wizard: Swap FSC selects for non-deprecated version
This swaps deprecated PF4 Selects on FSC step for non-deprecated PF5 ones.
1 parent e846816 commit e10546a

File tree

2 files changed

+79
-36
lines changed

2 files changed

+79
-36
lines changed

src/Components/CreateImageWizard/steps/FileSystem/FileSystemTable.tsx

+68-21
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ import {
77
Button,
88
Alert,
99
TextInput,
10+
Select,
11+
MenuToggleElement,
12+
MenuToggle,
13+
SelectList,
14+
SelectOption,
1015
} from '@patternfly/react-core';
11-
import { Select, SelectOption } from '@patternfly/react-core/deprecated';
1216
import { HelpIcon, MinusCircleIcon } from '@patternfly/react-icons';
1317
import styles from '@patternfly/react-styles/css/components/Table/table';
1418
import {
@@ -163,6 +167,8 @@ export const mountpointPrefixes = [
163167
'/var',
164168
];
165169

170+
const units = ['GiB', 'MiB', 'KiB'];
171+
166172
type MountpointPrefixPropTypes = {
167173
partition: Partition;
168174
};
@@ -173,10 +179,6 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
173179
const prefix = getPrefix(partition.mountpoint);
174180
const suffix = getSuffix(partition.mountpoint);
175181

176-
const onToggle = (isOpen: boolean) => {
177-
setIsOpen(isOpen);
178-
};
179-
180182
const onSelect = (event: React.MouseEvent, selection: string) => {
181183
setIsOpen(false);
182184
const mountpoint = selection + (suffix.length > 0 ? '/' + suffix : '');
@@ -185,18 +187,42 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
185187
);
186188
};
187189

190+
const onToggleClick = () => {
191+
setIsOpen(!isOpen);
192+
};
193+
194+
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
195+
<MenuToggle
196+
ref={toggleRef}
197+
onClick={onToggleClick}
198+
isExpanded={isOpen}
199+
isDisabled={prefix === '/'}
200+
data-testid="prefix-select"
201+
isFullWidth
202+
>
203+
{prefix}
204+
</MenuToggle>
205+
);
206+
188207
return (
189208
<Select
190209
ouiaId="mount-point"
191210
isOpen={isOpen}
192-
onToggle={(_event, isOpen) => onToggle(isOpen)}
211+
selected={prefix}
193212
onSelect={onSelect}
194-
selections={prefix}
195-
isDisabled={prefix === '/'}
213+
onOpenChange={(isOpen) => setIsOpen(isOpen)}
214+
toggle={toggle}
215+
shouldFocusToggleOnSelect
196216
>
197-
{mountpointPrefixes.map((prefix, index) => {
198-
return <SelectOption key={index} value={prefix} />;
199-
})}
217+
<SelectList>
218+
{mountpointPrefixes.map((prefix, index) => {
219+
return (
220+
<SelectOption key={index} value={prefix}>
221+
{prefix}
222+
</SelectOption>
223+
);
224+
})}
225+
</SelectList>
200226
</Select>
201227
);
202228
};
@@ -291,10 +317,6 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
291317
const dispatch = useAppDispatch();
292318
const [isOpen, setIsOpen] = useState(false);
293319

294-
const onToggle = (isOpen: boolean) => {
295-
setIsOpen(isOpen);
296-
};
297-
298320
const initialValue = useRef(partition).current;
299321

300322
const onSelect = (event: React.MouseEvent, selection: Units) => {
@@ -310,18 +332,43 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
310332
setIsOpen(false);
311333
};
312334

335+
const onToggleClick = () => {
336+
setIsOpen(!isOpen);
337+
};
338+
339+
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
340+
<MenuToggle
341+
ref={toggleRef}
342+
onClick={onToggleClick}
343+
isExpanded={isOpen}
344+
data-testid="unit-select"
345+
>
346+
{partition.unit}
347+
</MenuToggle>
348+
);
349+
313350
return (
314351
<Select
315352
ouiaId="unit"
316353
isOpen={isOpen}
317-
onToggle={(_event, isOpen) => onToggle(isOpen)}
354+
selected={partition.unit}
318355
onSelect={onSelect}
319-
selections={partition.unit}
356+
onOpenChange={(isOpen) => setIsOpen(isOpen)}
357+
toggle={toggle}
358+
shouldFocusToggleOnSelect
320359
>
321-
<SelectOption value={'KiB'} />
322-
<SelectOption value={'MiB'} />
323-
<SelectOption value={'GiB'} />
324-
<>{initialValue.unit === 'B' && <SelectOption value={'B'} />}</>
360+
<SelectList>
361+
{units.map((unit, index) => (
362+
<SelectOption key={index} value={unit}>
363+
{unit}
364+
</SelectOption>
365+
))}
366+
<>
367+
{initialValue.unit === 'B' && (
368+
<SelectOption value={'B'}>B</SelectOption>
369+
)}
370+
</>
371+
</SelectList>
325372
</Select>
326373
);
327374
};

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

+11-15
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,19 @@ const changePartitionSize = async () => {
8888
const changePartitionUnitsToKiB = async () => {
8989
const user = userEvent.setup();
9090
const row = await getRow(1);
91-
const units = await within(row).findAllByRole('button', {
92-
name: /options menu/i,
93-
});
94-
await waitFor(() => user.click(units[1]));
95-
const mibibytes = await screen.findByText('KiB');
96-
await waitFor(() => user.click(mibibytes));
91+
const units = await within(row).findByTestId('unit-select');
92+
await waitFor(() => user.click(units));
93+
const kibOption = await screen.findByRole('option', { name: 'KiB' });
94+
await waitFor(() => user.click(kibOption));
9795
};
9896

9997
const changePartitionUnitsToMiB = async () => {
10098
const user = userEvent.setup();
10199
const row = await getRow(1);
102-
const units = await within(row).findAllByRole('button', {
103-
name: /options menu/i,
104-
});
105-
await waitFor(() => user.click(units[1]));
106-
const mibibytes = await screen.findByText('MiB');
107-
await waitFor(() => user.click(mibibytes));
100+
const units = await within(row).findByTestId('unit-select');
101+
await waitFor(() => user.click(units));
102+
const mibOption = await screen.findByRole('option', { name: 'MiB' });
103+
await waitFor(() => user.click(mibOption));
108104
};
109105

110106
const goToReviewStep = async () => {
@@ -191,9 +187,9 @@ describe('Step File system configuration', () => {
191187
expect(rows).toHaveLength(3);
192188

193189
//Change mountpoint of final row to /var, resolving errors
194-
const mountPointOptions = within(rows[2]).getAllByRole('button', {
195-
name: 'Options menu',
196-
})[0];
190+
const mountPointOptions = await within(rows[2]).findByTestId(
191+
'prefix-select'
192+
);
197193
user.click(mountPointOptions);
198194
const varButton = await within(rows[2]).findByRole('option', {
199195
name: '/var',

0 commit comments

Comments
 (0)