Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Mar 8, 2024
1 parent 6268678 commit 2bf6ad3
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 39 deletions.
144 changes: 142 additions & 2 deletions web/src/components/storage/ProposalActionsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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 (
<ul>
<li>{presenter.name()}</li>
<ul>
<li>{presenter.details()}</li>
<li>{presenter.size()}</li>
<li>{presenter.mountPoint()}</li>
</ul>
</ul>
);
};

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 <DeviceResult key={i} presenter={presenter(d)} />;
});
});
};

/**
* Section with the actions to perform in the system
* @component
Expand All @@ -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 (
<Section
// TRANSLATORS: The storage "Planned Actions" section's title. The
Expand All @@ -130,7 +265,12 @@ export default function ProposalActionsSection({ actions = [], errors = [], isLo
<If
condition={isLoading}
then={<ActionsSkeleton />}
else={<ProposalActions actions={actions} />}
else={
<>
<DevicesResult settings={settings} devices={devices} />
<ProposalActions actions={actions} />
</>
}
/>
</Section>
);
Expand Down
4 changes: 4 additions & 0 deletions web/src/components/storage/ProposalPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export default function ProposalPage() {
};

const PageContent = () => {
const devices = { system: state.system, staging: state.staging };

return (
<>
<ProposalDeviceSection
Expand Down Expand Up @@ -246,6 +248,8 @@ export default function ProposalPage() {
/>
<ProposalActionsSection
actions={state.actions}
settings={state.settings}
devices={devices}
errors={state.errors}
isLoading={state.loading}
/>
Expand Down
78 changes: 41 additions & 37 deletions web/src/components/storage/ProposalSpacePolicySection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -84,15 +84,16 @@ const columnNames = {
* @param {StorageDevice} props.device
*/
const DeviceDescriptionColumn = ({ device }) => {
return (
<>
<div>{device.name}</div>
<If
condition={device.isDrive}
then={<div className="fs-small">{`${device.vendor} ${device.model}`}</div>}
/>
</>
);
// return (
// <>
// <div>{device.name}</div>
// <If
// condition={device.isDrive}
// then={<div className="fs-small">{`${device.vendor} ${device.model}`}</div>}
// />
// </>
// );
return <div>{device.name}</div>;
};

/**
Expand All @@ -103,44 +104,47 @@ const DeviceDescriptionColumn = ({ device }) => {
* @param {StorageDevice} props.device
*/
const DeviceContentColumn = ({ device }) => {
const PartitionTableContent = () => {
return (
<div>
{/* TRANSLATORS: %s is replaced by partition table type (e.g., GPT) */}
{sprintf(_("%s partition table"), device.partitionTable.type.toUpperCase())}
</div>
);
};
// const PartitionTableContent = () => {
// return (
// <div>
// {/* TRANSLATORS: %s is replaced by partition table type (e.g., GPT) */}
// {sprintf(_("%s partition table"), device.partitionTable.type.toUpperCase())}
// </div>
// );
// };

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 <div>{renderContent()}</div>;
};

return (device.partitionTable ? <PartitionTableContent /> : <BlockContent />);
// return (device.partitionTable ? <PartitionTableContent /> : <BlockContent />);
return (device.partitionTable ? device.description : <BlockContent />);
};

/**
Expand Down

0 comments on commit 2bf6ad3

Please sign in to comment.