* Copyright (C) 2025 Red Hat, Inc.
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
import cockpit from "cockpit";
import React from "react";
import { Card, CardBody } from "@patternfly/react-core/dist/esm/components/Card/index.js";
import { Content } from "@patternfly/react-core/dist/esm/components/Content/index.js";
import { List, ListItem } from "@patternfly/react-core/dist/esm/components/List/index.js";
import { PageSection } from "@patternfly/react-core/dist/esm/components/Page/index.js";
import { Title } from "@patternfly/react-core/dist/esm/components/Title/index.js";
import { Flex, FlexItem } from "@patternfly/react-core/dist/esm/layouts/Flex/index.js";
import {
useMountPointConstraints,
useRequiredSize,
} from "../../../hooks/Storage.jsx";
const _ = cockpit.gettext;
const idPrefix = "cockpit-storage-integration";
export const ModifyStorageSideBar = () => {
const mountPointConstraints = useMountPointConstraints();
const requiredSize = useRequiredSize();
if (mountPointConstraints === undefined) {
return null;
}
const requiredConstraints = (
mountPointConstraints.filter(constraint => constraint.required.v)
);
const recommendedConstraints = (
mountPointConstraints.filter(constraint => !constraint.required.v && constraint.recommended.v)
);
const getConstraints = constraints => (
<List className={idPrefix + "-requirements-hint-list"}>
{constraints.map(constraint => {
const item = [
constraint["mount-point"].v,
constraint["required-filesystem-type"].v
]
.filter(c => !!c)
.join(" ");
return <ListItem key={item}>{item}</ListItem>;
})}
</List>
);
const requiredConstraintsSection = (
requiredConstraints.length > 0 &&
<>
<Content component="p" className={idPrefix + "-requirements-hint"}>
{_("If you are configuring partitions the following are required:")}
</Content>
{getConstraints(requiredConstraints)}
</>
);
const recommendedConstraintsSection = (
recommendedConstraints.length > 0 &&
<>
<Content component="p" className={idPrefix + "-requirements-hint"}>
{_("Recommended partitions:")}
</Content>
{getConstraints(recommendedConstraints)}
</>
);
return (
<PageSection hasBodyWrapper={false} className={idPrefix + "-sidebar"}>
<Card>
<CardBody>
<Flex direction={{ default: "column" }} spaceItems={{ default: "spaceItemsLg" }}>
<FlexItem>
<Title headingLevel="h3" size="lg">{_("Requirements")}</Title>
<Content>
<Content component="p" className={idPrefix + "-requirements-hint"}>
{cockpit.format(_("Fedora linux requires at least $0 of disk space."), cockpit.format_bytes(requiredSize))}
</Content>
<Content component="p" className={idPrefix + "-requirements-hint-detail"}>
{_("You can either free up enough space here and let the installer handle the rest or manually set up partitions.")}
</Content>
</Content>
</FlexItem>
<FlexItem>
<Title headingLevel="h3" size="lg">{_("Partitions (advanced)")}</Title>
<Content>
{requiredConstraintsSection}
{recommendedConstraintsSection}
</Content>
</FlexItem>
</Flex>
</CardBody>
</Card>
</PageSection>
);
};