| 1 |
/* |
| 2 |
* Copyright (C) 2023 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from "cockpit"; |
| 7 |
import React from "react"; |
| 8 |
import client from "../client"; |
| 9 |
|
| 10 |
import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js"; |
| 11 |
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js"; |
| 12 |
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; |
| 13 |
|
| 14 |
import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx"; |
| 15 |
import { StorageUsageBar } from "../storage-controls.jsx"; |
| 16 |
import { std_lock_action } from "../crypto/actions.jsx"; |
| 17 |
import { std_format_action } from "../block/actions.jsx"; |
| 18 |
import { btrfs_device_usage } from "./utils.jsx"; |
| 19 |
|
| 20 |
const _ = cockpit.gettext; |
| 21 |
|
| 22 |
export function make_btrfs_device_card(next, backing_block, content_block, block_btrfs) { |
| 23 |
const label = block_btrfs && block_btrfs.data.label; |
| 24 |
const uuid = block_btrfs && block_btrfs.data.uuid; |
| 25 |
const use = btrfs_device_usage(client, uuid, block_btrfs.path); |
| 26 |
|
| 27 |
const btrfs_card = new_card({ |
| 28 |
title: _("btrfs device"), |
| 29 |
location: { |
| 30 |
label: label || uuid, |
| 31 |
to: ["btrfs-volume", uuid], |
| 32 |
}, |
| 33 |
next, |
| 34 |
component: BtrfsDeviceCard, |
| 35 |
props: { backing_block, content_block }, |
| 36 |
actions: btrfs_device_actions(backing_block, content_block), |
| 37 |
}); |
| 38 |
|
| 39 |
register_crossref({ |
| 40 |
key: uuid, |
| 41 |
card: btrfs_card, |
| 42 |
size: <StorageUsageBar stats={use} short />, |
| 43 |
}); |
| 44 |
|
| 45 |
return btrfs_card; |
| 46 |
} |
| 47 |
|
| 48 |
export const BtrfsDeviceCard = ({ card, backing_block, content_block }) => { |
| 49 |
const block_btrfs = client.blocks_fsys_btrfs[content_block.path]; |
| 50 |
const uuid = block_btrfs && block_btrfs.data.uuid; |
| 51 |
const label = block_btrfs && block_btrfs.data.label; |
| 52 |
const use = btrfs_device_usage(client, uuid, block_btrfs.path); |
| 53 |
|
| 54 |
return ( |
| 55 |
<StorageCard card={card}> |
| 56 |
<CardBody> |
| 57 |
<DescriptionList className="pf-m-horizontal-on-sm"> |
| 58 |
<StorageDescription title={_("btrfs volume")}> |
| 59 |
{uuid |
| 60 |
? <Button variant="link" isInline role="link" |
| 61 |
onClick={() => cockpit.location.go(["btrfs-volume", uuid])}> |
| 62 |
{label || uuid} |
| 63 |
</Button> |
| 64 |
: "-" |
| 65 |
} |
| 66 |
</StorageDescription> |
| 67 |
<StorageDescription title={_("UUID")} value={content_block.IdUUID} /> |
| 68 |
{ block_btrfs && |
| 69 |
<StorageDescription title={_("Usage")}> |
| 70 |
<StorageUsageBar key="s" stats={use} /> |
| 71 |
</StorageDescription> |
| 72 |
} |
| 73 |
</DescriptionList> |
| 74 |
</CardBody> |
| 75 |
</StorageCard>); |
| 76 |
}; |
| 77 |
|
| 78 |
export function btrfs_device_actions(backing_block, content_block) { |
| 79 |
if (backing_block && content_block) |
| 80 |
return [ |
| 81 |
std_lock_action(backing_block, content_block), |
| 82 |
std_format_action(backing_block, content_block), |
| 83 |
]; |
| 84 |
else |
| 85 |
return []; |
| 86 |
} |