Skip to content

Commit

Permalink
WIP - towards cards
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Nov 16, 2023
1 parent 38c1f1d commit 1b14b63
Show file tree
Hide file tree
Showing 36 changed files with 943 additions and 1,219 deletions.
109 changes: 14 additions & 95 deletions pkg/storaged/block/create-pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

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

import { get_partitions, fmt_size } from "../utils.js";
import { get_fstab_config } from "../filesystem/utils.jsx";

import { format_dialog } from "./format-dialog.jsx";
import { StorageSize } from "../storage-controls.jsx";

import { make_unrecognized_data_page } from "./unrecognized-data.jsx";
import { make_unformatted_data_page } from "./unformatted-data.jsx";
import { make_locked_encrypted_data_page } from "../crypto/locked-encrypted-data.jsx";
Expand All @@ -37,84 +31,9 @@ import { make_stratis_blockdev_page } from "../stratis/blockdev.jsx";
import { make_swap_page } from "../swap/swap.jsx";
import { make_partition_table_page } from "../partitions/partition-table.jsx";
import { make_legacy_vdo_page } from "../legacy-vdo/legacy-vdo.jsx";
import { make_encryption_card } from "../crypto/encryption.jsx";

import { make_partition_container, delete_partition } from "../partitions/partition.jsx";
import { make_encryption_container } from "../crypto/encryption.jsx";

import { new_page } from "../pages.jsx";

const _ = cockpit.gettext;

/* Creating all the pages
*
* This is where a lot of the hair is.
*/

export function make_block_pages(parent, block) {
if (client.blocks_ptable[block.path])
make_partition_pages(parent, block);
else
make_block_page(parent, block, null);
}

function make_partition_pages(parent, block) {
const block_ptable = client.blocks_ptable[block.path];

function make_free_space_page(parent, start, size, enable_dos_extended) {
new_page({
parent,
name: _("Free space"),
columns: [
null,
null,
<StorageSize key="s" size={size} />,
],
actions: [
{
title: _("Create partition"),
action: () => format_dialog(client, block.path, start, size,
enable_dos_extended),
}
],
});
}

function make_extended_partition_page(parent, partition) {
const page = new_page({
parent,
name: _("Extended partition"),
columns: [
null,
null,
fmt_size(partition.size),
],
actions: [
{ title: _("Delete"), action: () => delete_partition(partition.block, page), danger: true },
]
});
process_partitions(page, partition.partitions, false);
}

function process_partitions(parent, partitions, enable_dos_extended) {
let i, p;
for (i = 0; i < partitions.length; i++) {
p = partitions[i];
if (p.type == 'free')
make_free_space_page(parent, p.start, p.size, enable_dos_extended);
else if (p.type == 'container')
make_extended_partition_page(parent, p);
else {
const container = make_partition_container(null, p.block);
make_block_page(parent, p.block, container);
}
}
}

process_partitions(parent, get_partitions(client, block),
block_ptable.Type == 'dos');
}

