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 15, 2023
1 parent 38c1f1d commit 7c2f39b
Show file tree
Hide file tree
Showing 30 changed files with 781 additions and 941 deletions.
14 changes: 3 additions & 11 deletions pkg/storaged/block/create-pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cockpit from "cockpit";
import React from "react";
import client from "../client";

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

import { format_dialog } from "./format-dialog.jsx";
Expand Down Expand Up @@ -64,11 +64,7 @@ function make_partition_pages(parent, block) {
new_page({
parent,
name: _("Free space"),
columns: [
null,
null,
<StorageSize key="s" size={size} />,
],
size: <StorageSize key="s" size={size} />,
actions: [
{
title: _("Create partition"),
Expand All @@ -83,11 +79,7 @@ function make_partition_pages(parent, block) {
const page = new_page({
parent,
name: _("Extended partition"),
columns: [
null,
null,
fmt_size(partition.size),
],
size: <StorageSize key="s" size={partition.size} />,
actions: [
{ title: _("Delete"), action: () => delete_partition(partition.block, page), danger: true },
]
Expand Down
8 changes: 4 additions & 4 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_container, block_location } from "../pages.jsx";
import { block_name } from "../utils.js";
import { partitionable_block_actions } from "../partitions/actions.jsx";

Expand All @@ -35,6 +34,7 @@ const _ = cockpit.gettext;

export function make_other_page(parent, block) {
const container = new_container({
title: _("Block device"),
parent: null,
page_location: ["other", block_location(block)],
component: OtherContainer,
Expand All @@ -47,14 +47,14 @@ export function make_other_page(parent, block) {

const OtherContainer = ({ container, block }) => {
return (
<SCard title={_("Block device")} actions={<ActionButtons container={container} />}>
<StorageCard 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>
</StorageCard>
);
};
40 changes: 13 additions & 27 deletions pkg/storaged/block/unformatted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ 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_container, block_location,
} 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";
Expand All @@ -36,31 +32,21 @@ 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 },
const unformatted_card = new_container({
title: _("Unformatted data"),
parent: container,
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({
location: [block_location(backing_block)],
parent,
container: unformatted_card,
name: block_name(backing_block),
size: <StorageSize key="s" size={backing_block.Size} />,
});
}
53 changes: 24 additions & 29 deletions pkg/storaged/block/unrecognized-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ 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,
StorageCard,
new_page, new_container, block_location,
} from "../pages.jsx";
import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { block_name } from "../utils.js";
Expand All @@ -39,38 +37,35 @@ 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,
const unrec_card = new_container({
title: _("Unrecognized data"),
parent: container,
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({
location: [block_location(backing_block)],
parent,
container: unrec_card,
name: block_name(backing_block),
size: <StorageSize key="s" size={backing_block.Size} />,
});
}

export const UnrecognizedDataPage = ({ page, backing_block, content_block }) => {
export const UnrecognizedDataCard = ({ container, 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 container={container}>
<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>
);
};
10 changes: 5 additions & 5 deletions pkg/storaged/crypto/encryption.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import { useObject, useEvent } from "hooks";
import * as python from "python.js";
import * as timeformat from "timeformat.js";

import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { dialog_open, TextInput, PassInput } from "../dialog.jsx";
import { block_name, encode_filename, decode_filename, parse_options, unparse_options, extract_option, edit_crypto_config } from "../utils.js";
import { new_container } from "../pages.jsx";
import { StorageCard, new_container } from "../pages.jsx";
import luksmeta_monitor_hack_py from "./luksmeta-monitor-hack.py";
import { is_mounted } from "../filesystem/utils.jsx";
import { StorageLink } from "../storage-controls.jsx";
Expand All @@ -41,8 +40,9 @@ const _ = cockpit.gettext;

export function make_encryption_container(parent, block) {
return new_container({
title: _("Encryption"),
parent,
type_format: _("$0 (encrypted)"), // XXX - icon?
type_extra: _("encrypted"),
component: EncryptionContainer,
props: { block },
});
Expand Down Expand Up @@ -220,7 +220,7 @@ const EncryptionContainer = ({ container, block }) => {
const options = option_parts.join(", ");

return (
<SCard title={_("Encryption")}>
<StorageCard container={container}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm ct-wide-labels">
<SDesc title={_("Encryption type")}>
Expand All @@ -240,5 +240,5 @@ const EncryptionContainer = ({ container, block }) => {
<CryptoKeyslots client={client} block={block}
slots={luks_info.slots} slot_error={luks_info.slot_error}
max_slots={luks_info.max_slots} />
</SCard>);
</StorageCard>);
};
38 changes: 13 additions & 25 deletions pkg/storaged/crypto/locked-encrypted-data.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ 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 { SCard } from "../utils/card.jsx";
import { PageContainerStackItems, new_page, block_location, ActionButtons } from "../pages.jsx";
import { StorageCard, new_page, new_container, block_location } from "../pages.jsx";
import { format_dialog } from "../block/format-dialog.jsx";
import { block_name } from "../utils.js";
import { unlock } from "./actions.jsx";
Expand All @@ -33,31 +30,22 @@ import { StorageSize } from "../storage-controls.jsx";
const _ = cockpit.gettext;

export function make_locked_encrypted_data_page(parent, block, container) {
new_page({
location: [block_location(block)],
parent,
container,
name: block_name(block),
columns: [
_("Locked encrypted data"),
null,
<StorageSize key="s" size={(block.Size)} />,
],
component: LockedEncryptedDataPage,
const locked_card = new_container({
title: _("Locked data"),
parent: container,
component: StorageCard,
props: { block },
actions: [
{ title: _("Unlock"), action: () => unlock(block) },
{ title: _("Format"), action: () => format_dialog(client, block.path), danger: true },
]
});
}

export const LockedEncryptedDataPage = ({ page, block }) => {
return (
<Stack hasGutter>
<StackItem>
<SCard title={_("Locked encrypted data")} actions={<ActionButtons page={page} />} />
</StackItem>
<PageContainerStackItems page={page} />
</Stack>);
};
new_page({
location: [block_location(block)],
parent,
container: locked_card,
name: block_name(block),
size: <StorageSize key="s" size={(block.Size)} />,
});
}
36 changes: 15 additions & 21 deletions pkg/storaged/drive/drive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";
import { Flex } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js";

import { SCard } from "../utils/card.jsx";
import { SDesc } from "../utils/desc.jsx";
import { ActionButtons, block_location, new_container, new_page } from "../pages.jsx";
import { StorageCard, block_location, new_container, new_page } from "../pages.jsx";
import { block_name, drive_name, format_temperature, fmt_size_long } from "../utils.js";
import { format_disk } from "../partitions/format-dialog.jsx";

Expand Down Expand Up @@ -73,29 +72,24 @@ export function make_drive_page(parent, drive) {
if (!block)
return;

if (block.Size > 0) {
const container = new_container({
parent: null,
page_location: ["drive", block_location(block)],
id_extra: drive_name(drive),
component: DriveContainer,
props: { drive },
actions: partitionable_block_actions(block),
});
const container = new_container({
title: _("Drive"),
parent: null,
page_location: ["drive", block_location(block)],
id_extra: drive_name(drive),
component: DriveContainer,
props: { drive },
actions: block.Size > 0 ? partitionable_block_actions(block) : [],
});

if (block.Size > 0) {
make_block_page(parent, block, container);
} else {
new_page({
parent,
name: block_name(block) + " - " + drive_name(drive),
container,
name: block_name(block),
location: ["drive", block_location(block)],
columns: [
null,
null,
null,
],
component: DriveContainer,
props: { drive }
});
}
}
Expand Down Expand Up @@ -123,7 +117,7 @@ const DriveContainer = ({ container, page, drive }) => {
}

return (
<SCard title={_("Drive")} actions={<ActionButtons container={container} page={page} />}>
<StorageCard container={container}>
<CardBody>
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Model")} value={drive.Model} />
Expand All @@ -145,6 +139,6 @@ const DriveContainer = ({ container, page, drive }) => {
}
</DescriptionList>
</CardBody>
</SCard>
</StorageCard>
);
};
Loading

0 comments on commit 7c2f39b

Please sign in to comment.