Skip to content

Commit

Permalink
storaged: filter attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Apr 3, 2024
1 parent fdbbfc6 commit c22d6d0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/storaged/btrfs/subvolume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function make_btrfs_subvolume_page(parent, volume, subvol, path_prefix, subvols)
component: BtrfsSubvolumeCard,
has_warning: !!mismount_warning,
props: { subvol, mount_point, mismount_warning, block, fstab_config, forced_options },
hidden: subvol.parent_uuid !== null,
page_properties: { is_snapshot: !!subvol.parent_uuid },
actions,
});

Expand Down
5 changes: 4 additions & 1 deletion pkg/storaged/btrfs/volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { VolumeIcon } from "../icons/gnome-icons.jsx";

import {
new_card, new_page, PAGE_CATEGORY_VIRTUAL,
get_crossrefs, ChildrenTable, PageTable, StorageCard, StorageDescription
get_crossrefs, ChildrenTable, PageTable, StorageCard, StorageDescription,
register_filter,
} from "../pages.jsx";
import { StorageUsageBar, StorageLink } from "../storage-controls.jsx";
import { fmt_size_long, validate_fsys_label, should_ignore } from "../utils.js";
Expand Down Expand Up @@ -55,6 +56,8 @@ export function make_btrfs_volume_page(parent, uuid) {
const volume = client.uuids_btrfs_volume[uuid];
const use = btrfs_usage(client, volume);

register_filter(_("snapshots"), "is_snapshot", (property) => !!property);

if (block_devices.some(blk => should_ignore(client, blk.path)))
return;

Expand Down
31 changes: 30 additions & 1 deletion pkg/storaged/pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,17 @@ const _ = cockpit.gettext;

let pages = null;
let crossrefs = null;
let filters = null;

// Pages are sorted on category
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();
filters = new Map();
}

function name_from_card(card) {
Expand All @@ -161,6 +164,12 @@ function category_from_card(card) {
return category_from_card(card.next) || card.page_category;
}

function properties_from_card(card) {
if (!card)
return null;
return card.page_properties || {};
}

function key_from_card(card) {
if (!card)
return null;
Expand All @@ -187,6 +196,7 @@ export function new_page(parent, card, options) {
name: name_from_card(card),
icon: icon_from_card(card),
category: category_from_card(card),
filter_properties: properties_from_card(card),
key: key_from_card(card),
parent,
children: [],
Expand Down Expand Up @@ -220,7 +230,7 @@ export function new_card({
title, location, next,
type_extra, id_extra,
page_name, page_icon, page_category, page_key, page_location, page_size,
page_block,
page_block, page_properties,
for_summary,
has_warning, has_danger, job_path,
component, props,
Expand All @@ -242,6 +252,7 @@ export function new_card({
page_category: page_category || PAGE_CATEGORY_PHYSICAL,
page_key,
page_location,
page_properties,
page_size,
for_summary,
component,
Expand Down Expand Up @@ -299,6 +310,10 @@ export function navigate_away_from_card(card) {
loc.go(page.parent.location);
}

export function register_filter(display_name, property_name, filter_func) {
filters.set(property_name, { display_name, filter_func });
}

export function navigate_to_new_card_location(card, location) {
if (!card)
return;
Expand Down Expand Up @@ -654,6 +669,19 @@ export const PageTable = ({ emptyCaption, aria_label, pages, crossrefs, sorted,
function make_page_rows(pages, level, last_has_border, key, sorted) {
const sorted_pages = sort(pages, p => p, sorted);
for (const p of sorted_pages) {
let filtered = false;
for (const [filter_prop, filter_val] of filters.entries()) {
const val = p.filter_properties[filter_prop];
if (val) {
filtered = filter_val.filter_func(val);
}
}

if (filtered)
continue;

console.log(p);

const is_last = (level == 0 || p == sorted_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 Down Expand Up @@ -837,6 +865,7 @@ export const StorageDescription = ({ title, value, action, children }) => {
export const StoragePage = ({ location, plot_state }) => {
const page = get_page_from_location(location);

// Filter state lives here
return (
<Page id="storage">
{ (!client.in_anaconda_mode() && page.parent) &&
Expand Down

0 comments on commit c22d6d0

Please sign in to comment.