export function make_block_page(parent, block, container) {
export function make_block_page(parent, block, card) {
let is_crypto = block.IdUsage == 'crypto';
let content_block = is_crypto ? client.blocks_cleartext[block.path] : block;
const fstab_config = get_fstab_config(content_block || block, true);
Expand All @@ -128,12 +47,12 @@ export function make_block_page(parent, block, container) {
block_stratis_stopped_pool);

if (client.blocks_ptable[block.path]) {
make_partition_table_page(parent, block, container);
make_partition_table_page(parent, block, card);
return;
}

if (legacy_vdo) {
make_legacy_vdo_page(parent, legacy_vdo, block, container);
make_legacy_vdo_page(parent, legacy_vdo, block, card);
return;
}

Expand All @@ -144,14 +63,14 @@ export function make_block_page(parent, block, container) {
}

if (is_crypto)
container = make_encryption_container(container, block);
card = make_encryption_card(card, block);

if (!content_block) {
// assert(is_crypto);
if (fstab_config.length > 0) {
make_filesystem_page(parent, block, null, fstab_config, container);
make_filesystem_page(parent, block, null, fstab_config, card);
} else {
make_locked_encrypted_data_page(parent, block, container);
make_locked_encrypted_data_page(parent, block, card);
}
return;
}
Expand All @@ -161,20 +80,20 @@ export function make_block_page(parent, block, container) {
const block_swap = client.blocks_swap[content_block.path];

if (is_filesystem) {
make_filesystem_page(parent, block, content_block, fstab_config, container);
make_filesystem_page(parent, block, content_block, fstab_config, card);
} else if ((content_block.IdUsage == "raid" && content_block.IdType == "LVM2_member") ||
(block_pvol && client.vgroups[block_pvol.VolumeGroup])) {
make_lvm2_physical_volume_page(parent, block, content_block, container);
make_lvm2_physical_volume_page(parent, block, content_block, card);
} else if (is_stratis) {
make_stratis_blockdev_page(parent, block, content_block, container);
make_stratis_blockdev_page(parent, block, content_block, card);
} else if ((content_block.IdUsage == "raid") ||
(client.mdraids[content_block.MDRaidMember])) {
make_mdraid_disk_page(parent, block, content_block, container);
make_mdraid_disk_page(parent, block, content_block, card);
} else if (block_swap || (content_block && content_block.IdUsage == "other" && content_block.IdType == "swap")) {

Check warning

Code scanning / CodeQL

Useless conditional Warning

This use of variable 'content_block' always evaluates to true.
make_swap_page(parent, block, content_block, container);
make_swap_page(parent, block, content_block, card);
} else if (client.blocks_available[content_block.path]) {
make_unformatted_data_page(parent, block, content_block, container);
make_unformatted_data_page(parent, block, content_block, card);
} else {
make_unrecognized_data_page(parent, block, content_block, container);
make_unrecognized_data_page(parent, block, content_block, card);
}
}
18 changes: 9 additions & 9 deletions pkg/storaged/block/other.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import React from "react";
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 { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { ActionButtons, new_container, block_location } from "../pages.jsx";
import { StorageCard, new_card, block_location } from "../pages.jsx";
import { block_name } from "../utils.js";
import { partitionable_block_actions } from "../partitions/actions.jsx";

Expand All @@ -34,27 +33,28 @@ import { make_block_page } from "../block/create-pages.jsx";
const _ = cockpit.gettext;

export function make_other_page(parent, block) {
const container = new_container({
parent: null,
const card = new_card({
title: _("Block device"),
next: null,
page_location: ["other", block_location(block)],
component: OtherContainer,
component: OtherCard,
props: { block },
actions: partitionable_block_actions(block),
});

make_block_page(parent, block, container);
make_block_page(parent, block, card);
}

const OtherContainer = ({ container, block }) => {
const OtherCard = ({ card, block }) => {
return (
<SCard title={_("Block device")} actions={<ActionButtons container={container} />}>
<StorageCard card={card}>
<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>
</StorageCard>
);
};
4 changes: 2 additions & 2 deletions pkg/storaged/block/resize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function lvol_or_part_and_fsys_resize(client, lvol_or_part, size, offline, passp
// HACK - https://bugzilla.redhat.com/show_bug.cgi?id=1934567
//
// block_fsys.MountedAt might be out of synch with reality
// here if resizing the crypto container accidentally
// here if resizing the crypto card accidentally
// triggered an unmount. Thus, we check synchronously
// whether or not we should be doing a offline resize or
// not.
Expand Down Expand Up @@ -313,7 +313,7 @@ export function free_space_after_part(client, part) {
for (const p of parts) {
if (p.type == "free" && p.start == part.Offset + part.Size)
return p.size;
if (p.type == "container") {
if (p.type == "card") {
const s = find_it(p.partitions);
if (s)
return s;
Expand Down
40 changes: 9 additions & 31 deletions pkg/storaged/block/unformatted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,27 @@
*/

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

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

import {
PageContainerStackItems,
new_page, block_location, ActionButtons, page_type,
StorageCard, new_page, new_card,
} from "../pages.jsx";
import { SCard } from "../utils/card.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { block_name } from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";
import { StorageSize } from "../storage-controls.jsx";

const _ = cockpit.gettext;

export function make_unformatted_data_page(parent, backing_block, content_block, container) {
new_page({
location: [block_location(backing_block)],
parent,
container,
name: block_name(backing_block),
columns: [
_("Unformatted data"),
null,
<StorageSize key="s" size={backing_block.Size} />,
],
component: UnformattedDataPage,
props: { backing_block, content_block },
export function make_unformatted_data_page(parent, backing_block, content_block, next_card) {
const unformatted_card = new_card({
title: _("Unformatted data"),
next: next_card,
page_block: backing_block,
component: StorageCard,
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path) },
]
});
}

export const UnformattedDataPage = ({ page, backing_block, content_block }) => {
return (
<Stack hasGutter>
<StackItem>
<SCard title={page_type(page)} actions={<ActionButtons page={page} />} />
</StackItem>
<PageContainerStackItems page={page} />
</Stack>);
};
new_page(parent, unformatted_card);
}
53 changes: 19 additions & 34 deletions pkg/storaged/block/unrecognized-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,40 @@ import React from "react";
import client from "../client";

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 { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import {
PageContainerStackItems,
new_page, block_location, ActionButtons, page_type,
} from "../pages.jsx";
import { SCard } from "../utils/card.jsx";
import { StorageCard, new_page, new_card } from "../pages.jsx";
import { SDesc } from "../utils/desc.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { block_name } from "../utils.js";
import { std_lock_action } from "../crypto/actions.jsx";
import { StorageSize } from "../storage-controls.jsx";

const _ = cockpit.gettext;

export function make_unrecognized_data_page(parent, backing_block, content_block, container) {
new_page({
location: [block_location(backing_block)],
parent,
container,
name: block_name(backing_block),
columns: [
_("Unrecognized data"),
null,
<StorageSize key="s" size={backing_block.Size} />,
],
component: UnrecognizedDataPage,
export function make_unrecognized_data_page(parent, backing_block, content_block, next_card) {
const unrec_card = new_card({
title: _("Unrecognized data"),
next: next_card,
page_block: backing_block,
component: UnrecognizedDataCard,
props: { backing_block, content_block },
actions: [
std_lock_action(backing_block, content_block),
{ title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true },
]
});

new_page(parent, unrec_card);
}

export const UnrecognizedDataPage = ({ page, backing_block, content_block }) => {
export const UnrecognizedDataCard = ({ card, backing_block, content_block }) => {
return (
<Stack hasGutter>
<StackItem>
<SCard title={page_type(page)} actions={<ActionButtons page={page} />}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Usage")} value={content_block.IdUsage || "-"} />
<SDesc title={_("Type")} value={content_block.IdType || "-"} />
</DescriptionList>
</CardBody>
</SCard>
</StackItem>
<PageContainerStackItems page={page} />
</Stack>);
<StorageCard card={card}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Usage")} value={content_block.IdUsage || "-"} />
<SDesc title={_("Type")} value={content_block.IdType || "-"} />
</DescriptionList>
</CardBody>
</StorageCard>
);
};
Loading

0 comments on commit 1b14b63

Please sign in to comment.