-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Create a section for file systems
And mount there the storage/ProposalVolumes component instead of doing so in the settings section. Note that, most probably, the code of ProposalFileSystemsSection and ProposalVolumes could be merged in a single component.
- Loading branch information
Showing
5 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) [2024] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React from "react"; | ||
import { _ } from "~/i18n"; | ||
import { Section } from "~/components/core"; | ||
import { ProposalVolumes } from "~/components/storage"; | ||
import { noop } from "~/utils"; | ||
|
||
/** | ||
* @typedef {import ("~/client/storage").ProposalManager.ProposalSettings} ProposalSettings | ||
* @typedef {import ("~/client/storage").ProposalManager.Volume} Volume | ||
*/ | ||
|
||
/** | ||
* Section for editing the proposal file systems | ||
* @component | ||
* | ||
* @callback onChangeFn | ||
* @param {object} settings | ||
* | ||
* @param {object} props | ||
* @param {ProposalSettings} props.settings | ||
* @param {Volume[]} [props.volumeTemplates=[]] | ||
* @param {boolean} [props.isLoading=false] | ||
* @param {onChangeFn} [props.onChange=noop] | ||
* | ||
*/ | ||
export default function ProposalFileSystemsSection({ | ||
settings, | ||
volumeTemplates = [], | ||
isLoading = false, | ||
onChange = noop | ||
}) { | ||
const { volumes = [] } = settings; | ||
|
||
const changeVolumes = (volumes) => { | ||
onChange({ volumes }); | ||
}; | ||
|
||
// 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) | ||
)); | ||
}; | ||
|
||
const encryption = settings.encryptionPassword !== undefined && settings.encryptionPassword.length > 0; | ||
|
||
return ( | ||
<Section title={_("File systems")}> | ||
<ProposalVolumes | ||
volumes={volumes} | ||
templates={usefulTemplates()} | ||
options={{ lvm: settings.lvm, encryption }} | ||
isLoading={isLoading && settings.volumes === undefined} | ||
onChange={changeVolumes} | ||
/> | ||
</Section> | ||
); | ||
} |
54 changes: 54 additions & 0 deletions
54
web/src/components/storage/ProposalFileSystemsSection.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) [2024] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React from "react"; | ||
import { screen, within } from "@testing-library/react"; | ||
import { plainRender } from "~/test-utils"; | ||
import { ProposalFileSystemsSection } from "~/components/storage"; | ||
|
||
const props = { | ||
settings: {}, | ||
isLoading: false, | ||
onChange: jest.fn() | ||
}; | ||
|
||
describe("ProposalFileSystemsSection", () => { | ||
it("renders a section holding file systems related stuff", () => { | ||
plainRender(<ProposalFileSystemsSection {...props} />); | ||
screen.getByRole("region", { name: "File systems" }); | ||
}); | ||
|
||
it("requests a volume change when onChange callback is triggered", async () => { | ||
const { user } = plainRender(<ProposalFileSystemsSection {...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( | ||
expect.objectContaining({ volumes: expect.any(Array) }) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters