From 2bf6ad3754088c353cad8efccf12b5e0563a62b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 13:26:54 +0000 Subject: [PATCH] WIP --- .../storage/ProposalActionsSection.jsx | 144 +++++++++++++++++- web/src/components/storage/ProposalPage.jsx | 4 + .../storage/ProposalSpacePolicySection.jsx | 78 +++++----- 3 files changed, 187 insertions(+), 39 deletions(-) diff --git a/web/src/components/storage/ProposalActionsSection.jsx b/web/src/components/storage/ProposalActionsSection.jsx index 8d35563afd..b4baee4413 100644 --- a/web/src/components/storage/ProposalActionsSection.jsx +++ b/web/src/components/storage/ProposalActionsSection.jsx @@ -29,6 +29,7 @@ import { import { sprintf } from "sprintf-js"; import { _, n_ } from "~/i18n"; +import { deviceSize } from "~/components/storage/utils"; import { If, Section } from "~/components/core"; import { partition } from "~/utils"; @@ -104,6 +105,132 @@ const ActionsSkeleton = () => { ); }; +class DevicesManager { + constructor(system, staging) { + this.system = system; + this.staging = staging; + } + + systemDevice(sid) { + return this.system.find(d => d.sid === sid); + } + + device(sid) { + return this.staging.find(d => d.sid === sid); + } + + lvmVgsWithMountPoints() { + const vgs = this.staging.filter(d => d.type === "lvmVg"); + return vgs.filter(v => v.logicalVolumes.find(l => l.filesystem?.mountPath !== undefined)); + } + + children(device) { + if (device.partitionTable) return this.partitionTableChildren(device.partitionTable); + if (device.type === "lvmVg") return this.lvmVgChildren(device); + return []; + } + + partitionTableChildren(partitionTable) { + const { partitions, unusedSlots } = partitionTable; + const children = partitions.concat(unusedSlots); + + return children.sort((a, b) => a.start < b.start ? -1 : 1); + } + + lvmVgChildren(lvmVg) { + return lvmVg.logicalVolumes.sort((a, b) => a.name < b.name ? -1 : 1); + } + + isSlot(storageElement) { + return storageElement.sid === undefined; + } +} + +class SlotPresenter { + constructor(slot) { + this.slot = slot; + } + + name() { + return ""; + } + + details() { + return "Unused space"; + } + + size() { + return deviceSize(this.slot.size); + } + + mountPoint() { + return ""; + } +} + +class DevicePresenter { + constructor(device, devicesManager) { + this.device = device; + this.devicesManager = devicesManager; + } + + name() { + return this.device.name; + } + + details() { + return this.device.description; + } + + size() { + return deviceSize(this.device.size); + } + + mountPoint() { + return this.device.filesystem?.mountPath || ""; + } +} + +const DeviceResult = ({ presenter }) => { + return ( + + ); +}; + +const DevicesResult = ({ settings, devices }) => { + const { system = [], staging = [] } = devices; + const devicesManager = new DevicesManager(system, staging); + + const usedDevices = () => { + const diskDevices = settings.installationDevices.map(d => devicesManager.device(d.sid)); + const lvmVgs = devicesManager.lvmVgsWithMountPoints(); + + return diskDevices.concat(lvmVgs); + }; + + const presenter = (storageElement) => { + if (devicesManager.isSlot(storageElement)) + return new SlotPresenter(storageElement); + else + return new DevicePresenter(storageElement, devicesManager); + }; + + return usedDevices().map(device => { + const devices = [device].concat(devicesManager.children(device)); + + return devices.map((d, i) => { + return ; + }); + }); +}; + /** * Section with the actions to perform in the system * @component @@ -113,9 +240,17 @@ const ActionsSkeleton = () => { * @param {string[]} [props.errors=[]] * @param {boolean} [props.isLoading=false] - Whether the section content should be rendered as loading */ -export default function ProposalActionsSection({ actions = [], errors = [], isLoading = false }) { +export default function ProposalActionsSection({ + actions, + settings, + devices, + errors = [], + isLoading = false +}) { if (isLoading) errors = []; + console.log("devices: ", devices); + return (
} - else={} + else={ + <> + + + + } />
); diff --git a/web/src/components/storage/ProposalPage.jsx b/web/src/components/storage/ProposalPage.jsx index ccb3bfdf4c..082bfaaadf 100644 --- a/web/src/components/storage/ProposalPage.jsx +++ b/web/src/components/storage/ProposalPage.jsx @@ -218,6 +218,8 @@ export default function ProposalPage() { }; const PageContent = () => { + const devices = { system: state.system, staging: state.staging }; + return ( <> diff --git a/web/src/components/storage/ProposalSpacePolicySection.jsx b/web/src/components/storage/ProposalSpacePolicySection.jsx index c08135c0e5..0f32a50187 100644 --- a/web/src/components/storage/ProposalSpacePolicySection.jsx +++ b/web/src/components/storage/ProposalSpacePolicySection.jsx @@ -70,7 +70,7 @@ const SPACE_POLICIES = [ // Names of the columns for the policy actions. const columnNames = { device: N_("Used device"), - content: N_("Current content"), + content: N_("Description"), size: N_("Size"), details: N_("Details"), action: N_("Action") @@ -84,15 +84,16 @@ const columnNames = { * @param {StorageDevice} props.device */ const DeviceDescriptionColumn = ({ device }) => { - return ( - <> -
{device.name}
- {`${device.vendor} ${device.model}`}} - /> - - ); + // return ( + // <> + //
{device.name}
+ // {`${device.vendor} ${device.model}`}} + // /> + // + // ); + return
{device.name}
; }; /** @@ -103,44 +104,47 @@ const DeviceDescriptionColumn = ({ device }) => { * @param {StorageDevice} props.device */ const DeviceContentColumn = ({ device }) => { - const PartitionTableContent = () => { - return ( -
- {/* TRANSLATORS: %s is replaced by partition table type (e.g., GPT) */} - {sprintf(_("%s partition table"), device.partitionTable.type.toUpperCase())} -
- ); - }; + // const PartitionTableContent = () => { + // return ( + //
+ // {/* TRANSLATORS: %s is replaced by partition table type (e.g., GPT) */} + // {sprintf(_("%s partition table"), device.partitionTable.type.toUpperCase())} + //
+ // ); + // }; const BlockContent = () => { const renderContent = () => { const systems = device.systems; if (systems.length > 0) return systems.join(", "); - const filesystem = device.filesystem; - if (filesystem?.isEFI) return _("EFI system partition"); - if (filesystem) { - // TRANSLATORS: %s is replaced by a file system type (e.g., btrfs). - return sprintf(_("%s file system"), filesystem?.type); - } - - const component = device.component; - switch (component?.type) { - case "physical_volume": - // TRANSLATORS: %s is replaced by a LVM volume group name (e.g., /dev/vg0). - return sprintf(_("LVM physical volume of %s"), component.deviceNames[0]); - case "md_device": - // TRANSLATORS: %s is replaced by a RAID name (e.g., /dev/md0). - return sprintf(_("Member of RAID %s"), component.deviceNames[0]); - default: - return _("Not identified"); - } + return device.description; + + // const filesystem = device.filesystem; + // if (filesystem?.isEFI) return _("EFI system partition"); + // if (filesystem) { + // // TRANSLATORS: %s is replaced by a file system type (e.g., btrfs). + // return sprintf(_("%s file system"), filesystem?.type); + // } + + // const component = device.component; + // switch (component?.type) { + // case "physical_volume": + // // TRANSLATORS: %s is replaced by a LVM volume group name (e.g., /dev/vg0). + // return sprintf(_("LVM physical volume of %s"), component.deviceNames[0]); + // case "md_device": + // // TRANSLATORS: %s is replaced by a RAID name (e.g., /dev/md0). + // return sprintf(_("Member of RAID %s"), component.deviceNames[0]); + // default: + // return _("Not identified"); + // } }; return
{renderContent()}
; }; - return (device.partitionTable ? : ); + // return (device.partitionTable ? : ); + return (device.partitionTable ? device.description : ); }; /**