Skip to content

Commit

Permalink
WIP - absolutely everything is a container!
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Nov 9, 2023
1 parent f98a436 commit 25c5951
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 123 deletions.
10 changes: 5 additions & 5 deletions pkg/storaged/pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,21 +453,21 @@ export const PageContainerStackItems = ({ page }) => {
const items = [];
let cont = page.container;
while (cont) {
items.push(<>
items.push(<React.Fragment key={items.length}>
<Bullseye>
<Icon size="lg">
<LongArrowAltDownIcon />
</Icon>
</Bullseye>
<StackItem key={items.length}>
<StackItem>
<Container container={cont} />
</StackItem>
</>);
</React.Fragment>);
cont = cont.parent;
}

if (page.parent && page.parent.parent) {
items.push(<>
items.push(<React.Fragment key={items.length}>
<Bullseye>
<Icon size="lg">
<LongArrowAltDownIcon />
Expand All @@ -482,7 +482,7 @@ export const PageContainerStackItems = ({ page }) => {
</Card>
</Bullseye>
</StackItem>
</>);
</React.Fragment>);
}

return items;
Expand Down
57 changes: 20 additions & 37 deletions pkg/storaged/pages/other.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,42 @@

import cockpit from "cockpit";
import React from "react";
import client from "../client";

import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";
import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
import { Stack, StackItem } from "@patternfly/react-core/dist/esm/layouts/Stack/index.js";

import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { PageChildrenCard, ActionButtons, new_page, page_type, block_location } from "../pages.jsx";
import { ActionButtons, new_container, block_location } from "../pages.jsx";
import { block_name } from "../utils.js";
import { partitionable_block_actions, make_partitionable_block_pages } from "./drive.jsx";
import { StorageSize } from "../storage-controls.jsx";
import { partitionable_block_actions } from "./drive.jsx";

import { make_block_page } from "../create-pages.jsx";

const _ = cockpit.gettext;

export function make_other_page(parent, block) {
const p = new_page({
location: ["other", block_location(block)],
parent,
name: block_location(block),
columns: [
_("Block device"),
block_name(block),
<StorageSize key="s" size={block.Size} />,
],
const container = new_container({
parent: null,
page_location: ["other", block_location(block)],
component: OtherContainer,
props: { block },
actions: partitionable_block_actions(block),
component: OtherPage,
props: { block }
});

make_partitionable_block_pages(p, block);
make_block_page(parent, block, container);
}

const OtherPage = ({ page, block }) => {
const OtherContainer = ({ container, block }) => {
return (
<Stack hasGutter>
<StackItem>
<SCard title={page_type(page)}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Device number")}
value={Math.floor(block.DeviceNumber / 256) + ":" + block.DeviceNumber % 256} />
<SDesc title={_("Device file")} value={block_name(block)} />
</DescriptionList>
</CardBody>
</SCard>
</StackItem>
<StackItem>
<PageChildrenCard title={client.blocks_ptable[block.path] ? _("Partitions") : _("Content")}
actions={<ActionButtons page={page} />}
emptyCaption={_("Block device is not formatted")}
page={page} />
</StackItem>
</Stack>
<SCard title={_("Block device")} actions={<ActionButtons container={container} />}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Device number")}
value={Math.floor(block.DeviceNumber / 256) + ":" + block.DeviceNumber % 256} />
<SDesc title={_("Device file")} value={block_name(block)} />
</DescriptionList>
</CardBody>
</SCard>
);
};
175 changes: 94 additions & 81 deletions pkg/storaged/pages/stratis-pool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,31 @@ export function make_stratis_pool_page(parent, pool) {
{
title: _("Add block devices"),
action: () => add_disks(pool),
tag: "blockdevs",
},
],
});

const pool_container = new_container({
parent: blockdevs_container,
component: StratisPoolContainer,
props: { pool, degraded_ops, can_grow, managed_fsys_sizes, stats },
actions: [
{
title: _("Delete pool"),
action: () => delete_pool(pool),
danger: true,
},
],
});

const p = new_page({
location: ["pool", pool.Uuid],
parent,
container: blockdevs_container,
container: pool_container,
name: pool.Name,
columns: [
pool.Encrypted ? _("Encrypted Stratis filesystems pool") : _("Stratis filesystems pool"),
"/dev/stratis/" + pool.Name + "/",
pool.Encrypted ? _("Encrypted Stratis filesystems") : _("Stratis filesystems"),
null,
<StorageSize key="s" size={pool.TotalPhysicalSize} />,
],
has_warning: degraded_ops || can_grow,
Expand All @@ -401,13 +413,6 @@ export function make_stratis_pool_page(parent, pool) {
excuse: (managed_fsys_sizes && stats.pool_free < fsys_min_size
? _("Not enough space for new filesystems")
: null),
tag: "pool"
},
{
title: _("Delete pool"),
action: () => delete_pool(pool),
danger: true,
tag: "pool",
},
],
});
Expand All @@ -416,14 +421,6 @@ export function make_stratis_pool_page(parent, pool) {
}

const StratisPoolPage = ({ page, pool, degraded_ops, can_grow, managed_fsys_sizes, stats }) => {
const key_desc = (pool.Encrypted &&
pool.KeyDescription[0] &&
pool.KeyDescription[1][1]);
const can_tang = (client.features.stratis_crypto_binding &&
pool.Encrypted &&
pool.ClevisInfo[0] && // pool has consistent clevis config
(!pool.ClevisInfo[1][0] || pool.ClevisInfo[1][1][0] == "tang")); // not bound or bound to "tang"
const tang_url = can_tang && pool.ClevisInfo[1][0] ? JSON.parse(pool.ClevisInfo[1][1][1]).url : null;
const blockdevs = client.stratis_pool_blockdevs[pool.path] || [];

function grow_blockdevs() {
Expand Down Expand Up @@ -461,6 +458,33 @@ const StratisPoolPage = ({ page, pool, degraded_ops, can_grow, managed_fsys_size
</StackItem>);
}

return (
<Stack hasGutter>
{alerts}
<StackItem>
<SCard title={page_type(page)} actions={<ActionButtons page={page} />}>
<CardBody className="contains-list">
<PageTable emptyCaption={_("No filesystems")}
aria-label={_("Stratis filesystems pool")}
pages={page.children} />
</CardBody>
</SCard>
</StackItem>
<PageContainerStackItems page={page} />
</Stack>
);
};

const StratisPoolContainer = ({ container, pool, degraded_ops, can_grow, managed_fsys_sizes, stats }) => {
const key_desc = (pool.Encrypted &&
pool.KeyDescription[0] &&
pool.KeyDescription[1][1]);
const can_tang = (client.features.stratis_crypto_binding &&
pool.Encrypted &&
pool.ClevisInfo[0] && // pool has consistent clevis config
(!pool.ClevisInfo[1][0] || pool.ClevisInfo[1][1][0] == "tang")); // not bound or bound to "tang"
const tang_url = can_tang && pool.ClevisInfo[1][0] ? JSON.parse(pool.ClevisInfo[1][1][1]).url : null;

function add_passphrase() {
dialog_open({
Title: _("Add passphrase"),
Expand Down Expand Up @@ -598,70 +622,59 @@ const StratisPoolPage = ({ page, pool, degraded_ops, can_grow, managed_fsys_size
const use = pool.TotalPhysicalUsed[0] && [Number(pool.TotalPhysicalUsed[1]), Number(pool.TotalPhysicalSize)];

return (
<Stack hasGutter>
{alerts}
<StackItem>
<SCard title={page_type(page)} actions={<ActionButtons page={page} tag="pool" />}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Name")}
value={pool.Name}
action={<StorageLink onClick={() => rename_pool(pool)}>
{_("edit")}
</StorageLink>} />
<SDesc title={_("UUID")} value={pool.Uuid} />
{ !managed_fsys_sizes && use &&
<SDesc title={_("Usage")}>
<StorageUsageBar stats={use} critical={0.95} />
</SDesc>
}
{ pool.Encrypted && client.features.stratis_crypto_binding &&
<SDesc title={_("Passphrase")}>
<Flex>
{ !key_desc
? <FlexItem><StorageLink onClick={add_passphrase}>{_("Add passphrase")}</StorageLink></FlexItem>
: <>
<FlexItem><StorageLink onClick={change_passphrase}>{_("Change")}</StorageLink></FlexItem>
<FlexItem>
<StorageLink onClick={remove_passphrase}
excuse={!tang_url ? _("This passphrase is the only way to unlock the pool and can not be removed.") : null}>
{_("Remove")}
</StorageLink>
</FlexItem>
</>
}
</Flex>
</SDesc>
<SCard title={_("Stratis pool")} actions={<ActionButtons container={container} />}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Name")}
value={pool.Name}
action={<StorageLink onClick={() => rename_pool(pool)}>
{_("edit")}
</StorageLink>} />
<SDesc title={_("UUID")} value={pool.Uuid} />
{ !managed_fsys_sizes && use &&
<SDesc title={_("Usage")}>
<StorageUsageBar stats={use} critical={0.95} />
</SDesc>
}
{ pool.Encrypted && client.features.stratis_crypto_binding &&
<SDesc title={_("Passphrase")}>
<Flex>
{ !key_desc
? <FlexItem><StorageLink onClick={add_passphrase}>{_("Add passphrase")}</StorageLink></FlexItem>
: <>
<FlexItem><StorageLink onClick={change_passphrase}>{_("Change")}</StorageLink></FlexItem>
<FlexItem>
<StorageLink onClick={remove_passphrase}
excuse={!tang_url ? _("This passphrase is the only way to unlock the pool and can not be removed.") : null}>
{_("Remove")}
</StorageLink>
</FlexItem>
</>
}
{ can_tang &&
<SDesc title={_("Keyserver")}>
<Flex>
{ tang_url == null
? <FlexItem><StorageLink onClick={add_tang}>{_("Add keyserver")}</StorageLink></FlexItem>
: <>
<FlexItem>{ tang_url }</FlexItem>
<FlexItem>
<StorageLink onClick={remove_tang}
excuse={!key_desc ? _("This keyserver is the only way to unlock the pool and can not be removed.") : null}>
{_("Remove")}
</StorageLink>
</FlexItem>
</>
}
</Flex>
</SDesc>
</Flex>
</SDesc>
}
{ can_tang &&
<SDesc title={_("Keyserver")}>
<Flex>
{ tang_url == null
? <FlexItem><StorageLink onClick={add_tang}>{_("Add keyserver")}</StorageLink></FlexItem>
: <>
<FlexItem>{ tang_url }</FlexItem>
<FlexItem>
<StorageLink onClick={remove_tang}
excuse={!key_desc ? _("This keyserver is the only way to unlock the pool and can not be removed.") : null}>
{_("Remove")}
</StorageLink>
</FlexItem>
</>
}
</DescriptionList>
</CardBody>
<CardBody className="contains-list">
<PageTable emptyCaption={_("No filesystems")}
aria-label={_("Stratis filesystems pool")}
pages={page.children} />
</CardBody>
</SCard>
</StackItem>
<PageContainerStackItems page={page} />
</Stack>
</Flex>
</SDesc>
}
</DescriptionList>
</CardBody>
</SCard>
);
};

Expand Down

0 comments on commit 25c5951

Please sign in to comment.