From d2fa7356cea7ff005ae80d7c1c01686e0a01a55d Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Fri, 16 Feb 2024 15:10:23 +0100 Subject: [PATCH] first functionality for btrfs snapshots globally --- .../storage/ProposalSettingsSection.jsx | 61 +++++++++++++------ 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/web/src/components/storage/ProposalSettingsSection.jsx b/web/src/components/storage/ProposalSettingsSection.jsx index 1a01aa41a9..f3c2d3fc69 100644 --- a/web/src/components/storage/ProposalSettingsSection.jsx +++ b/web/src/components/storage/ProposalSettingsSection.jsx @@ -453,31 +453,35 @@ const EncryptionSettingsForm = ({ * @component * * @param {object} props - * @param {boolean} [props.isChecked=false] - Whether system snapshots are selected - * @param {boolean} [props.isLoading=false] - Whether to show the selector as loading + * @param {ProposalSettings} props.settings - Settings used for calculating a proposal. * @param {onChangeFn} [props.onChange=noop] - On change callback * * @callback onChangeFn * @param {object} settings */ const SnapshotsField = ({ - isChecked: isCheckedProp = false, - isLoading = false, + settings, onChange = noop }) => { - const [isChecked, setIsChecked] = useState(isCheckedProp); + const rootVolume = (settings.volumes || []).find((i) => i.mountPath === "/"); - const switchState = (checked) => { - setIsChecked(checked); - onChange(checked); - }; + const initialChecked = rootVolume !== undefined && rootVolume.fsType === "Btrfs" && rootVolume.snapshots; + const [isChecked, setIsChecked] = useState(initialChecked); - if (isLoading) return ; + // no root volume is probably some error or still loading + if (rootVolume === undefined) { + return ; + } - const explanation = _("Allows to restore a previous version of the system after configuration changes or software upgrades."); + const switchState = (_, checked) => { + console.log(checked); + setIsChecked(checked); + onChange({ value: checked, settings }); + }; - return ( - <> + if (rootVolume.outline.snapshotsConfigurable) { + const explanation = _("Uses btrfs for the root file system allowing to boot to a previous version of the system after configuration changes or software upgrades."); + return (
- - ); + ); + } else if (rootVolume.fsType === "Btrfs" && rootVolume.snapshots) { + return ( +
+ {_("Btrfs snapshots required by product.")} +
+ ); + } else { // strange situation, should not happen + return undefined; + } }; /** @@ -742,6 +754,21 @@ export default function ProposalSettingsSection({ onChange({ volumes }); }; + const changeBtrfsSnapshots = ({ value, settings }) => { + console.log(settings); + const rootVolume = settings.volumes.find((i) => i.mountPath === "/"); + console.log(rootVolume); + console.log(value); + if (value) { + rootVolume.fsType = "Btrfs"; + rootVolume.snapshots = true; + } else { + rootVolume.snapshots = false; + } + console.log(settings); + changeVolumes(settings.volumes); + }; + const { bootDevice } = settings; const encryption = settings.encryptionPassword !== undefined && settings.encryptionPassword.length > 0; @@ -762,9 +789,7 @@ export default function ProposalSettingsSection({ />