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

[web] SpacePolicy as pop-up #1090

Merged
merged 4 commits into from
Mar 15, 2024
Merged
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
80 changes: 0 additions & 80 deletions web/src/components/storage/ProposalFileSystemsSection.jsx

This file was deleted.

55 changes: 0 additions & 55 deletions web/src/components/storage/ProposalFileSystemsSection.test.jsx

This file was deleted.

12 changes: 0 additions & 12 deletions web/src/components/storage/ProposalPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import {
ProposalActionsSection,
ProposalPageMenu,
ProposalSettingsSection,
ProposalSpacePolicySection,
ProposalDeviceSection,
ProposalFileSystemsSection,
ProposalTransactionalInfo
} from "~/components/storage";
import { IDLE } from "~/client/status";
Expand Down Expand Up @@ -233,17 +231,7 @@ export default function ProposalPage() {
<ProposalSettingsSection
availableDevices={state.availableDevices}
encryptionMethods={state.encryptionMethods}
settings={state.settings}
onChange={changeSettings}
isLoading={state.loading}
/>
<ProposalFileSystemsSection
settings={state.settings}
volumeTemplates={state.volumeTemplates}
onChange={changeSettings}
isLoading={state.loading}
/>
<ProposalSpacePolicySection
settings={state.settings}
onChange={changeSettings}
isLoading={state.loading}
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/storage/ProposalPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ it("loads the proposal data", async () => {
await screen.findByText(/\/dev\/vda/);
});

it("renders the settings, find space and actions sections", async () => {
it("renders the device, settings and actions sections", async () => {
installerRender(<ProposalPage />);

await screen.findByText(/Device/);
await screen.findByText(/Settings/);
await screen.findByText(/Find Space/);
await screen.findByText(/Planned Actions/);
});

Expand Down
35 changes: 35 additions & 0 deletions web/src/components/storage/ProposalSettingsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Checkbox, Form, Skeleton, Switch, Tooltip } from "@patternfly/react-cor

import { _ } from "~/i18n";
import { If, PasswordAndConfirmationInput, Section, Popup } from "~/components/core";
import { ProposalVolumes, ProposalSpacePolicyField } from "~/components/storage";
import { Icon } from "~/components/layout";
import { noop } from "~/utils";
import { hasFS } from "~/components/storage/utils";
Expand Down Expand Up @@ -283,6 +284,8 @@ const EncryptionField = ({
export default function ProposalSettingsSection({
settings,
encryptionMethods = [],
volumeTemplates = [],
isLoading = false,
onChange = noop
}) {
const changeEncryption = ({ password, method }) => {
Expand All @@ -302,8 +305,26 @@ export default function ProposalSettingsSection({
onChange({ volumes: settings.volumes });
};

const changeVolumes = (volumes) => {
onChange({ volumes });
};

const changeSpacePolicy = (policy, actions) => {
onChange({ spacePolicy: policy, spaceActions: actions });
};

const encryption = settings.encryptionPassword !== undefined && settings.encryptionPassword.length > 0;

const { volumes = [] } = settings;

// Templates for already existing mount points are filtered out
const usefulTemplates = () => {
const mountPaths = volumes.map(v => v.mountPath);
return volumeTemplates.filter(t => (
t.mountPath.length > 0 && !mountPaths.includes(t.mountPath)
));
};

return (
<>
<Section title={_("Settings")}>
Expand All @@ -319,6 +340,20 @@ export default function ProposalSettingsSection({
isLoading={settings.encryptionPassword === undefined}
onChange={changeEncryption}
/>
<ProposalVolumes
volumes={volumes}
templates={usefulTemplates()}
options={{ lvm: settings.lvm, encryption }}
isLoading={isLoading && settings.volumes === undefined}
onChange={changeVolumes}
/>
<ProposalSpacePolicyField
policy={settings.spacePolicy}
actions={settings.spaceActions}
devices={settings.installationDevices}
isLoading={isLoading}
onChange={changeSpacePolicy}
/>
</Section>
</>
);
Expand Down
27 changes: 26 additions & 1 deletion web/src/components/storage/ProposalSettingsSection.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ jest.mock("@patternfly/react-core", () => {
let props;

beforeEach(() => {
props = {};
props = {
settings: {},
onChange: jest.fn()
};
});

const rootVolume = { mountPath: "/", fsType: "Btrfs", outline: { snapshotsConfigurable: true } };
Expand Down Expand Up @@ -65,6 +68,28 @@ describe("if snapshots are not configurable", () => {
});
});

it("renders a section holding file systems related stuff", () => {
plainRender(<ProposalSettingsSection {...props} />);
screen.getByRole("grid", { name: "Table with mount points" });
screen.getByRole("grid", { name: /mount points/ });
});

it("requests a volume change when onChange callback is triggered", async () => {
const { user } = plainRender(<ProposalSettingsSection {...props } />);
const button = screen.getByRole("button", { name: "Actions" });

await user.click(button);

const menu = screen.getByRole("menu");
const reset = within(menu).getByRole("menuitem", { name: /Reset/ });

await user.click(reset);

expect(props.onChange).toHaveBeenCalledWith(
{ volumes: expect.any(Array) }
);
});

describe("Encryption field", () => {
describe("if encryption password setting is not set yet", () => {
beforeEach(() => {
Expand Down
Loading
Loading