Skip to content

Commit

Permalink
storage: Simplify "Initialize disk" dialog
Browse files Browse the repository at this point in the history
Use radio buttons, and only offer MBR when it will work.
  • Loading branch information
mvollmer committed Apr 12, 2024
1 parent 2e613ab commit c5c38a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions pkg/storaged/block/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import cockpit from "cockpit";
import client from "../client";

import { format_disk } from "./format-disk-dialog.jsx";
import { initialize_disk_dialog } from "../partitions/initialize-disk-dialog.jsx";
import { format_dialog } from "./format-dialog.jsx";
import { format_swap_dialog } from "../swap/format-dialog.jsx";
import { erase_dialog } from "./erase-dialog.jsx";
Expand All @@ -37,8 +37,8 @@ export function block_actions(block, kind) {
if (client.blocks_available[block.path]) {
if (kind == "part") {
actions.push({
title: _("Create partitions"),
action: () => format_disk(block),
title: _("Initialize for partitions"),
action: () => initialize_disk_dialog(block),
primary: true,
excuse,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import client from "../client";

import {
dialog_open,
SelectOne,
SelectOneRadioVertical,
BlockingMessage, TeardownMessage,
init_active_usage_processes
} from "../dialog.jsx";
Expand All @@ -31,8 +31,8 @@ import { job_progress_wrapper } from "../jobs-panel.jsx";

const _ = cockpit.gettext;

export function format_disk(block) {
const usage = get_active_usage(client, block.path, _("initialize"), _("delete"));
export function initialize_disk_dialog(block) {
const usage = get_active_usage(client, block.path, _("write partition table"), _("delete"));

if (usage.Blocking) {
dialog_open({
Expand All @@ -42,24 +42,24 @@ export function format_disk(block) {
return;
}

const offer_mbr = block.Size < 2 * 1024 * 1024 * 1024 * 1024; // 2 TiB

dialog_open({
Title: cockpit.format(_("Create partitions on $0"), block_name(block)),
Title: cockpit.format(_("Initialize $0 for partitions"), block_name(block)),
Teardown: TeardownMessage(usage),
Fields: [
SelectOne("type", _("Type"),
SelectOneRadioVertical("type", _("Type"),
{
value: "gpt",
choices: [
{ value: "dos", title: _("Compatible with all systems and devices (MBR)") },
{
value: "gpt",
title: _("Compatible with modern system and hard disks > 2TB (GPT)")
},
]
{ value: "gpt", title: _("Modern (GPT)") },
{ value: "dos", title: _("Legacy (MBR)") },
],
visible: () => offer_mbr,
}),
],
Action: {
Title: _("Create partition table"),
Title: _("Initialize for partitions"),
wrapper: job_progress_wrapper(client, block.path),
disable_on_error: usage.Teardown,
action: async function (vals) {
Expand All @@ -68,7 +68,7 @@ export function format_disk(block) {
};

await teardown_active_usage(client, usage);
await block.Format(vals.type, options);
await block.Format(offer_mbr ? vals.type : "gpt", options);
await reload_systemd();
}
},
Expand Down

0 comments on commit c5c38a9

Please sign in to comment.