Debian Codegraph @

pkg/storaged/stratis/blockdev.jsx

raw
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 { std_format_action } from "../block/actions.jsx";
16 import { fmt_size } from "../utils.js";
17 import { std_lock_action } from "../crypto/actions.jsx";
18
19 const _ = cockpit.gettext;
20
21 export function make_stratis_blockdev_card(next, backing_block, content_block) {
22 const blockdev = client.blocks_stratis_blockdev[content_block.path];
23 const pool = blockdev && client.stratis_pools[blockdev.Pool];
24 const uuid = client.blocks_stratis_stopped_pool[content_block.path];
25
26 const blockdev_card = new_card({
27 title: _("Stratis block device"),
28 location: {
29 label: pool ? pool.Name : client.stratis_manager.StoppedPools[uuid]?.name?.v || uuid,
30 to: ["pool", pool ? pool.Uuid : uuid],
31 },
32 next,
33 component: StratisBlockdevCard,
34 props: { backing_block, content_block, pool, stopped_pool: uuid },
35 actions: [
36 std_lock_action(backing_block, content_block),
37 std_format_action(backing_block, content_block),
38 ]
39 });
40
41 if (pool || uuid) {
42 let extra;
43 if (blockdev && blockdev.Tier == 0)
44 extra = _("data");
45 else if (blockdev && blockdev.Tier == 1)
46 extra = _("cache");
47 else
48 extra = null;
49
50 register_crossref({
51 key: pool || uuid,
52 card: blockdev_card,
53 actions: [],
54 size: blockdev ? fmt_size(Number(blockdev.TotalPhysicalSize)) : fmt_size(content_block.Size),
55 extra,
56 });
57 }
58
59 return blockdev_card;
60 }
61
62 export const StratisBlockdevCard = ({ card, backing_block, content_block, pool, stopped_pool }) => {
63 const pool_name = pool ? pool.Name : stopped_pool;
64 const pool_uuid = pool ? pool.Uuid : stopped_pool;
65
66 return (
67 <StorageCard card={card}>
68 <CardBody>
69 <DescriptionList className="pf-m-horizontal-on-sm">
70 <StorageDescription title={_("Stratis pool")}>
71 {(pool || stopped_pool)
72 ? <Button variant="link" isInline role="link"
73 onClick={() => cockpit.location.go(["pool", pool_uuid])}>
74 {pool_name}
75 </Button>
76 : "-"
77 }
78 </StorageDescription>
79 </DescriptionList>
80 </CardBody>
81 </StorageCard>
82 );
83 };