Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Feb 14, 2024
1 parent 253917c commit dc807a0
Showing 1 changed file with 3 additions and 108 deletions.
111 changes: 3 additions & 108 deletions web/src/components/storage/ProposalSpacePolicySection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
* find current contact information at www.suse.com.
*/

import React, { useEffect, useState } from "react";
import { Form, Radio, Skeleton } from "@patternfly/react-core";
import React, { useEffect } from "react";
import { Radio } from "@patternfly/react-core";

import { _, n_, N_ } from "~/i18n";
import { deviceSize } from '~/components/storage/utils';
import { If, Section, SectionSkeleton, Popup } from "~/components/core";
import { If, Section, SectionSkeleton } from "~/components/core";
import { noop, useLocalStorage } from "~/utils";
import { SpacePolicyButton, SpacePolicySelector as SpacePolicySelectorOld, SpacePolicyDisksHint } from "~/components/storage";
import { sprintf } from "sprintf-js";
import { Table, Thead, Tr, Th, Tbody, Td, TreeRowWrapper } from '@patternfly/react-table';

Expand Down Expand Up @@ -77,103 +76,6 @@ const columnNames = {
action: N_("Action")
};

/**
* Form for configuring the space policy.
* @component
*
* @param {object} props
* @param {string} props.id - Form ID.
* @param {ProposalSettings} props.settings - Settings used for calculating a proposal.
* @param {onSubmitFn} [props.onSubmit=noop] - On submit callback.
*
* @callback onSubmitFn
* @param {string} policy - Name of the selected policy.
*/
const SpacePolicyForm = ({
id,
policy,
onSubmit: onSubmitProp = noop
}) => {
const [spacePolicy, setSpacePolicy] = useState(policy);

const onSubmit = (e) => {
e.preventDefault();
onSubmitProp(spacePolicy);
};

return (
<Form id={id} onSubmit={onSubmit}>
<SpacePolicySelectorOld value={spacePolicy} onChange={setSpacePolicy} />
</Form>
);
};

/**
* Allows to select SpacePolicy.
* @component
*
* @param {object} props
* @param {ProposalSettings} props.settings - Settings used for calculating a proposal.
* @param {boolean} [props.isLoading=false] - Whether to show the selector as loading.
* @param {onChangeFn} [props.onChange=noop] - On change callback.
*
* @callback onChangeFn
* @param {string} policy
*/
const SpacePolicyField = ({
settings,
isLoading = false,
onChange = noop
}) => {
const [isFormOpen, setIsFormOpen] = useState(false);
const [spacePolicy, setSpacePolicy] = useState(settings.spacePolicy);

const openForm = () => setIsFormOpen(true);
const closeForm = () => setIsFormOpen(false);

const onSubmitForm = (policy) => {
onChange(policy);
setSpacePolicy(policy);
closeForm();
};

if (isLoading) return <Skeleton width="25%" />;

const description = _("Select how to make free space in the disks selected for allocating the \
file systems.");

return (
<div className="split">
{/* TRANSLATORS: To be completed with the rest of a sentence like "deleting all content" */}
<span>{_("Find space")}</span>
<SpacePolicyButton policy={spacePolicy} devices={settings.installationDevices} onClick={openForm} />
<Popup
description={description}
title={_("Space Policy")}
isOpen={isFormOpen}
>
<div className="stack">
<SpacePolicyDisksHint devices={settings.installationDevices} />
<SpacePolicyForm
id="spacePolicyForm"
policy={spacePolicy}
onSubmit={onSubmitForm}
/>
</div>
<Popup.Actions>
<Popup.Confirm
form="spacePolicyForm"
type="submit"
>
{_("Accept")}
</Popup.Confirm>
<Popup.Cancel onClick={closeForm} />
</Popup.Actions>
</Popup>
</div>
);
};

/**
* Indicates whether a device is a drive (disk, RAID).
* @function
Expand Down Expand Up @@ -531,14 +433,7 @@ export default function ProposalSpacePolicySection({
then={<SectionSkeleton numRows={4} />}
else={
<>
<SpacePolicyField
settings={settings}
isLoading={settings.spacePolicy === undefined}
onChange={changeSpacePolicy}
/>

<SpacePolicySelector currentPolicy={currentPolicy} onChange={changeSpacePolicy} />

<If
condition={settings.installationDevices?.length > 0}
then={<SpaceActionsTable settings={settings} onChange={changeSpaceActions} />}
Expand Down

0 comments on commit dc807a0

Please sign in to comment.