Skip to content

Commit

Permalink
WIP - navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvollmer committed Nov 16, 2023
1 parent c853c94 commit 75cd39d
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 122 deletions.
14 changes: 7 additions & 7 deletions pkg/storaged/lvm2/block-logical-volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { StorageButton, StorageLink, StorageSize } from "../storage-controls.jsx

import { SDesc } from "../utils/desc.jsx";
import { check_unused_space, get_resize_info, grow_dialog, shrink_dialog } from "../block/resize.jsx";
import { StorageCard, new_card, navigate_to_new_page_location, navigate_away_from_page } from "../pages.jsx";
import { StorageCard, new_card, navigate_to_new_card_location, navigate_away_from_card } from "../pages.jsx";
import { block_name, fmt_size, get_active_usage, teardown_active_usage, reload_systemd } from "../utils.js";
import {
dialog_open, TextInput, SelectSpaces, BlockingMessage, TeardownMessage,
Expand Down Expand Up @@ -59,7 +59,7 @@ export function lvol_rename(lvol) {
});
}

export function lvol_delete(lvol, page) {
export function lvol_delete(lvol, card) {
const vgroup = client.vgroups[lvol.VolumeGroup];
const block = client.lvols_block[lvol.path];
const usage = get_active_usage(client, block ? block.path : lvol.path, _("delete"));
Expand All @@ -82,7 +82,7 @@ export function lvol_delete(lvol, page) {
await teardown_active_usage(client, usage);
await lvol.Delete({ 'tear-down': { t: 'b', v: true } });
await reload_systemd();
navigate_away_from_page(page);
navigate_away_from_card(card);
}
},
Inits: [
Expand Down Expand Up @@ -194,7 +194,7 @@ export function make_block_logical_volume_card(next, vgroup, lvol, block) {
if (status_code == "degraded" || status_code == "degraded-maybe-partial")
repair_action = { title: _("Repair"), action: () => repair(lvol) };

const cont = new_card({
const card = new_card({
title: _("LVM2 logical volume"),
next,
page_location: ["vg", vgroup.Name, lvol.Name],
Expand Down Expand Up @@ -226,12 +226,12 @@ export function make_block_logical_volume_card(next, vgroup, lvol, block) {
repair_action,
{
title: _("Delete"),
action: () => lvol_delete(lvol, cont.page),
action: () => lvol_delete(lvol, card),
danger: !client.blocks_available[block.path],
},
],
});
return cont;
return card;
}

const LVM2LogicalVolumeCard = ({ card, vgroup, lvol, block, unused_space_warning, resize_info }) => {
Expand All @@ -248,7 +248,7 @@ const LVM2LogicalVolumeCard = ({ card, vgroup, lvol, block, unused_space_warning
Title: _("Rename"),
action: async function (vals) {
await lvol.Rename(vals.name, { });
navigate_to_new_page_location(card.page, ["vg", vgroup.Name, vals.name]);
navigate_to_new_card_location(card, ["vg", vgroup.Name, vals.name]);
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/lvm2/inactive-logical-volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export function make_inactive_logical_volume_page(parent, vgroup, lvol, next_car
actions: [
{ title: _("Activate"), action: () => lvol.Activate({}) },
lvm2_create_snapshot_action(lvol),
{ title: _("Delete"), action: () => lvol_delete(lvol, page), danger: true },
{ title: _("Delete"), action: () => lvol_delete(lvol, inactive_card), danger: true },
]
});

const page = new_page(parent, inactive_card);
new_page(parent, inactive_card);
}
6 changes: 3 additions & 3 deletions pkg/storaged/lvm2/thin-pool-logical-volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function make_lvm2_thin_pool_card(next, vgroup, lvol) {
);
}

const c = new_card({
const card = new_card({
title: _("Pool for thinly provisioned LVM2 logical volumes"),
next,
component: LVM2ThinPoolCard,
Expand All @@ -119,12 +119,12 @@ function make_lvm2_thin_pool_card(next, vgroup, lvol) {
},
{
title: _("Delete"),
action: () => lvol_delete(lvol, c.page),
action: () => lvol_delete(lvol, card),
danger: true,
},
],
});
return c;
return card;
}

function perc(ratio) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storaged/lvm2/unsupported-logical-volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export function make_unsupported_logical_volume_page(parent, vgroup, lvol, next_
props: { vgroup, lvol },
actions: [
{ title: _("Deactivate"), action: () => lvol.Deactivate({}) },
{ title: _("Delete"), action: () => lvol_delete(lvol, page), danger: true },
{ title: _("Delete"), action: () => lvol_delete(lvol, unsupported_card), danger: true },
]
});

const page = new_page(parent, unsupported_card);
new_page(parent, unsupported_card);
}

const LVM2UnsupportedLogicalVolumeCard = ({ card, vgroup, lvol }) => {
Expand Down
36 changes: 13 additions & 23 deletions pkg/storaged/lvm2/volume-group.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { SDesc } from "../utils/desc.jsx";
import { StorageButton, StorageLink, StorageSize } from "../storage-controls.jsx";
import {
StorageCard, PageTable, new_page, new_card, get_crossrefs,
navigate_to_new_card_location, navigate_away_from_card
} from "../pages.jsx";
import {
fmt_size_long, get_active_usage, teardown_active_usage, for_each_async,
Expand All @@ -45,7 +46,6 @@ import {
} from "../dialog.jsx";

import { create_logical_volume } from "./create-logical-volume-dialog.jsx";

import { make_block_logical_volume_card } from "./block-logical-volume.jsx";
import { make_vdo_pool_card } from "./vdo-pool.jsx";
import { make_thin_pool_logical_volume_page } from "./thin-pool-logical-volume.jsx";
Expand All @@ -55,9 +55,7 @@ import { make_block_page } from "../block/create-pages.jsx";

const _ = cockpit.gettext;

export function vgroup_rename(client, vgroup) {
const location = cockpit.location;

function vgroup_rename(client, vgroup, card) {
dialog_open({
Title: _("Rename volume group"),
Fields: [
Expand All @@ -69,18 +67,15 @@ export function vgroup_rename(client, vgroup) {
],
Action: {
Title: _("Rename"),
action: function (vals) {
return vgroup.Rename(vals.name, { })
.then(function () {
location.go(['vg', vals.name]);
});
action: async function (vals) {
await vgroup.Rename(vals.name, { });
navigate_to_new_card_location(card, ["vg", vals.name]);
}
}
});
}

export function vgroup_delete(client, vgroup, parent_page) {
const location = cockpit.location;
function vgroup_delete(client, vgroup, card) {
const usage = get_active_usage(client, vgroup.path, _("delete"));

if (usage.Blocking) {
Expand All @@ -99,16 +94,11 @@ export function vgroup_delete(client, vgroup, parent_page) {
Danger: _("Deleting erases all data on a volume group."),
Title: _("Delete"),
disable_on_error: usage.Teardown,
action: function () {
return teardown_active_usage(client, usage)
.then(function () {
return vgroup.Delete(true,
{ 'tear-down': { t: 'b', v: true } })
.then(reload_systemd)
.then(function () {
location.go(parent_page.location);
});
});
action: async function () {
await teardown_active_usage(client, usage);
await vgroup.Delete(true, { 'tear-down': { t: 'b', v: true } });
await reload_systemd();
navigate_away_from_card(card);
}
},
Inits: [
Expand Down Expand Up @@ -257,7 +247,7 @@ export function make_lvm2_volume_group_page(parent, vgroup) {
actions: [
{
title: _("Delete group"),
action: () => vgroup_delete(client, vgroup, parent),
action: () => vgroup_delete(client, vgroup, vgroup_card),
danger: true,
tag: "group",
},
Expand Down Expand Up @@ -390,7 +380,7 @@ const LVM2VolumeGroupCard = ({ card, vgroup }) => {
<DescriptionList className="pf-m-horizontal-on-sm">
<SDesc title={_("Name")}
value={vgroup.Name}
action={<StorageLink onClick={() => vgroup_rename(client, vgroup)}
action={<StorageLink onClick={() => vgroup_rename(client, vgroup, card)}
excuse={has_missing_pvs && _("A volume group with missing physical volumes can not be renamed.")}>
{_("edit")}
</StorageLink>} />
Expand Down
18 changes: 7 additions & 11 deletions pkg/storaged/mdraid/mdraid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc

import { SDesc } from "../utils/desc.jsx";
import { StorageButton, StorageSize } from "../storage-controls.jsx";
import { StorageCard, PageTable, new_page, new_card, get_crossrefs } from "../pages.jsx";
import { StorageCard, PageTable, new_page, new_card, get_crossrefs, navigate_away_from_card } from "../pages.jsx";
import { make_block_page } from "../block/create-pages.jsx";
import {
block_name, mdraid_name, encode_filename, decode_filename,
Expand Down Expand Up @@ -86,9 +86,7 @@ function mdraid_stop(mdraid) {
return mdraid.Stop({});
}

function mdraid_delete(mdraid, block) {
const location = cockpit.location;

function mdraid_delete(mdraid, block, card) {
function delete_() {
if (mdraid.Delete)
return mdraid.Delete({ 'tear-down': { t: 'b', v: true } }).then(reload_systemd);
Expand Down Expand Up @@ -123,12 +121,10 @@ function mdraid_delete(mdraid, block) {
Action: {
Title: _("Delete"),
Danger: _("Deleting erases all data on a MDRAID device."),
action: function () {
return teardown_active_usage(client, usage)
.then(delete_)
.then(function () {
location.go('/');
});
action: async function () {
await teardown_active_usage(client, usage);
await delete_();
navigate_away_from_card(card);
}
},
Inits: [
Expand Down Expand Up @@ -223,7 +219,7 @@ export function make_mdraid_page(parent, mdraid) {
start_stop_action(mdraid),
{
title: _("Delete"),
action: () => mdraid_delete(mdraid, block),
action: () => mdraid_delete(mdraid, block, mdraid_card),
danger: true,
},
]),
Expand Down
48 changes: 22 additions & 26 deletions pkg/storaged/nfs/nfs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {

import { SDesc } from "../utils/desc.jsx";
import { StorageUsageBar } from "../storage-controls.jsx";
import { StorageCard, new_page, new_card } from "../pages.jsx";
import { StorageCard, new_page, new_card, 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 @@ -82,7 +82,7 @@ function get_exported_directories(server) {
});
}

export function nfs_fstab_dialog(client, entry) {
export function nfs_fstab_dialog(client, entry, card) {
const mount_options = entry ? entry.fields[3] : "defaults";
const split_options = parse_options(mount_options == "defaults" ? "" : mount_options);
const opt_auto = !extract_option(split_options, "noauto");
Expand Down Expand Up @@ -182,21 +182,19 @@ export function nfs_fstab_dialog(client, entry) {
},
Action: {
Title: entry ? _("Save") : _("Add"),
action: function (vals) {
const location = cockpit.location;
const fields = [vals.server + ":" + vals.remote,
action: async function (vals) {
const fields = [
vals.server + ":" + vals.remote,
vals.dir,
entry ? entry.fields[2] : "nfs",
mounting_options(vals) || "defaults"];
mounting_options(vals) || "defaults"
];
if (entry) {
return client.nfs.update_entry(entry, fields)
.then(function () {
if (entry.fields[0] != fields[0] ||
entry.fields[1] != fields[1])
location.go(["nfs", fields[0], fields[1]]);
});
await client.nfs.update_entry(entry, fields);
if (entry.fields[0] != fields[0] || entry.fields[1] != fields[1])
navigate_to_new_card_location(card, ["nfs", fields[0], fields[1]]);
} else
return client.nfs.add_entry(fields);
await client.nfs.add_entry(fields);
}
}
});
Expand Down Expand Up @@ -231,12 +229,11 @@ function mount(client, entry) {
client.nfs.mount_entry(entry));
}

function unmount(client, entry) {
const location = cockpit.location;
function unmount(client, entry, card) {
client.nfs.unmount_entry(entry)
.then(function () {
if (!entry.fstab)
location.go("/");
navigate_away_from_card(card);
})
.catch(function (error) {
nfs_busy_dialog(client,
Expand All @@ -247,21 +244,20 @@ function unmount(client, entry) {
return client.nfs.stop_and_unmount_entry(users, entry)
.then(function () {
if (!entry.fstab)
location.go("/");
navigate_away_from_card(card);
});
});
});
}

function edit(client, entry) {
nfs_fstab_dialog(client, entry);
function edit(client, entry, card) {
nfs_fstab_dialog(client, entry, card);
}

function remove(client, entry) {
const location = cockpit.location;
function remove(client, entry, card) {
client.nfs.remove_entry(entry)
.then(function () {
location.go("/");
navigate_away_from_card(card);
})
.catch(function (error) {
nfs_busy_dialog(client,
Expand All @@ -271,7 +267,7 @@ function remove(client, entry) {
function (users) {
return client.nfs.stop_and_remove_entry(users, entry)
.then(function () {
location.go("/");
navigate_away_from_card(card);
});
});
});
Expand Down Expand Up @@ -303,13 +299,13 @@ export function make_nfs_page(parent, entry) {
props: { entry },
actions: [
(entry.mounted
? { title: _("Unmount"), action: () => unmount(client, entry) }
? { title: _("Unmount"), action: () => unmount(client, entry, nfs_card) }
: { title: _("Mount"), action: () => mount(client, entry) }),
(entry.fstab
? { title: _("Edit"), action: () => edit(client, entry) }
? { title: _("Edit"), action: () => edit(client, entry, nfs_card) }
: null),
(entry.fstab
? { title: _("Remove"), action: () => remove(client, entry), danger: true }
? { title: _("Remove"), action: () => remove(client, entry, nfs_card), danger: true }
: null),
]
});
Expand Down
2 changes: 1 addition & 1 deletion pkg/storaged/overview/overview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const OverviewCard = ({ card, plot_state }) => {
menu_item(null, _("Create MDRAID device"), () => create_mdraid()),
menu_item(lvm2_feature, _("Create LVM2 volume group"), () => create_vgroup(client)),
menu_item(stratis_feature, _("Create Stratis pool"), () => create_stratis_pool(client)),
menu_item(nfs_feature, _("New NFS mount"), () => nfs_fstab_dialog(client, null)),
menu_item(nfs_feature, _("New NFS mount"), () => nfs_fstab_dialog(client, null, null)),
menu_item(iscsi_feature, _("Change iSCSI initiater name"), () => iscsi_change_name(client)),
menu_item(iscsi_feature, _("Add iSCSI portal"), () => iscsi_discover(client)),
].filter(item => item !== null);
Expand Down
12 changes: 10 additions & 2 deletions pkg/storaged/pages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,22 @@ export function get_page_from_location(location) {
/* Common UI things
*/

export function navigate_away_from_page(page) {
export function navigate_away_from_card(card) {
if (!card)
return;

const loc = cockpit.location;
const page = card.page;
if (page.parent && JSON.stringify(loc.path) == JSON.stringify(page.location))
loc.go(page.parent.location);
}

export function navigate_to_new_page_location(page, location) {
export function navigate_to_new_card_location(card, location) {
if (!card)
return;

const loc = cockpit.location;
const page = card.page;
if (JSON.stringify(loc.path) == JSON.stringify(page.location))
loc.go(location);
}
Expand Down
Loading

0 comments on commit 75cd39d

Please sign in to comment.