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: Use meaningful icons in Storage proposal page #1152

Merged
merged 5 commits into from
Apr 16, 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
6 changes: 6 additions & 0 deletions web/package/cockpit-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Apr 16 11:15:13 UTC 2024 - David Diaz <[email protected]>

- Use better icons in storage proposal page
(gh#openSUSE/agama#1152).

-------------------------------------------------------------------
Mon Apr 15 10:52:14 UTC 2024 - David Diaz <[email protected]>

Expand Down
16 changes: 5 additions & 11 deletions web/src/components/core/Field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ const Field = ({
);
};

/**
* @param {Omit<FieldProps, 'icon'>} props
*/
const SettingsField = ({ ...props }) => {
return <Field {...props} icon="shadow" />;
};

/**
* @param {Omit<FieldProps, 'icon'> & {isChecked: boolean, highlightContent?: boolean}} props
*/
Expand All @@ -108,14 +101,15 @@ const SwitchField = ({ isChecked = false, highlightContent = false, ...props })
};

/**
* @param {Omit<FieldProps, 'icon'> & {isExpanded: boolean}} props
* @param {FieldProps & {isExpanded: boolean}} props
*/
const ExpandableField = ({ isExpanded, ...props }) => {
const ExpandableField = ({ label, isExpanded, ...props }) => {
const iconName = isExpanded ? "collapse_all" : "expand_all";
const className = isExpanded ? "expanded" : "collapsed";
const labelWithIcon = <>{label} <Icon name={iconName} size="xs" /></>;

return <Field {...props} icon={iconName} className={className} />;
return <Field {...props} label={labelWithIcon} className={className} />;
};

export default Field;
export { ExpandableField, SettingsField, SwitchField };
export { ExpandableField, SwitchField };
33 changes: 9 additions & 24 deletions web/src/components/core/Field.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import React from "react";
import { screen } from "@testing-library/react";
import { plainRender } from "~/test-utils";
import { Field, ExpandableField, SettingsField, SwitchField } from "~/components/core";
import { Field, ExpandableField, SwitchField } from "~/components/core";

const onClick = jest.fn();

Expand Down Expand Up @@ -64,17 +64,6 @@ describe("Field", () => {
});
});

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 />);
Expand Down Expand Up @@ -111,19 +100,15 @@ describe("SwitchField", () => {
});

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 'expanded' as className prop value when isExpanded", () => {
const { container } = plainRender(<ExpandableField label="More settings" isExpanded />);
const field = container.querySelector("[data-type='agama/field']");
expect(field.classList.contains("expanded")).toBe(true);
});

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");
it("uses 'collapsed' as className prop value when isExpanded", () => {
const { container } = plainRender(<ExpandableField label="More settings" />);
const field = container.querySelector("[data-type='agama/field']");
expect(field.classList.contains("collapsed")).toBe(true);
});
});
2 changes: 1 addition & 1 deletion web/src/components/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ export { default as Tag } from "./Tag";
export { default as TreeTable } from "./TreeTable";
export { default as ControlledPanels } from "./ControlledPanels";
export { default as Field } from "./Field";
export { ExpandableField, SettingsField, SwitchField } from "./Field";
export { ExpandableField, SwitchField } from "./Field";
4 changes: 4 additions & 0 deletions web/src/components/layout/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import ExpandMore from "@icons/expand_more.svg?component";
import Feedback from "@icons/feedback.svg?component";
import Folder from "@icons/folder.svg?component";
import FolderOff from "@icons/folder_off.svg?component";
import FrameInspect from "@icons/frame_inspect.svg?component";
import Globe from "@icons/globe.svg?component";
import HardDrive from "@icons/hard_drive.svg?component";
import Help from "@icons/help.svg?component";
Expand All @@ -63,6 +64,7 @@ import SettingsApplications from "@icons/settings_applications.svg?component";
import SettingsEthernet from "@icons/settings_ethernet.svg?component";
import SettingsFill from "@icons/settings-fill.svg?component";
import Shadow from "@icons/shadow.svg?component";
import ShieldLock from "@icons/shield_lock.svg?component";
import SignalCellularAlt from "@icons/signal_cellular_alt.svg?component";
import Storage from "@icons/storage.svg?component";
import Sync from "@icons/sync.svg?component";
Expand Down Expand Up @@ -109,6 +111,7 @@ const icons = {
feedback: Feedback,
folder: Folder,
folder_off: FolderOff,
frame_inspect: FrameInspect,
globe: Globe,
hard_drive: HardDrive,
help: Help,
Expand All @@ -132,6 +135,7 @@ const icons = {
settings_applications: SettingsApplications,
settings_ethernet: SettingsEthernet,
shadow: Shadow,
shield_lock: ShieldLock,
signal_cellular_alt: SignalCellularAlt,
storage: Storage,
sync: Sync,
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/storage/BootConfigField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Button = ({ isBold = false, onClick }) => {

return (
<button onClick={onClick} className="inline-flex-button">
{isBold ? <b>{text}</b> : text} <Icon name="shadow" size="xxs" />
{isBold ? <b>{text}</b> : text}
</button>
);
};
Expand All @@ -68,7 +68,7 @@ const Button = ({ isBold = false, onClick }) => {
* @property {boolean} configureBoot
* @property {StorageDevice} bootDevice
*/
export default function BootConfigField ({
export default function BootConfigField({
configureBoot,
bootDevice,
defaultBootDevice,
Expand Down Expand Up @@ -104,7 +104,7 @@ export default function BootConfigField ({

return (
<div>
{ value } <Button onClick={openDialog} isBold={!configureBoot} />
{value} <Button onClick={openDialog} isBold={!configureBoot} />
<If
condition={isDialogOpen}
then={
Expand Down
7 changes: 4 additions & 3 deletions web/src/components/storage/EncryptionField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import React, { useCallback, useEffect, useState } from "react";
import { Skeleton } from "@patternfly/react-core";
import { _ } from "~/i18n";
import { noop } from "~/utils";
import { If, SettingsField } from "~/components/core";
import { If, Field } from "~/components/core";
import { EncryptionMethods } from "~/client/storage";
import EncryptionSettingsDialog from "~/components/storage/EncryptionSettingsDialog";

Expand Down Expand Up @@ -91,7 +91,8 @@ export default function EncryptionField({
};

return (
<SettingsField
<Field
icon="shield_lock"
label={LABEL}
description={DESCRIPTION}
value={isLoading ? VALUES.loading : VALUES[isEnabled ? method : "disabled"]}
Expand All @@ -110,6 +111,6 @@ export default function EncryptionField({
/>
}
/>
</SettingsField>
</Field>
);
}
7 changes: 4 additions & 3 deletions web/src/components/storage/InstallationDeviceField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Skeleton } from "@patternfly/react-core";
import { _ } from "~/i18n";
import { DeviceSelectionDialog, ProposalPageMenu } from "~/components/storage";
import { deviceLabel } from '~/components/storage/utils';
import { If, SettingsField } from "~/components/core";
import { If, Field } from "~/components/core";
import { sprintf } from "sprintf-js";

/**
Expand Down Expand Up @@ -114,7 +114,8 @@ export default function InstallationDeviceField({
value = targetValue(target, targetDevice, targetPVDevices);

return (
<SettingsField
<Field
icon="hard_drive"
label={LABEL}
value={value}
description={DESCRIPTION}
Expand All @@ -135,6 +136,6 @@ export default function InstallationDeviceField({
/>
}
/>
</SettingsField>
</Field>
);
}
1 change: 1 addition & 0 deletions web/src/components/storage/PartitionsField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ export default function PartitionsField({

return (
<ExpandableField
icon="storage"
isExpanded={isExpanded}
label={_("Partitions and file systems")}
description={_("Structure of the new system, including any additional partition needed for booting,")}
Expand Down
9 changes: 5 additions & 4 deletions web/src/components/storage/SpacePolicyField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Skeleton } from "@patternfly/react-core";

import { sprintf } from "sprintf-js";
import { _, n_ } from "~/i18n";
import { If, SettingsField } from "~/components/core";
import { If, Field } from "~/components/core";
import SpacePolicyDialog from "~/components/storage/SpacePolicyDialog";

/**
Expand Down Expand Up @@ -82,10 +82,11 @@ export default function SpacePolicyField({
}

return (
<SettingsField
<Field
icon="frame_inspect"
label={_("Find space")}
value={value}
description={ _("Allocating the file systems might need to find free space \
description={_("Allocating the file systems might need to find free space \
in the installation device(s).")}
onClick={openDialog}
>
Expand All @@ -102,6 +103,6 @@ in the installation device(s).")}
/>
}
/>
</SettingsField>
</Field>
);
}
Loading