-
Notifications
You must be signed in to change notification settings - Fork 82
web: Revamp storage proposal page #1138
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
302b335
web: Define types for icon name and size
dgdavid d7fdb32
web: Add initial version of core/Field
dgdavid e483ec2
web: core/Field improvements
dgdavid 4bfd0aa
web: Move storage/SpacePolicyField to its own file
dgdavid 1f79798
web: Enable type checking in some test files
dgdavid 51d55a8
web: Move storage/BootConfigField to its own file
dgdavid 8193701
web: Move storage/SnapshotsField to its own file
dgdavid ace29e0
[WIP] web: New PartitionsField
ancorgs 9c060f8
web: Add InstallationDeviceField
joseivanlopez e0910bf
web: Remove ProposalDeviceSection
joseivanlopez 0eef502
web: move storage/EncryptionField to its own file
dgdavid a0d09c2
web: Add link for activating disks
joseivanlopez 0fcc1e1
web: Small text adjustments
ancorgs 18a62da
web: Fix ProposalPage tests
joseivanlopez 4ea77fb
web: small icon adjustment
ancorgs 16a0f2e
web: Fix typo
ancorgs 4e09b30
web: Fix types
joseivanlopez ce141a0
web: Fix typo
ancorgs 35c2a78
web: Allow set/unset the encryption
dgdavid 7ada3fb
web: Fix ProposalSettingsSection tests
joseivanlopez 318ac15
web: Remove leftover Skeleton
dgdavid 11f7439
web: Fix styles of PartitionsField basic view
dgdavid 38fdd5c
web: Fix EncryptionField value calculation
dgdavid 0ed651e
web: Fix and adapt tests
joseivanlopez 2b616f4
web: Fix more tests
joseivanlopez 51fdee0
web: EncryptionField fixes and improvements
dgdavid 396d855
web: Extract the EncryptionSettingsDialog
dgdavid 324b018
web: Remove not needed aria-label attributes
dgdavid f0cb4d6
web: Small CSS adjustments
dgdavid e359517
web: EncryptionSettingsDialog refinement
dgdavid bcc4e8a
web: Add changelog entry
dgdavid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,121 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| // @ts-check | ||
|
|
||
| import React from "react"; | ||
| import { Icon } from "~/components/layout"; | ||
|
|
||
| /** | ||
| * @typedef {import("react").ButtonHTMLAttributes} ButtonHTMLAttributes | ||
| * @typedef {import("~/components/layout/Icon").IconName} IconName | ||
| * @typedef {import("~/components/layout/Icon").IconSize} IconSize | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef {object} FieldProps | ||
| * @property {React.ReactNode} label - The field label. | ||
| * @property {React.ReactNode} [value] - The field value. | ||
| * @property {React.ReactNode} [description] - A field description, useful for providing context to the user. | ||
| * @property {IconName} [icon] - The name of the icon for the field. | ||
| * @property {IconSize} [iconSize="s"] - The size for the field icon. | ||
| * @property {("b"|"span")} [textWrapper="b"] - The element used for wrapping the label. | ||
| * @property {ButtonHTMLAttributes} [buttonAttrs={}] - The element used for wrapping the label. | ||
| * @property {string} [className] - ClassName | ||
| * @property {() => void} [onClick] - Callback | ||
| * @property {React.ReactNode} [children] - A content to be rendered as field children | ||
| * | ||
| * @typedef {Omit<FieldProps, 'icon'>} FieldPropsWithoutIcon | ||
| */ | ||
|
|
||
| /** | ||
| * Component for laying out a page field | ||
| * | ||
| * @param {FieldProps} props | ||
| */ | ||
| const Field = ({ | ||
| label, | ||
| value, | ||
| description, | ||
| icon, | ||
| iconSize = "s", | ||
| onClick, | ||
| children, | ||
| textWrapper = "b", | ||
| buttonAttrs = {}, | ||
| ...props | ||
| }) => { | ||
| const FieldIcon = () => icon?.length > 0 && <Icon name={icon} size={iconSize} />; | ||
| const TextWrapper = textWrapper; | ||
| return ( | ||
| <div {...props} data-type="agama/field"> | ||
| <div> | ||
| <button {...buttonAttrs} className="plain-button" onClick={onClick}> | ||
| <FieldIcon /> <TextWrapper>{label}</TextWrapper> | ||
| </button> {value} | ||
| </div> | ||
| <div> | ||
| {description} | ||
| </div> | ||
| <div> | ||
| {children} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Omit<FieldProps, 'icon'>} props | ||
| */ | ||
| const SettingsField = ({ ...props }) => { | ||
| return <Field {...props} icon="shadow" />; | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Omit<FieldProps, 'icon'> & {isChecked: boolean, highlightContent?: boolean}} props | ||
| */ | ||
| const SwitchField = ({ isChecked = false, highlightContent = false, ...props }) => { | ||
| const iconName = isChecked ? "toggle_on" : "toggle_off"; | ||
| const baseClassnames = highlightContent ? "highlighted" : ""; | ||
| const stateClassnames = isChecked ? "on" : "off"; | ||
|
|
||
| return ( | ||
| <Field | ||
| {...props} | ||
| icon={iconName} | ||
| className={[baseClassnames, stateClassnames].join(" ")} | ||
| buttonAttrs={{ role: "switch", "aria-checked": isChecked }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Omit<FieldProps, 'icon'> & {isExpanded: boolean}} props | ||
| */ | ||
| const ExpandableField = ({ isExpanded, ...props }) => { | ||
| const iconName = isExpanded ? "collapse_all" : "expand_all"; | ||
| const className = isExpanded ? "expanded" : "collapsed"; | ||
|
|
||
| return <Field {...props} icon={iconName} className={className} />; | ||
| }; | ||
|
|
||
| export default Field; | ||
| export { ExpandableField, SettingsField, SwitchField }; | ||
This file contains hidden or 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,129 @@ | ||
| /* | ||
| * 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 } from "@testing-library/react"; | ||
| import { plainRender } from "~/test-utils"; | ||
| import { Field, ExpandableField, SettingsField, SwitchField } from "~/components/core"; | ||
|
|
||
| const onClick = jest.fn(); | ||
|
|
||
| describe("Field", () => { | ||
| it("renders a button with given icon and label", () => { | ||
| const { container } = plainRender( | ||
| <Field icon="edit" label="Theme" value="dark" onClick={onClick} /> | ||
| ); | ||
| screen.getByRole("button", { name: "Theme" }); | ||
| const icon = container.querySelector("button > svg"); | ||
| expect(icon).toHaveAttribute("data-icon-name", "edit"); | ||
| }); | ||
|
|
||
| it("renders value, description, and given children", () => { | ||
| plainRender( | ||
| <Field | ||
| icon="edit" | ||
| label="Theme" | ||
| value="dark" | ||
| description="Choose your preferred color schema." | ||
| onClick={onClick} | ||
| > | ||
| <p>This is a <b>preview</b></p>; | ||
| </Field> | ||
| ); | ||
| screen.getByText("dark"); | ||
| screen.getByText("Choose your preferred color schema."); | ||
| screen.getByText("This is a"); | ||
| screen.getByText("preview"); | ||
| }); | ||
|
|
||
| it("triggers the onClick callback when users clicks the button", async () => { | ||
| const { user } = plainRender( | ||
| <Field label="Theme" value="dark" onClick={onClick} /> | ||
| ); | ||
| const button = screen.getByRole("button"); | ||
| await user.click(button); | ||
| expect(onClick).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("SettingsField", () => { | ||
| it("uses the 'shadow' icon", () => { | ||
| const { container } = plainRender( | ||
| // Trying to set other icon, although typechecking should catch it. | ||
| <SettingsField icon="edit" label="Theme" value="dark" onClick={onClick} /> | ||
| ); | ||
| const icon = container.querySelector("button > svg"); | ||
| expect(icon).toHaveAttribute("data-icon-name", "shadow"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("SwitchField", () => { | ||
| it("sets button role to switch", () => { | ||
| plainRender(<SwitchField label="Zoom" value="enabled" isChecked />); | ||
| const switchButton = screen.getByRole("switch", { name: "Zoom" }); | ||
| expect(switchButton instanceof HTMLButtonElement).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps aria-checked attribute in sync with isChecked prop", () => { | ||
| let switchButton; | ||
| const { rerender } = plainRender(<SwitchField label="Zoom" value="enabled" isChecked />); | ||
| switchButton = screen.getByRole("switch", { name: "Zoom" }); | ||
| expect(switchButton).toHaveAttribute("aria-checked", "true"); | ||
|
|
||
| rerender(<SwitchField label="Zoom" value="disabled" />); | ||
| switchButton = screen.getByRole("switch", { name: "Zoom" }); | ||
| expect(switchButton).toHaveAttribute("aria-checked", "false"); | ||
| }); | ||
|
|
||
| it("uses the 'toggle_on' icon when isChecked", () => { | ||
| const { container } = plainRender( | ||
| <SwitchField label="Zoom" value="enabled" isChecked /> | ||
| ); | ||
| const icon = container.querySelector("button > svg"); | ||
| expect(icon).toHaveAttribute("data-icon-name", "toggle_on"); | ||
| }); | ||
|
|
||
| it("uses the 'toggle_off' icon when not isChecked", () => { | ||
| const { container } = plainRender( | ||
| <SwitchField label="Zoom" value="disabled" /> | ||
| ); | ||
| const icon = container.querySelector("button > svg"); | ||
| expect(icon).toHaveAttribute("data-icon-name", "toggle_off"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("ExpandableField", () => { | ||
| it("uses the 'collapse_all' icon when isExpanded", () => { | ||
| const { container } = plainRender( | ||
| <ExpandableField label="More settings" isExpanded /> | ||
| ); | ||
| const icon = container.querySelector("button > svg"); | ||
| expect(icon).toHaveAttribute("data-icon-name", "collapse_all"); | ||
| }); | ||
|
|
||
| it("uses the 'expand_all' icon when not isExpanded", () => { | ||
| const { container } = plainRender( | ||
| <ExpandableField label="More settings" /> | ||
| ); | ||
| const icon = container.querySelector("button > svg"); | ||
| expect(icon).toHaveAttribute("data-icon-name", "expand_all"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.