Wizard: Swap FSC selects for non-deprecated version

This swaps deprecated PF4 Selects on FSC step for non-deprecated PF5 ones.
This commit is contained in:
regexowl 2025-02-17 09:51:26 +01:00 committed by Lucas Garfield
parent 2127476f98
commit dcd1bb6fc9
2 changed files with 79 additions and 36 deletions

View file

@ -7,8 +7,12 @@ import {
Button, Button,
Alert, Alert,
TextInput, TextInput,
Select,
MenuToggleElement,
MenuToggle,
SelectList,
SelectOption,
} from '@patternfly/react-core'; } from '@patternfly/react-core';
import { Select, SelectOption } from '@patternfly/react-core/deprecated';
import { HelpIcon, MinusCircleIcon } from '@patternfly/react-icons'; import { HelpIcon, MinusCircleIcon } from '@patternfly/react-icons';
import styles from '@patternfly/react-styles/css/components/Table/table'; import styles from '@patternfly/react-styles/css/components/Table/table';
import { import {
@ -163,6 +167,8 @@ export const mountpointPrefixes = [
'/var', '/var',
]; ];
const units = ['GiB', 'MiB', 'KiB'];
type MountpointPrefixPropTypes = { type MountpointPrefixPropTypes = {
partition: Partition; partition: Partition;
}; };
@ -173,10 +179,6 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
const prefix = getPrefix(partition.mountpoint); const prefix = getPrefix(partition.mountpoint);
const suffix = getSuffix(partition.mountpoint); const suffix = getSuffix(partition.mountpoint);
const onToggle = (isOpen: boolean) => {
setIsOpen(isOpen);
};
const onSelect = (event: React.MouseEvent, selection: string) => { const onSelect = (event: React.MouseEvent, selection: string) => {
setIsOpen(false); setIsOpen(false);
const mountpoint = selection + (suffix.length > 0 ? '/' + suffix : ''); const mountpoint = selection + (suffix.length > 0 ? '/' + suffix : '');
@ -185,18 +187,42 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
); );
}; };
const onToggleClick = () => {
setIsOpen(!isOpen);
};
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
onClick={onToggleClick}
isExpanded={isOpen}
isDisabled={prefix === '/'}
data-testid="prefix-select"
isFullWidth
>
{prefix}
</MenuToggle>
);
return ( return (
<Select <Select
ouiaId="mount-point" ouiaId="mount-point"
isOpen={isOpen} isOpen={isOpen}
onToggle={(_event, isOpen) => onToggle(isOpen)} selected={prefix}
onSelect={onSelect} onSelect={onSelect}
selections={prefix} onOpenChange={(isOpen) => setIsOpen(isOpen)}
isDisabled={prefix === '/'} toggle={toggle}
shouldFocusToggleOnSelect
> >
{mountpointPrefixes.map((prefix, index) => { <SelectList>
return <SelectOption key={index} value={prefix} />; {mountpointPrefixes.map((prefix, index) => {
})} return (
<SelectOption key={index} value={prefix}>
{prefix}
</SelectOption>
);
})}
</SelectList>
</Select> </Select>
); );
}; };
@ -292,10 +318,6 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const onToggle = (isOpen: boolean) => {
setIsOpen(isOpen);
};
const initialValue = useRef(partition).current; const initialValue = useRef(partition).current;
const onSelect = (event: React.MouseEvent, selection: Units) => { const onSelect = (event: React.MouseEvent, selection: Units) => {
@ -311,18 +333,43 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
setIsOpen(false); setIsOpen(false);
}; };
const onToggleClick = () => {
setIsOpen(!isOpen);
};
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
onClick={onToggleClick}
isExpanded={isOpen}
data-testid="unit-select"
>
{partition.unit}
</MenuToggle>
);
return ( return (
<Select <Select
ouiaId="unit" ouiaId="unit"
isOpen={isOpen} isOpen={isOpen}
onToggle={(_event, isOpen) => onToggle(isOpen)} selected={partition.unit}
onSelect={onSelect} onSelect={onSelect}
selections={partition.unit} onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
> >
<SelectOption value={'KiB'} /> <SelectList>
<SelectOption value={'MiB'} /> {units.map((unit, index) => (
<SelectOption value={'GiB'} /> <SelectOption key={index} value={unit}>
<>{initialValue.unit === 'B' && <SelectOption value={'B'} />}</> {unit}
</SelectOption>
))}
<>
{initialValue.unit === 'B' && (
<SelectOption value={'B'}>B</SelectOption>
)}
</>
</SelectList>
</Select> </Select>
); );
}; };

View file

@ -88,23 +88,19 @@ const changePartitionSize = async () => {
const changePartitionUnitsToKiB = async () => { const changePartitionUnitsToKiB = async () => {
const user = userEvent.setup(); const user = userEvent.setup();
const row = await getRow(1); const row = await getRow(1);
const units = await within(row).findAllByRole('button', { const units = await within(row).findByTestId('unit-select');
name: /options menu/i, await waitFor(() => user.click(units));
}); const kibOption = await screen.findByRole('option', { name: 'KiB' });
await waitFor(() => user.click(units[1])); await waitFor(() => user.click(kibOption));
const mibibytes = await screen.findByText('KiB');
await waitFor(() => user.click(mibibytes));
}; };
const changePartitionUnitsToMiB = async () => { const changePartitionUnitsToMiB = async () => {
const user = userEvent.setup(); const user = userEvent.setup();
const row = await getRow(1); const row = await getRow(1);
const units = await within(row).findAllByRole('button', { const units = await within(row).findByTestId('unit-select');
name: /options menu/i, await waitFor(() => user.click(units));
}); const mibOption = await screen.findByRole('option', { name: 'MiB' });
await waitFor(() => user.click(units[1])); await waitFor(() => user.click(mibOption));
const mibibytes = await screen.findByText('MiB');
await waitFor(() => user.click(mibibytes));
}; };
const goToReviewStep = async () => { const goToReviewStep = async () => {
@ -191,9 +187,9 @@ describe('Step File system configuration', () => {
expect(rows).toHaveLength(3); expect(rows).toHaveLength(3);
//Change mountpoint of final row to /var, resolving errors //Change mountpoint of final row to /var, resolving errors
const mountPointOptions = within(rows[2]).getAllByRole('button', { const mountPointOptions = await within(rows[2]).findByTestId(
name: 'Options menu', 'prefix-select'
})[0]; );
user.click(mountPointOptions); user.click(mountPointOptions);
const varButton = await within(rows[2]).findByRole('option', { const varButton = await within(rows[2]).findByRole('option', {
name: '/var', name: '/var',