From efddee6c45946f1f2385ea439538795deaf87389 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Wed, 24 Jan 2024 14:05:13 +0200 Subject: [PATCH] storage: Move "Format" action one card up Offer it on the "Partition" card instead of the "Filesystem" card, for example. This makes more sense. One formats a partition, but mounts the filesystem. --- pkg/lib/cockpit-components-dynamic-list.jsx | 2 +- .../format-disk-dialog.jsx | 0 pkg/storaged/block/other.jsx | 2 +- pkg/storaged/block/unformatted-data.jsx | 3 -- pkg/storaged/block/unrecognized-data.jsx | 3 -- pkg/storaged/btrfs/device.jsx | 2 - pkg/storaged/crypto/locked-encrypted-data.jsx | 3 -- pkg/storaged/drive/drive.jsx | 4 +- pkg/storaged/filesystem/filesystem.jsx | 2 - pkg/storaged/legacy-vdo/legacy-vdo.jsx | 2 + pkg/storaged/lvm2/block-logical-volume.jsx | 2 + pkg/storaged/lvm2/physical-volume.jsx | 2 - pkg/storaged/mdraid/mdraid-disk.jsx | 2 - pkg/storaged/mdraid/mdraid.jsx | 20 +++++----- pkg/storaged/partitions/actions.jsx | 40 ------------------- pkg/storaged/partitions/partition.jsx | 2 + pkg/storaged/stratis/blockdev.jsx | 2 - pkg/storaged/swap/swap.jsx | 2 - test/reference | 2 +- 19 files changed, 20 insertions(+), 77 deletions(-) rename pkg/storaged/{partitions => block}/format-disk-dialog.jsx (100%) delete mode 100644 pkg/storaged/partitions/actions.jsx diff --git a/pkg/lib/cockpit-components-dynamic-list.jsx b/pkg/lib/cockpit-components-dynamic-list.jsx index 46b483b3148c..12c376070978 100644 --- a/pkg/lib/cockpit-components-dynamic-list.jsx +++ b/pkg/lib/cockpit-components-dynamic-list.jsx @@ -57,7 +57,7 @@ export class DynamicListForm extends React.Component { addItem() { this.setState(state => { - return { list: [...state.list, {key: this.keyCounter++, ...this.props.default}] }; + return { list: [...state.list, { key: this.keyCounter++, ...this.props.default }] }; }, () => this.props.onChange(this.state.list)); } diff --git a/pkg/storaged/partitions/format-disk-dialog.jsx b/pkg/storaged/block/format-disk-dialog.jsx similarity index 100% rename from pkg/storaged/partitions/format-disk-dialog.jsx rename to pkg/storaged/block/format-disk-dialog.jsx diff --git a/pkg/storaged/block/other.jsx b/pkg/storaged/block/other.jsx index a564a3f9ad74..bc0239dad24e 100644 --- a/pkg/storaged/block/other.jsx +++ b/pkg/storaged/block/other.jsx @@ -26,7 +26,7 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index. import { StorageCard, StorageDescription, new_card } from "../pages.jsx"; import { block_name, should_ignore } from "../utils.js"; -import { partitionable_block_actions } from "../partitions/actions.jsx"; +import { partitionable_block_actions } from "./actions.jsx"; import { OtherIcon } from "../icons/gnome-icons.jsx"; import { make_block_page } from "../block/create-pages.jsx"; diff --git a/pkg/storaged/block/unformatted-data.jsx b/pkg/storaged/block/unformatted-data.jsx index 7c4e5ed12c01..6843905e9e8d 100644 --- a/pkg/storaged/block/unformatted-data.jsx +++ b/pkg/storaged/block/unformatted-data.jsx @@ -18,10 +18,8 @@ */ import cockpit from "cockpit"; -import client from "../client"; import { StorageCard, new_card } from "../pages.jsx"; -import { format_dialog } from "./format-dialog.jsx"; import { std_lock_action } from "../crypto/actions.jsx"; const _ = cockpit.gettext; @@ -33,7 +31,6 @@ export function make_unformatted_data_card(next, backing_block, content_block) { component: StorageCard, actions: [ std_lock_action(backing_block, content_block), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); } diff --git a/pkg/storaged/block/unrecognized-data.jsx b/pkg/storaged/block/unrecognized-data.jsx index f5056d6524f9..ce682df63913 100644 --- a/pkg/storaged/block/unrecognized-data.jsx +++ b/pkg/storaged/block/unrecognized-data.jsx @@ -19,13 +19,11 @@ import cockpit from "cockpit"; import React from "react"; -import client from "../client"; import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js"; import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; import { StorageCard, StorageDescription, new_card } from "../pages.jsx"; -import { format_dialog } from "./format-dialog.jsx"; import { std_lock_action } from "../crypto/actions.jsx"; const _ = cockpit.gettext; @@ -38,7 +36,6 @@ export function make_unrecognized_data_card(next, backing_block, content_block) props: { backing_block, content_block }, actions: [ std_lock_action(backing_block, content_block), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); } diff --git a/pkg/storaged/btrfs/device.jsx b/pkg/storaged/btrfs/device.jsx index 7e6dbb33f139..a31ea237a653 100644 --- a/pkg/storaged/btrfs/device.jsx +++ b/pkg/storaged/btrfs/device.jsx @@ -28,7 +28,6 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx"; import { StorageUsageBar } from "../storage-controls.jsx"; import { std_lock_action } from "../crypto/actions.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { btrfs_device_usage } from "./utils.jsx"; const _ = cockpit.gettext; @@ -46,7 +45,6 @@ export function make_btrfs_device_card(next, backing_block, content_block, block props: { backing_block, content_block }, actions: [ std_lock_action(backing_block, content_block), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ], }); diff --git a/pkg/storaged/crypto/locked-encrypted-data.jsx b/pkg/storaged/crypto/locked-encrypted-data.jsx index 155aade4e7d0..59712de98b01 100644 --- a/pkg/storaged/crypto/locked-encrypted-data.jsx +++ b/pkg/storaged/crypto/locked-encrypted-data.jsx @@ -18,10 +18,8 @@ */ import cockpit from "cockpit"; -import client from "../client"; import { StorageCard, new_card } from "../pages.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { unlock } from "./actions.jsx"; const _ = cockpit.gettext; @@ -35,7 +33,6 @@ export function make_locked_encrypted_data_card(next, block) { props: { block }, actions: [ { title: _("Unlock"), action: () => unlock(block) }, - { title: _("Format"), action: () => format_dialog(client, block.path), danger: true }, ] }); } diff --git a/pkg/storaged/drive/drive.jsx b/pkg/storaged/drive/drive.jsx index c6fdd96874fd..d8b97ab0b7ca 100644 --- a/pkg/storaged/drive/drive.jsx +++ b/pkg/storaged/drive/drive.jsx @@ -29,7 +29,7 @@ import { HDDIcon, SSDIcon, MediaDriveIcon } from "../icons/gnome-icons.jsx"; import { StorageCard, StorageDescription, new_card, new_page } from "../pages.jsx"; import { block_name, drive_name, format_temperature, fmt_size_long, should_ignore } from "../utils.js"; import { make_block_page } from "../block/create-pages.jsx"; -import { partitionable_block_actions } from "../partitions/actions.jsx"; +import { partitionable_block_actions } from "../block/actions.jsx"; const _ = cockpit.gettext; @@ -81,7 +81,7 @@ export function make_drive_page(parent, drive) { job_path: drive.path, component: DriveCard, props: { drive }, - actions: block.Size > 0 ? partitionable_block_actions(block) : [], + actions: partitionable_block_actions(block), }); if (block.Size > 0) { diff --git a/pkg/storaged/filesystem/filesystem.jsx b/pkg/storaged/filesystem/filesystem.jsx index 0f30345ed2bd..6ce68f0311a4 100644 --- a/pkg/storaged/filesystem/filesystem.jsx +++ b/pkg/storaged/filesystem/filesystem.jsx @@ -34,7 +34,6 @@ import { import { StorageLink, StorageUsageBar, StorageSize } from "../storage-controls.jsx"; import { StorageCard, StorageDescription, new_card, useIsNarrow } from "../pages.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { is_mounted, MountPoint, mount_point_text } from "./utils.jsx"; import { mounting_dialog } from "./mounting-dialog.jsx"; import { check_mismounted_fsys, MismountAlert } from "./mismounting.jsx"; @@ -106,7 +105,6 @@ export function make_filesystem_card(next, backing_block, content_block, fstab_c primary: true, action: () => mounting_dialog(client, content_block || backing_block, "mount"), }, - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); } diff --git a/pkg/storaged/legacy-vdo/legacy-vdo.jsx b/pkg/storaged/legacy-vdo/legacy-vdo.jsx index 198c3904295f..15e1e32d3f25 100644 --- a/pkg/storaged/legacy-vdo/legacy-vdo.jsx +++ b/pkg/storaged/legacy-vdo/legacy-vdo.jsx @@ -33,6 +33,7 @@ import { StorageButton, StorageOnOff } from "../storage-controls.jsx"; import { StorageCard, new_page, new_card } from "../pages.jsx"; import { make_block_page } from "../block/create-pages.jsx"; +import { block_actions } from "../block/actions.jsx"; import inotify_py from "inotify.py"; import vdo_monitor_py from "./vdo-monitor.py"; @@ -149,6 +150,7 @@ export function make_legacy_vdo_page(parent, vdo, backing_block, next_card) { ? { title: _("Stop"), action: stop } : { title: _("Start"), action: () => vdo.start() } ), + ...block_actions(block), { title: _("Delete"), action: delete_, danger: true } ], }); diff --git a/pkg/storaged/lvm2/block-logical-volume.jsx b/pkg/storaged/lvm2/block-logical-volume.jsx index 7331d860afb0..7464b6d08b08 100644 --- a/pkg/storaged/lvm2/block-logical-volume.jsx +++ b/pkg/storaged/lvm2/block-logical-volume.jsx @@ -30,6 +30,7 @@ import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/ind import { StorageButton, StorageLink } from "../storage-controls.jsx"; import { check_unused_space, get_resize_info, grow_dialog, shrink_dialog } from "../block/resize.jsx"; +import { block_actions } from "../block/actions.jsx"; import { StorageCard, StorageDescription, 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 { @@ -218,6 +219,7 @@ export function make_block_logical_volume_card(next, vgroup, lvol, block) { }, lvm2_create_snapshot_action(lvol), repair_action, + ...block_actions(block), { title: _("Delete"), action: () => lvol_delete(lvol, card), diff --git a/pkg/storaged/lvm2/physical-volume.jsx b/pkg/storaged/lvm2/physical-volume.jsx index d3f2c1482779..b754c0100a66 100644 --- a/pkg/storaged/lvm2/physical-volume.jsx +++ b/pkg/storaged/lvm2/physical-volume.jsx @@ -26,7 +26,6 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index. import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { std_lock_action } from "../crypto/actions.jsx"; import { StorageUsageBar } from "../storage-controls.jsx"; @@ -47,7 +46,6 @@ export function make_lvm2_physical_volume_card(next, backing_block, content_bloc props: { backing_block, content_block }, actions: [ std_lock_action(backing_block, content_block), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); diff --git a/pkg/storaged/mdraid/mdraid-disk.jsx b/pkg/storaged/mdraid/mdraid-disk.jsx index ada102336118..cb85235e7b96 100644 --- a/pkg/storaged/mdraid/mdraid-disk.jsx +++ b/pkg/storaged/mdraid/mdraid-disk.jsx @@ -26,7 +26,6 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index. import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { block_short_name, fmt_size, mdraid_name } from "../utils.js"; import { std_lock_action } from "../crypto/actions.jsx"; @@ -44,7 +43,6 @@ export function make_mdraid_disk_card(next, backing_block, content_block) { props: { backing_block, content_block, mdraid }, actions: [ std_lock_action(backing_block, content_block), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); diff --git a/pkg/storaged/mdraid/mdraid.jsx b/pkg/storaged/mdraid/mdraid.jsx index 4803cbdddc63..cc94cd20fb54 100644 --- a/pkg/storaged/mdraid/mdraid.jsx +++ b/pkg/storaged/mdraid/mdraid.jsx @@ -46,7 +46,7 @@ import { init_active_usage_processes } from "../dialog.jsx"; -import { partitionable_block_actions } from "../partitions/actions.jsx"; +import { partitionable_block_actions } from "../block/actions.jsx"; const _ = cockpit.gettext; @@ -145,7 +145,7 @@ function start_stop_action(mdraid) { // "Stop" is only in the card, to discourage stopping. if (!running) - return { title: _("Start"), action: () => mdraid_start(mdraid), tag: "device" }; + return { title: _("Start"), action: () => mdraid_start(mdraid) }; else return null; } @@ -229,15 +229,13 @@ export function make_mdraid_page(parent, mdraid) { excuse: add_excuse, tag: "disks", }), - ].concat( - (block ? partitionable_block_actions(block, "device") : []).concat( - [ - { - title: _("Delete"), - action: () => mdraid_delete(mdraid, block, mdraid_card), - danger: true, - }, - ])), + ...partitionable_block_actions(block), + { + title: _("Delete"), + action: () => mdraid_delete(mdraid, block, mdraid_card), + danger: true, + }, + ], }); if (!block) { diff --git a/pkg/storaged/partitions/actions.jsx b/pkg/storaged/partitions/actions.jsx deleted file mode 100644 index dd936c9c0785..000000000000 --- a/pkg/storaged/partitions/actions.jsx +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of Cockpit. - * - * Copyright (C) 2023 Red Hat, Inc. - * - * Cockpit is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * Cockpit is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Cockpit; If not, see . - */ - -import cockpit from "cockpit"; - -import { format_disk } from "./format-disk-dialog.jsx"; - -const _ = cockpit.gettext; - -export function partitionable_block_actions(block, tag) { - const excuse = block.ReadOnly ? _("Device is read-only") : null; - - return [ - (block.Size > 0 - ? { - title: _("Create partition table"), - action: () => format_disk(block), - danger: true, - excuse, - tag - } - : null) - ]; -} diff --git a/pkg/storaged/partitions/partition.jsx b/pkg/storaged/partitions/partition.jsx index 5bb5cab85643..f2502b135439 100644 --- a/pkg/storaged/partitions/partition.jsx +++ b/pkg/storaged/partitions/partition.jsx @@ -33,6 +33,7 @@ import { } from "../dialog.jsx"; import { block_name, fmt_size, get_active_usage, teardown_active_usage, reload_systemd } from "../utils.js"; import { check_unused_space, get_resize_info, free_space_after_part, grow_dialog, shrink_dialog } from "../block/resize.jsx"; +import { block_actions } from "../block/actions.jsx"; import { StorageCard, StorageDescription, new_card, navigate_away_from_card } from "../pages.jsx"; const _ = cockpit.gettext; @@ -100,6 +101,7 @@ export function make_partition_card(next, block) { action: () => grow_dialog(client, block_part, info), excuse: grow_excuse, }), + ...block_actions(block), { title: _("Delete"), action: () => delete_partition(block, card), diff --git a/pkg/storaged/stratis/blockdev.jsx b/pkg/storaged/stratis/blockdev.jsx index 117f268a5614..5e7f8cdbda51 100644 --- a/pkg/storaged/stratis/blockdev.jsx +++ b/pkg/storaged/stratis/blockdev.jsx @@ -26,7 +26,6 @@ import { CardBody } from "@patternfly/react-core/dist/esm/components/Card/index. import { DescriptionList } from "@patternfly/react-core/dist/esm/components/DescriptionList/index.js"; import { StorageCard, StorageDescription, new_card, register_crossref } from "../pages.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { fmt_size } from "../utils.js"; import { std_lock_action } from "../crypto/actions.jsx"; @@ -45,7 +44,6 @@ export function make_stratis_blockdev_card(next, backing_block, content_block) { props: { backing_block, content_block, pool, stopped_pool }, actions: [ std_lock_action(backing_block, content_block), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); diff --git a/pkg/storaged/swap/swap.jsx b/pkg/storaged/swap/swap.jsx index de588dfc2667..4172865f777c 100644 --- a/pkg/storaged/swap/swap.jsx +++ b/pkg/storaged/swap/swap.jsx @@ -26,7 +26,6 @@ import { DescriptionList } from "@patternfly/react-core/dist/esm/components/Desc import { useEvent } from "hooks"; import { StorageCard, StorageDescription, new_card } from "../pages.jsx"; -import { format_dialog } from "../block/format-dialog.jsx"; import { fmt_size, decode_filename, encode_filename, parse_options, unparse_options, extract_option, @@ -97,7 +96,6 @@ export function make_swap_card(next, backing_block, content_block) { (block_swap && !block_swap.Active ? { title: _("Start"), action: start } : null), - { title: _("Format"), action: () => format_dialog(client, backing_block.path), danger: true }, ] }); } diff --git a/test/reference b/test/reference index 06eda9a23bea..1c5bb63444af 160000 --- a/test/reference +++ b/test/reference @@ -1 +1 @@ -Subproject commit 06eda9a23bea359998946b439860100cd3763417 +Subproject commit 1c5bb63444af268b2f602365ce225694bccb055b