Skip to content

Commit

Permalink
first functionality for btrfs snapshots globally
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 16, 2024
1 parent 20f7719 commit d2fa735
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions web/src/components/storage/ProposalSettingsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Skeleton width="25%" />;
// no root volume is probably some error or still loading
if (rootVolume === undefined) {
return <Skeleton width="25%" />;
}

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 (
<div>
<Switch
id="snapshots"
Expand All @@ -490,8 +494,16 @@ const SnapshotsField = ({
{explanation}
</div>
</div>
</>
);
);
} else if (rootVolume.fsType === "Btrfs" && rootVolume.snapshots) {
return (
<div>
{_("Btrfs snapshots required by product.")}
</div>
);
} else { // strange situation, should not happen
return undefined;
}
};

/**
Expand Down Expand Up @@ -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;

Expand All @@ -762,9 +789,7 @@ export default function ProposalSettingsSection({
/>
<SnapshotsField
settings={settings}
isChecked={false} // TODO
isLoading={false} // TODO
onChange={noop} // TODO
onChange={changeBtrfsSnapshots}
/>
<EncryptionField
password={settings.encryptionPassword || ""}
Expand Down

0 comments on commit d2fa735

Please sign in to comment.