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

storage: show toast notification when disks selection changed #32

Merged
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
92 changes: 83 additions & 9 deletions src/components/storage/InstallationDestination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React, { useContext, useEffect, useRef, useState } from "react";
import {
Alert,
AlertActionCloseButton,
AlertGroup,
Button,
Chip,
ChipGroup,
Expand All @@ -31,9 +32,12 @@ import {
SelectList,
SelectOption,
Spinner,
Text,
TextContent,
TextInputGroup,
TextInputGroupMain,
TextInputGroupUtilities,
TextVariants,
Title,
} from "@patternfly/react-core";
import { SyncAltIcon, TimesIcon } from "@patternfly/react-icons";
Expand Down Expand Up @@ -393,20 +397,19 @@ export const InstallationDestination = ({
/>
);

const equalDisks = refUsableDisks.current && checkIfArraysAreEqual(refUsableDisks.current, diskSelection.usableDisks);
const headingLevel = isBootIso ? "h2" : "h3";

return (
<>
<Title headingLevel={headingLevel} id={idPrefix + "-disk-selector-title"}>{_("Destination")}</Title>
{equalDisksNotify && equalDisks &&
<Alert
id="no-disks-detected-alert"
isInline
title={_("No additional disks detected")}
variant="info"
actionClose={<AlertActionCloseButton onClose={() => { setEqualDisksNotify(false) }} />}
/>}
{!isRescanningDisks && diskSelection.usableDisks !== undefined && refUsableDisks.current !== undefined &&
<DisksChangedAlert
deviceData={deviceData}
equalDisksNotify={equalDisksNotify}
refUsableDisks={refUsableDisks}
setEqualDisksNotify={setEqualDisksNotify}
usableDisks={diskSelection.usableDisks}
/>}
<FormGroup>
<Flex spaceItems={{ default: "spaceItemsMd" }} alignItems={{ default: "alignItemsCenter" }}>
{(diskSelection.usableDisks.length > 1 || (diskSelection.usableDisks.length === 1 && diskSelection.selectedDisks.length === 0))
Expand Down Expand Up @@ -436,3 +439,74 @@ export const InstallationDestination = ({
</>
);
};

const DisksChangedAlert = ({
deviceData,
equalDisksNotify,
refUsableDisks,
setEqualDisksNotify,
usableDisks,
}) => {
const [showChangedNotification, setShowChangedNotification] = useState(true);
const equalDisks = checkIfArraysAreEqual(refUsableDisks.current, usableDisks);
const disksAdded = usableDisks.filter(disk => !refUsableDisks.current.includes(disk));
const disksRemoved = (
refUsableDisks.current &&
refUsableDisks.current.filter(disk => !usableDisks.includes(disk))
);

return (
<AlertGroup isToast isLiveRegion>
{equalDisksNotify && equalDisks &&
<Alert
id="no-disks-detected-alert"
title={_("No additional disks detected")}
variant="info"
actionClose={<AlertActionCloseButton onClose={() => { setEqualDisksNotify(false) }} />}
/>}
{showChangedNotification && !equalDisks &&
<Alert
id="disks-changed-alert"
title={_("The usable disks have changed")}
variant="info"
actionClose={<AlertActionCloseButton onClose={() => { setShowChangedNotification(false) }} />}>
<TextContent>
{disksAdded?.length > 0 &&
<Text component={TextVariants.p}>
{cockpit.format(
cockpit.ngettext(
"The following disk was detected: $0",
"The following disks were detected: $0",
disksAdded.length
),
disksAdded.map(disk => (
cockpit.format(
"$0 ($1)",
deviceData[disk].name.v,
deviceData[disk].description.v
))
).join(", ")
)}
</Text>}
{disksRemoved?.length > 0 &&
<Text component={TextVariants.p}>
{cockpit.format(
cockpit.ngettext(
"The following disk is no longer available: $0",
"The following disks are no longer available: $0",
disksRemoved.length
),
disksRemoved.map(disk => (
cockpit.format(
"$0 ($1)",
deviceData[disk].name.v,
deviceData[disk].description.v
))
).join(", ")
)}
</Text>}
</TextContent>
</Alert>}
</AlertGroup>
);
};
3 changes: 3 additions & 0 deletions test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
dev = dev.split("/")[-1]
s.rescan_disks()

# Check the newly added disk generated a notification
s.wait_disk_added(dev)

# Check that the disk selection persists when moving next and back
s.check_disk_selected("vda", True)
i.next()
Expand Down
3 changes: 3 additions & 0 deletions test/helpers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def wait_no_disks_detected(self):
def wait_no_disks_detected_not_present(self):
self.browser.wait_not_present("#no-disks-detected-alert")

def wait_disk_added(self, disk):
self.browser.wait_in_text("#disks-changed-alert", f"The following disk was detected: {disk}")

@log_step(snapshots=True)
def rescan_disks(self):
self.browser.click(f"#{self._step}-rescan-disks")
Expand Down