-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: Move storage/SpacePolicyField to its own file
And adapts it to use a core/Field/SettingsField button.
- Loading branch information
Showing
3 changed files
with
110 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) [2024] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
// @ts-check | ||
|
||
import React, { useState } from "react"; | ||
import { Skeleton } from "@patternfly/react-core"; | ||
|
||
import { sprintf } from "sprintf-js"; | ||
import { _, n_ } from "~/i18n"; | ||
import { If, SettingsField } from "~/components/core"; | ||
import SpacePolicyDialog from "~/components/storage/SpacePolicyDialog"; | ||
|
||
/** | ||
* @typedef {import ("~/client/storage").SpaceAction} SpaceAction | ||
* @typedef {import ("~/components/storage/utils").SpacePolicy} SpacePolicy | ||
* @typedef {import ("~/client/storage").StorageDevice} StorageDevice | ||
* | ||
* @typedef {object} SpacePolicyConfig | ||
* @property {SpacePolicy} spacePolicy | ||
* @property {SpaceAction[]} spaceActions | ||
*/ | ||
|
||
/** | ||
* Allows to select the space policy. | ||
* @component | ||
* | ||
* @param {object} props | ||
* @param {SpacePolicy|undefined} props.policy | ||
* @param {SpaceAction[]} props.actions | ||
* @param {StorageDevice[]} props.devices | ||
* @param {boolean} props.isLoading | ||
* @param {(config: SpacePolicyConfig) => void} props.onChange | ||
* | ||
*/ | ||
export default function SpacePolicyField({ | ||
policy, | ||
actions, | ||
devices, | ||
isLoading, | ||
onChange | ||
}) { | ||
const [isDialogOpen, setIsDialogOpen] = useState(false); | ||
|
||
const openDialog = () => setIsDialogOpen(true); | ||
|
||
const closeDialog = () => setIsDialogOpen(false); | ||
|
||
const onAccept = ({ spacePolicy, spaceActions }) => { | ||
closeDialog(); | ||
onChange({ spacePolicy, spaceActions }); | ||
}; | ||
|
||
let value; | ||
if (isLoading || !policy) { | ||
value = <Skeleton screenreaderText={_("Waiting for information about space policy")} width="25%" />; | ||
} else if (policy.summaryLabels.length === 1) { | ||
// eslint-disable-next-line agama-i18n/string-literals | ||
value = _(policy.summaryLabels[0]); | ||
} else { | ||
// eslint-disable-next-line agama-i18n/string-literals | ||
value = sprintf(n_(policy.summaryLabels[0], policy.summaryLabels[1], devices.length), devices.length); | ||
} | ||
|
||
return ( | ||
<SettingsField | ||
label={_("Find space")} | ||
value={value} | ||
description={ _("Allocating the file systems might need to find free space \ | ||
in the installation device(s).")} | ||
onClick={openDialog} | ||
> | ||
<If | ||
condition={isDialogOpen} | ||
then={ | ||
<SpacePolicyDialog | ||
isOpen | ||
policy={policy} | ||
actions={actions} | ||
devices={devices} | ||
onAccept={onAccept} | ||
onCancel={closeDialog} | ||
/> | ||
} | ||
/> | ||
</SettingsField> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters