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