Skip to content

Commit

Permalink
Wizard: Swap FSC selects for non-deprecated version
Browse files Browse the repository at this point in the history
This swaps deprecated PF4 Selects on FSC step for non-deprecated PF5 ones.
  • Loading branch information
regexowl committed Feb 17, 2025
1 parent 074697a commit caafd1b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ import {
Button,
Alert,
TextInput,
Select,
MenuToggleElement,
MenuToggle,
SelectList,
SelectOption,
} from '@patternfly/react-core';
import { Select, SelectOption } from '@patternfly/react-core/deprecated';
import { HelpIcon, MinusCircleIcon } from '@patternfly/react-icons';
import styles from '@patternfly/react-styles/css/components/Table/table';
import {
Expand Down Expand Up @@ -163,6 +167,8 @@ export const mountpointPrefixes = [
'/var',
];

const units = ['GiB', 'MiB', 'KiB'];

type MountpointPrefixPropTypes = {
partition: Partition;
};
Expand All @@ -173,10 +179,6 @@ const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
const prefix = getPrefix(partition.mountpoint);
const suffix = getSuffix(partition.mountpoint);

const onToggle = (isOpen: boolean) => {
setIsOpen(isOpen);
};

const onSelect = (event: React.MouseEvent, selection: string) => {
setIsOpen(false);
const mountpoint = selection + (suffix.length > 0 ? '/' + suffix : '');
Expand All @@ -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 (
<Select
ouiaId="mount-point"
isOpen={isOpen}
onToggle={(_event, isOpen) => onToggle(isOpen)}
selected={prefix}
onSelect={onSelect}
selections={prefix}
isDisabled={prefix === '/'}
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
>
{mountpointPrefixes.map((prefix, index) => {
return <SelectOption key={index} value={prefix} />;
})}
<SelectList>
{mountpointPrefixes.map((prefix, index) => {
return (
<SelectOption key={index} value={prefix}>
{prefix}
</SelectOption>
);
})}
</SelectList>
</Select>
);
};
Expand Down Expand Up @@ -291,10 +317,6 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
const dispatch = useAppDispatch();
const [isOpen, setIsOpen] = useState(false);

const onToggle = (isOpen: boolean) => {
setIsOpen(isOpen);
};

const initialValue = useRef(partition).current;

const onSelect = (event: React.MouseEvent, selection: Units) => {
Expand All @@ -310,18 +332,43 @@ const SizeUnit = ({ partition }: SizeUnitPropTypes) => {
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 (
<Select
ouiaId="unit"
isOpen={isOpen}
onToggle={(_event, isOpen) => onToggle(isOpen)}
selected={partition.unit}
onSelect={onSelect}
selections={partition.unit}
onOpenChange={(isOpen) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
>
<SelectOption value={'KiB'} />
<SelectOption value={'MiB'} />
<SelectOption value={'GiB'} />
<>{initialValue.unit === 'B' && <SelectOption value={'B'} />}</>
<SelectList>
{units.map((unit, index) => (
<SelectOption key={index} value={unit}>
{unit}
</SelectOption>
))}
<>
{initialValue.unit === 'B' && (
<SelectOption value={'B'}>B</SelectOption>
)}
</>
</SelectList>
</Select>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,19 @@ const changePartitionSize = async () => {
const changePartitionUnitsToKiB = async () => {
const user = userEvent.setup();
const row = await getRow(1);
const units = await within(row).findAllByRole('button', {
name: /options menu/i,
});
await waitFor(() => user.click(units[1]));
const mibibytes = await screen.findByText('KiB');
await waitFor(() => user.click(mibibytes));
const units = await within(row).findByTestId('unit-select');
await waitFor(() => user.click(units));
const kibOption = await screen.findByRole('option', { name: 'KiB' });
await waitFor(() => user.click(kibOption));
};

const changePartitionUnitsToMiB = async () => {
const user = userEvent.setup();
const row = await getRow(1);
const units = await within(row).findAllByRole('button', {
name: /options menu/i,
});
await waitFor(() => user.click(units[1]));
const mibibytes = await screen.findByText('MiB');
await waitFor(() => user.click(mibibytes));
const units = await within(row).findByTestId('unit-select');
await waitFor(() => user.click(units));
const mibOption = await screen.findByRole('option', { name: 'MiB' });
await waitFor(() => user.click(mibOption));
};

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

//Change mountpoint of final row to /var, resolving errors
const mountPointOptions = within(rows[2]).getAllByRole('button', {
name: 'Options menu',
})[0];
const mountPointOptions = await within(rows[2]).findByTestId(
'prefix-select'
);
user.click(mountPointOptions);
const varButton = await within(rows[2]).findByRole('option', {
name: '/var',
Expand Down

0 comments on commit caafd1b

Please sign in to comment.