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