Skip to content

Commit f52bf5a

Browse files
tomasmatusjelly
authored andcommitted
storage: use StorageBarMenu in SMART card
1 parent aae2164 commit f52bf5a

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed

pkg/storaged/drive/smart-details.jsx

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@
1818
*/
1919

2020
import cockpit from "cockpit";
21-
import React, { useState } from "react";
21+
import React from "react";
2222

2323
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
2424
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";
25-
import { Dropdown, DropdownItem, MenuToggle } from "@patternfly/react-core";
26-
import { EllipsisVIcon, ExclamationCircleIcon, ExclamationTriangleIcon } from "@patternfly/react-icons";
25+
import { DropdownList } from "@patternfly/react-core";
26+
import { ExclamationCircleIcon, ExclamationTriangleIcon } from "@patternfly/react-icons";
2727
import { Flex } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js";
2828
import { Icon } from "@patternfly/react-core/dist/esm/components/Icon/index.js";
2929

3030
import { format_temperature } from "../utils.js";
31-
import { superuser } from "superuser.js";
3231
import { StorageCard, StorageDescription } from "../pages.jsx";
33-
import { useEvent } from "hooks.js";
32+
import { StorageBarMenu, StorageMenuItem } from "../storage-controls.jsx";
3433

3534
const _ = cockpit.gettext;
3635

@@ -71,7 +70,6 @@ const nvmeCriticalWarning = {
7170
};
7271

7372
const SmartActions = ({ smart_info }) => {
74-
const [isKebabOpen, setKebabOpen] = useState(false);
7573
const smartSelftestStatus = smart_info.SmartSelftestStatus;
7674

7775
const runSelfTest = (type) => {
@@ -82,31 +80,30 @@ const SmartActions = ({ smart_info }) => {
8280
smart_info.SmartSelftestAbort({});
8381
};
8482

85-
const testDisabled = !superuser.allowed || smartSelftestStatus === "inprogress";
83+
const testDisabled = smartSelftestStatus === "inprogress";
8684

87-
return (
88-
<Dropdown
89-
toggle={toggleRef => <MenuToggle ref={toggleRef} icon={<EllipsisVIcon />} variant="plain" aria-label={_("SMART actions")} onClick={() => setKebabOpen(!isKebabOpen)} isExpanded={isKebabOpen} />}
90-
isPlain
91-
isOpen={isKebabOpen}
92-
id="smart-actions"
93-
>
94-
<DropdownItem key="smart-short-test"
95-
isDisabled={testDisabled}
96-
onClick={() => { setKebabOpen(false); runSelfTest('short') }}>
85+
const actionItems = (
86+
<DropdownList>
87+
<StorageMenuItem isDisabled={testDisabled}
88+
onClick={() => { runSelfTest('short') }}
89+
>
9790
{_("Run short test")}
98-
</DropdownItem>,
99-
<DropdownItem key="smart-extended-test"
100-
isDisabled={testDisabled}
101-
onClick={() => { setKebabOpen(false); runSelfTest('extended') }}>
91+
</StorageMenuItem>
92+
<StorageMenuItem isDisabled={testDisabled}
93+
onClick={() => { runSelfTest('extended') }}
94+
>
10295
{_("Run extended test")}
103-
</DropdownItem>,
104-
<DropdownItem key="abort-smart-test"
105-
isDisabled={testDisabled}
106-
onClick={() => { setKebabOpen(false); abortSelfTest() }}>
96+
</StorageMenuItem>
97+
<StorageMenuItem isDisabled={!testDisabled}
98+
onClick={() => { abortSelfTest() }}
99+
>
107100
{_("Abort test")}
108-
</DropdownItem>,
109-
</Dropdown>
101+
</StorageMenuItem>
102+
</DropdownList>
103+
);
104+
105+
return (
106+
<StorageBarMenu isKebab label={_("Actions")} menuItems={actionItems} />
110107
);
111108
};
112109

@@ -116,8 +113,6 @@ export const isSmartOK = (drive_type, smart_info) => {
116113
};
117114

118115
export const SmartCard = ({ card, smart_info, drive_type }) => {
119-
useEvent(superuser, "changed");
120-
121116
const powerOnHours = (drive_type === "ata")
122117
? Math.floor(smart_info.SmartPowerOnSeconds / 3600)
123118
: smart_info.SmartPowerOnHours;

pkg/storaged/storage-controls.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ export const StorageSize = ({ size }) => {
224224
</div>);
225225
};
226226

227-
export const StorageMenuItem = ({ onClick, danger, excuse, children }) => (
227+
export const StorageMenuItem = ({ onClick, danger, excuse, children, isDisabled }) => (
228228
<DropdownItem className={danger && !excuse ? " delete-resource-dangerous" : ""}
229229
description={excuse}
230-
isDisabled={!!excuse}
230+
isDisabled={isDisabled || !!excuse}
231231
onClick={checked(onClick, null, excuse)}>
232232
{children}
233233
</DropdownItem>

0 commit comments

Comments
 (0)