Skip to content

Commit

Permalink
web: small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Dec 16, 2024
1 parent 4c0e887 commit 47f8436
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
8 changes: 5 additions & 3 deletions web/src/components/overview/StorageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ export default function StorageSection() {
return _("Install using several devices with a custom strategy to find the needed space.");
};

if (drives.length === 0) return <Text>{_("No device selected yet")}</Text>;
if (!drives.find((dr) => devices.map((d) => d.name).includes(dr.name)))
return <Text>{_("No device selected yet")}</Text>;
const existDevice = (name) => devices.some((d) => d.name === name);
const noDrive = drives.length === 0 || drives.some((d) => !existDevice(d));

if (noDrive) return <Text>{_("No device selected yet")}</Text>;

if (drives.length > 1) {
return (
<Content>
Expand Down
21 changes: 8 additions & 13 deletions web/src/components/storage/DriveEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
*/

import React, { useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useNavigate, generatePath } from "react-router-dom";
import { _, formatList } from "~/i18n";
import { sprintf } from "sprintf-js";
import { baseName, deviceLabel, formattedPath, SPACE_POLICIES } from "~/components/storage/utils";
import { useAvailableDevices } from "~/queries/storage";
import { configModel } from "~/api/storage/types";
import { StorageDevice } from "~/types/storage";
import { STORAGE as PATHS } from "~/routes/paths";
import { useChangeDrive, useSetSpacePolicy } from "~/queries/storage";
import * as driveUtils from "~/components/storage/utils/drive";
import { typeDescription, contentDescription } from "~/components/storage/utils/device";
import { Icon } from "../layout";
Expand All @@ -50,9 +52,6 @@ import {
MenuToggle,
} from "@patternfly/react-core";

import { useChangeDrive, useSetSpacePolicy } from "~/queries/storage";
import { Drive } from "~/api/storage/types/config-model";

type DriveEditorProps = { drive: configModel.Drive; driveDevice: StorageDevice };

// FIXME: Presentation is quite poor
Expand Down Expand Up @@ -92,9 +91,9 @@ const SpacePolicySelector = ({ drive, driveDevice }: DriveEditorProps) => {
const navigate = useNavigate();
const setSpacePolicy = useSetSpacePolicy();
const onToggle = () => setIsOpen(!isOpen);
const onSpacePolicyChange = (spacePolicy: "keep" | "delete" | "resize" | "custom") => {
const onSpacePolicyChange = (spacePolicy: configModel.SpacePolicy) => {
if (spacePolicy === "custom") {
return navigate("/storage/space-policy/" + baseName(drive.name));
return navigate(generatePath(PATHS.spacePolicy, { id: baseName(drive.name) }));
} else {
setSpacePolicy(drive.name, spacePolicy);
setIsOpen(false);
Expand Down Expand Up @@ -157,7 +156,7 @@ const SpacePolicySelector = ({ drive, driveDevice }: DriveEditorProps) => {
};

const SearchSelectorIntro = ({ drive }) => {
const mainText = (drive: Drive): string => {
const mainText = (drive: configModel.Drive): string => {
if (driveUtils.hasReuse(drive)) {
// The current device will be the only option to choose from
return _("This uses existing partitions at the device");
Expand Down Expand Up @@ -213,7 +212,7 @@ const SearchSelectorIntro = ({ drive }) => {
);
};

const extraText = (drive: Drive): string => {
const extraText = (drive: configModel.Drive): string => {
// Nothing to add in these cases
if (driveUtils.hasReuse(drive)) return;
if (!driveUtils.hasFilesystem(drive)) return;
Expand Down Expand Up @@ -314,7 +313,7 @@ const SearchSelectorMultipleOptions = ({ selected, withNewVg = false, onChange }
return (
<MenuItem
component="a"
onClick={() => navigate("/storage/target-device")}
onClick={() => navigate(PATHS.targetDevice)}
itemId="lvm"
description={_("The configured partitions will be created as logical volumes")}
>
Expand Down Expand Up @@ -513,7 +512,6 @@ const DriveHeader = ({ drive, driveDevice }: DriveEditorProps) => {
};

const PartitionsNoContentSelector = () => {
const navigate = useNavigate();
const menuRef = useRef();
const toggleMenuRef = useRef();
const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -547,7 +545,6 @@ const PartitionsNoContentSelector = () => {
key="add-partition"
itemId="add-partition"
description={_("Add another partition or mount an existing one")}
onClick={() => navigate("/storage/space-policy")}
>
<Flex component="span" justifyContent={{ default: "justifyContentSpaceBetween" }}>
<span>{_("Add or use partition")}</span>
Expand All @@ -562,7 +559,6 @@ const PartitionsNoContentSelector = () => {
};

const PartitionsWithContentSelector = ({ drive }) => {
const navigate = useNavigate();
const menuRef = useRef();
const toggleMenuRef = useRef();
const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -626,7 +622,6 @@ const PartitionsWithContentSelector = ({ drive }) => {
key="add-partition"
itemId="add-partition"
description={_("Add another partition or mount an existing one")}
onClick={() => navigate("/storage/space-policy")}
>
<Flex component="span" justifyContent={{ default: "justifyContentSpaceBetween" }}>
<span>{_("Add or use partition")}</span>
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/storage/SpacePolicySelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import { SpaceActionsTable } from "~/components/storage";
import { baseName, deviceChildren } from "~/components/storage/utils";
import { _ } from "~/i18n";
import { PartitionSlot, SpacePolicyAction, StorageDevice } from "~/types/storage";
import { Partition } from "~/api/storage/types/config-model";
import { configModel } from "~/api/storage/types";
import { useConfigModel, useDevices, useSetCustomSpacePolicy } from "~/queries/storage";
import { toStorageDevice } from "./device-utils";
import { sprintf } from "sprintf-js";

const partitionAction = (partition: Partition) => {
const partitionAction = (partition: configModel.Partition) => {
if (partition.delete) return "delete";
if (partition.resizeIfNeeded) return "resizeIfNeeded";

Expand Down
5 changes: 2 additions & 3 deletions web/src/components/storage/utils/drive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { _, n_, formatList } from "~/i18n";
import { configModel } from "~/api/storage/types";
import { SpacePolicy, SPACE_POLICIES, baseName, formattedPath } from "~/components/storage/utils";
import * as partitionUtils from "~/components/storage/utils/partition";
import { Drive } from "~/api/storage/types/config-model";
import { sprintf } from "sprintf-js";

/**
Expand Down Expand Up @@ -160,11 +159,11 @@ const hasReuse = (drive: configModel.Drive): boolean => {
return drive.partitions && drive.partitions.some((p) => p.mountPath && p.name);
};

const hasPv = (drive: Drive): boolean => {
const hasPv = (drive: configModel.Drive): boolean => {
return drive.volumeGroups && drive.volumeGroups.length > 0;
};

const explicitBoot = (drive: Drive): boolean => {
const explicitBoot = (drive: configModel.Drive): boolean => {
return drive.boot && drive.boot === "explicit";
};

Expand Down

0 comments on commit 47f8436

Please sign in to comment.