Skip to content

Commit

Permalink
[web] Adapt storage/SpacePolicy selector to core/Selector
Browse files Browse the repository at this point in the history
However, missing tests haven't been added because this selector is
subject to major changes in the short term according to
#103.
  • Loading branch information
dgdavid committed Feb 10, 2024
1 parent 5316bab commit be9ffe2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
10 changes: 5 additions & 5 deletions web/src/components/storage/ProposalSettingsSection.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ describe("Space policy field", () => {

const popup = await screen.findByRole("dialog");
within(popup).getByText("Space Policy");
within(popup).getByRole("option", { name: /Delete current content/ });
within(popup).getByRole("option", { name: /Shrink existing partitions/ });
within(popup).getByRole("option", { name: /Use available space/, selected: true });
within(popup).getByRole("row", { name: /Delete current content/ });
within(popup).getByRole("row", { name: /Shrink existing partitions/ });
within(popup).getByRole("row", { name: /Use available space/, selected: true });
});

it("allows to show the installation devices", async () => {
Expand Down Expand Up @@ -642,7 +642,7 @@ describe("Space policy field", () => {
await user.click(button);

const popup = await screen.findByRole("dialog");
const option = within(popup).getByRole("option", { name: /Shrink/ });
const option = within(popup).getByRole("row", { name: /Shrink/ });

await user.click(option);
const cancel = within(popup).getByRole("button", { name: "Cancel" });
Expand All @@ -661,7 +661,7 @@ describe("Space policy field", () => {
await user.click(button);

const popup = await screen.findByRole("dialog");
const option = within(popup).getByRole("option", { name: /Shrink/ });
const option = within(popup).getByRole("row", { name: /Shrink/ });

await user.click(option);
const accept = within(popup).getByRole("button", { name: "Accept" });
Expand Down
39 changes: 13 additions & 26 deletions web/src/components/storage/space-policy-utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,9 @@ import { _, n_ } from "~/i18n";
import { sprintf } from "sprintf-js";
import { noop } from "~/utils";
import { Button, ExpandableSection, Hint, HintBody } from "@patternfly/react-core";
import { Selector } from "~/components/core";
import { DeviceList } from "~/components/storage";

const ListBox = ({ children, ...props }) => <ul data-type="agama/list" data-of="agama/space-policies" {...props}>{children}</ul>;

const ListBoxItem = ({ isSelected, children, onClick, ...props }) => {
if (isSelected) props['aria-selected'] = true;

return (
<li
onClick={onClick}
{ ...props }
>
{children}
</li>
);
};

/**
* Content for a space policy item
* @component
Expand Down Expand Up @@ -91,10 +77,10 @@ Only the space that is not assigned to any partition will be used.");
};

return (
<>
<div data-items-type="agama/space-policies">
<Title />
<Description />
</>
</div>
);
};

Expand All @@ -108,19 +94,20 @@ Only the space that is not assigned to any partition will be used.");
* changes.
*/
const SpacePolicySelector = ({ value, onChange = noop }) => {
const onSelectionChange = (selection) => onChange(selection[0]);

return (
<ListBox aria-label={_("Select a mechanism to make space")} role="listbox">
<Selector
aria-label={_("Select a mechanism to make space")}
selectedIds={[value]}
onSelectionChange={onSelectionChange}
>
{ ["delete", "resize", "keep"].map(policy => (
<ListBoxItem
key={policy}
role="option"
onClick={() => onChange(policy)}
isSelected={policy === value}
>
<Selector.Option id={policy} key={policy}>
<PolicyItem policy={policy} />
</ListBoxItem>
</Selector.Option>
))}
</ListBox>
</Selector>
);
};

Expand Down

0 comments on commit be9ffe2

Please sign in to comment.