Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wizard: Remove deprecated selects #2903

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 27 additions & 8 deletions src/Components/CreateImageWizard/steps/ImageOutput/ArchSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { ReactElement, useState } from 'react';

import { FormGroup } from '@patternfly/react-core';
import {
FormGroup,
MenuToggle,
MenuToggleElement,
Select,
SelectList,
SelectOption,
SelectVariant,
} from '@patternfly/react-core/deprecated';
} from '@patternfly/react-core';

import { ARCHES } from '../../../../constants';
import { useAppDispatch, useAppSelector } from '../../../../store/hooks';
Expand Down Expand Up @@ -49,17 +51,34 @@ const ArchSelect = () => {
return options;
};

const onToggleClick = () => {
setIsOpen(!isOpen);
};

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
onClick={onToggleClick}
isExpanded={isOpen}
isFullWidth
data-testid="arch_select"
>
{arch}
</MenuToggle>
);

return (
<FormGroup isRequired={true} label="Architecture">
<Select
ouiaId="arch_select"
variant={SelectVariant.single}
onToggle={() => setIsOpen(!isOpen)}
onSelect={setArch}
selections={arch}
isOpen={isOpen}
selected={arch}
onSelect={setArch}
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
toggle={toggle}
shouldFocusToggleOnSelect
>
{setSelectOptions()}
<SelectList>{setSelectOptions()}</SelectList>
</Select>
</FormGroup>
);
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ const selectCentos9 = async () => {

const openArchitectureMenu = async () => {
const user = userEvent.setup();
const releaseMenu = screen.getAllByRole('button', {
name: /options menu/i,
})[1];
const releaseMenu = screen.getByTestId('arch_select');
await waitFor(() => user.click(releaseMenu));
};

Expand Down
Loading