Skip to content

Commit

Permalink
storage: Sort tables first by category
Browse files Browse the repository at this point in the history
Fixes #19747
  • Loading branch information
mvollmer committed Dec 14, 2023
1 parent d39a2fb commit 508d13d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
6 changes: 5 additions & 1 deletion pkg/storaged/iscsi/session.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";

import { NetworkIcon } from "../icons/gnome-icons.jsx";
import { StorageDescription, new_page, new_card, ChildrenTable, StorageCard } from "../pages.jsx";
import {
new_page, new_card, PAGE_CATEGORY_NETWORK,
StorageDescription, ChildrenTable, StorageCard
} from "../pages.jsx";

import { make_drive_page } from "../drive/drive.jsx";

Expand All @@ -44,6 +47,7 @@ export function make_iscsi_session_page(parent, session) {
page_location: ["iscsi", session.data.target_name],
page_name: session.data.target_name,
page_icon: NetworkIcon,
page_categroy: PAGE_CATEGORY_NETWORK,
component: ISCSISessionCard,
props: { session },
actions: [
Expand Down
4 changes: 3 additions & 1 deletion pkg/storaged/lvm2/volume-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import { useObject } from "hooks";
import { VolumeIcon } from "../icons/gnome-icons.jsx";
import { StorageButton, StorageLink } from "../storage-controls.jsx";
import {
StorageCard, StorageDescription, ChildrenTable, PageTable, new_page, new_card, get_crossrefs,
StorageCard, StorageDescription, ChildrenTable, PageTable,
new_page, new_card, get_crossrefs, PAGE_CATEGORY_VIRTUAL,
navigate_to_new_card_location, navigate_away_from_card
} from "../pages.jsx";
import {
Expand Down Expand Up @@ -229,6 +230,7 @@ export function make_lvm2_volume_group_page(parent, vgroup) {
page_location: ["vg", vgroup.Name],
page_name: vgroup.Name,
page_icon: VolumeIcon,
page_category: PAGE_CATEGORY_VIRTUAL,
page_size: vgroup.Size,
job_path: vgroup.path,
component: LVM2VolumeGroupCard,
Expand Down
7 changes: 6 additions & 1 deletion pkg/storaged/mdraid/mdraid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc

import { VolumeIcon } from "../icons/gnome-icons.jsx";
import { StorageButton, StorageLink } from "../storage-controls.jsx";
import { StorageCard, StorageDescription, PageTable, new_page, new_card, get_crossrefs, navigate_away_from_card } from "../pages.jsx";
import {
StorageCard, StorageDescription, PageTable,
new_page, new_card, PAGE_CATEGORY_VIRTUAL,
get_crossrefs, navigate_away_from_card
} from "../pages.jsx";
import { make_block_page } from "../block/create-pages.jsx";
import {
block_short_name, mdraid_name, encode_filename, decode_filename,
Expand Down Expand Up @@ -201,6 +205,7 @@ export function make_mdraid_page(parent, mdraid) {
page_location: ["mdraid", mdraid.UUID],
page_name: block ? block_short_name(block) : mdraid_name(mdraid),
page_icon: VolumeIcon,
page_category: PAGE_CATEGORY_VIRTUAL,
page_size: mdraid.Size,
type_extra: !block && _("stopped"),
id_extra: block && _("MDRAID device"),
Expand Down
7 changes: 6 additions & 1 deletion pkg/storaged/nfs/nfs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import {
} from "../dialog.jsx";

import { StorageUsageBar } from "../storage-controls.jsx";
import { StorageCard, StorageDescription, new_page, new_card, navigate_to_new_card_location, navigate_away_from_card } from "../pages.jsx";
import {
StorageCard, StorageDescription,
new_page, new_card, PAGE_CATEGORY_NETWORK,
navigate_to_new_card_location, navigate_away_from_card
} from "../pages.jsx";
import { parse_options, unparse_options, extract_option } from "../utils.js";

const _ = cockpit.gettext;
Expand Down Expand Up @@ -293,6 +297,7 @@ export function make_nfs_page(parent, entry) {
page_location: ["nfs", remote, local],
page_name: remote,
page_icon: NetworkIcon,
page_category: PAGE_CATEGORY_NETWORK,
page_size: <NfsEntryUsageBar key="size" entry={entry} not_mounted_text={null} short />,
component: NfsCard,
props: { entry },
Expand Down
29 changes: 25 additions & 4 deletions pkg/storaged/pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ const _ = cockpit.gettext;
let pages = null;
let crossrefs = null;

export const PAGE_CATEGORY_PHYSICAL = 1;
export const PAGE_CATEGORY_VIRTUAL = 2;
export const PAGE_CATEGORY_NETWORK = 3;

export function reset_pages() {
pages = new Map();
crossrefs = new Map();
Expand All @@ -150,6 +154,12 @@ function icon_from_card(card) {
return icon_from_card(card.next) || card.page_icon;
}

function category_from_card(card) {
if (!card)
return null;
return category_from_card(card.next) || card.page_category;
}

function key_from_card(card) {
if (!card)
return null;
Expand All @@ -175,6 +185,7 @@ export function new_page(parent, card, options) {
location: location_from_card(card),
name: name_from_card(card),
icon: icon_from_card(card),
category: category_from_card(card),
key: key_from_card(card),
parent,
children: [],
Expand Down Expand Up @@ -207,7 +218,7 @@ export function new_page(parent, card, options) {
export function new_card({
title, location, next,
type_extra, id_extra,
page_name, page_icon, page_key, page_location, page_size,
page_name, page_icon, page_category, page_key, page_location, page_size,
page_block,
for_summary,
has_warning, has_danger, job_path,
Expand All @@ -227,6 +238,7 @@ export function new_card({
type_extra,
page_name,
page_icon,
page_category: page_category || PAGE_CATEGORY_PHYSICAL,
page_key,
page_location,
page_size,
Expand Down Expand Up @@ -612,14 +624,23 @@ export const PageTable = ({ emptyCaption, aria_label, pages, crossrefs, sorted,
}
}

function page_compare(a, b) {
if (a.category < b.category)
return -1;
else if (a.category > b.category)
return 1;
else
return a.name.localeCompare(b.name);
}

function sort(things, accessor, sorted) {
if (sorted === false)
return things;
return things.toSorted((a, b) => accessor(a).localeCompare(accessor(b)));
return things.toSorted((a, b) => page_compare(accessor(a), accessor(b)));
}

function make_page_rows(pages, level, last_has_border, key, sorted) {
for (const p of sort(pages, p => p.name, sorted)) {
for (const p of sort(pages, p => p, sorted)) {
const is_last = (level == 0 || p == pages[pages.length - 1]);
const p_key = key + ":" + (p.key || p.name);
make_row(p, null, level, is_last && p.children.length == 0 && last_has_border, p_key);
Expand All @@ -628,7 +649,7 @@ export const PageTable = ({ emptyCaption, aria_label, pages, crossrefs, sorted,
}

function make_crossref_rows(crossrefs) {
for (const c of sort(crossrefs, c => c.card.page.name, sorted))
for (const c of sort(crossrefs, c => c.card.page, sorted))
make_row(c.card.page, c, 0, true, c.card.page.name);
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/storaged/stratis/pool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { fmt_to_fragments } from "utils.jsx";
import { StorageButton, StorageUsageBar, StorageLink } from "../storage-controls.jsx";
import {
StorageCard, StorageDescription, ChildrenTable, PageTable,
new_page, new_card, get_crossrefs, navigate_away_from_card
new_page, new_card, PAGE_CATEGORY_VIRTUAL,
get_crossrefs, navigate_away_from_card
} from "../pages.jsx";
import {
get_active_usage, teardown_active_usage, for_each_async,
Expand Down Expand Up @@ -290,6 +291,7 @@ export function make_stratis_pool_page(parent, pool) {
page_location: ["pool", pool.Uuid],
page_name: pool.Name,
page_icon: VolumeIcon,
page_category: PAGE_CATEGORY_VIRTUAL,
page_size: ((!managed_fsys_sizes && use)
? <StorageUsageBar key="s" stats={use} short />
: Number(pool.TotalPhysicalSize)),
Expand Down
9 changes: 8 additions & 1 deletion pkg/storaged/stratis/stopped-pool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import { CardHeader, CardBody } from "@patternfly/react-core/dist/esm/components
import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js";
import { List, ListItem } from "@patternfly/react-core/dist/esm/components/List/index.js";

import { StorageCard, StorageDescription, PageTable, new_page, new_card, get_crossrefs } from "../pages.jsx";
import { VolumeIcon } from "../icons/gnome-icons.jsx";
import {
StorageCard, StorageDescription, PageTable,
new_page, new_card, PAGE_CATEGORY_VIRTUAL,
get_crossrefs
} from "../pages.jsx";
import { dialog_open, PassInput } from "../dialog.jsx";
import { std_reply, with_stored_passphrase } from "./utils.jsx";

Expand Down Expand Up @@ -92,6 +97,8 @@ export function make_stratis_stopped_pool_page(parent, uuid) {
next: null,
page_location: ["pool", uuid],
page_name: uuid,
page_icon: VolumeIcon,
page_category: PAGE_CATEGORY_VIRTUAL,
component: StoppedStratisPoolCard,
props: { uuid },
actions: [
Expand Down

0 comments on commit 508d13d

Please sign in to comment.