import React, { useState } from 'react';
import {
Alert,
Button,
Popover,
Text,
TextContent,
TextInput,
TextVariants,
} from '@patternfly/react-core';
import { Select, SelectOption } from '@patternfly/react-core/deprecated';
import {
HelpIcon,
MinusCircleIcon,
PlusCircleIcon,
} from '@patternfly/react-icons';
import { ExternalLinkAltIcon } from '@patternfly/react-icons';
import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
import { v4 as uuidv4 } from 'uuid';
import { UNIT_GIB, UNIT_KIB, UNIT_MIB } from '../../../../constants';
import { useAppDispatch, useAppSelector } from '../../../../store/hooks';
import {
addPartition,
changePartitionMinSize,
changePartitionMountpoint,
selectImageTypes,
removePartition,
selectPartitions,
} from '../../../../store/wizardSlice';
import UsrSubDirectoriesDisabled from '../../UsrSubDirectoriesDisabled';
import { ValidatedTextInput } from '../../ValidatedTextInput';
export type Partition = {
id: string;
mountpoint: string;
min_size: string;
};
const FileSystemConfiguration = () => {
const partitions = useAppSelector((state) => selectPartitions(state));
const environments = useAppSelector((state) => selectImageTypes(state));
const dispatch = useAppDispatch();
const handleAddPartition = () => {
const id = uuidv4();
dispatch(
addPartition({
id,
mountpoint: '/home',
min_size: '1',
})
);
};
return (
<>
Configure partitions
{partitions?.find((partition) =>
partition?.mountpoint?.includes('/usr')
) && }
Create partitions for your image by defining mount points and minimum
sizes. Image builder creates partitions with a logical volume (LVM)
device type.
The order of partitions may change when the image is installed in
order to conform to best practices and ensure functionality.
}
iconPosition="right"
href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/creating_customized_images_by_using_insights_image_builder/customizing-file-systems-during-the-image-creation"
className="pf-u-pl-0"
>
Read more about manual configuration here
{environments.includes('image-installer') && (
)}
|
Mount point |
|
Type |
Minimum size
Image Builder may extend this size based on requirements,
selected packages, and configurations.
}
>
|
|
|
{partitions &&
partitions.map((partition) => (
))}
}
onClick={handleAddPartition}
>
Add partition
>
);
};
type RowPropTypes = {
partition: Partition;
};
const getPrefix = (mountpoint: string) => {
return mountpoint.split('/')[1] ? '/' + mountpoint.split('/')[1] : '/';
};
const getSuffix = (mountpoint: string) => {
const prefix = getPrefix(mountpoint);
return mountpoint.substring(prefix.length);
};
const Row = ({ partition }: RowPropTypes) => {
const [units, setUnits] = useState('MiB');
const dispatch = useAppDispatch();
const handleRemovePartition = (id: string) => {
dispatch(removePartition(id));
};
return (
|
|
{partition.mountpoint !== '/' &&
!partition.mountpoint.startsWith('/boot') &&
!partition.mountpoint.startsWith('/usr') ? (
|
) : (
|
)}
xfs |
|
|
}
onClick={() => handleRemovePartition(partition.id)}
data-testid="remove-mount-point"
isDisabled={partition.mountpoint === '/'}
/>
|
);
};
export const mountpointPrefixes = [
'/app',
'/boot',
'/data',
'/home',
'/opt',
'/srv',
'/tmp',
'/usr',
'/var',
];
type MountpointPrefixPropTypes = {
partition: Partition;
};
const MountpointPrefix = ({ partition }: MountpointPrefixPropTypes) => {
const dispatch = useAppDispatch();
const [isOpen, setIsOpen] = useState(false);
const prefix = getPrefix(partition.mountpoint);
const suffix = getSuffix(partition.mountpoint);
const onToggle = (isOpen: boolean) => {
setIsOpen(isOpen);
};
const onSelect = (event: React.MouseEvent, selection: string) => {
setIsOpen(false);
const mountpoint = selection + suffix;
dispatch(
changePartitionMountpoint({ id: partition.id, mountpoint: mountpoint })
);
};
return (
);
};
type MountpointSuffixPropTypes = {
partition: Partition;
};
const MountpointSuffix = ({ partition }: MountpointSuffixPropTypes) => {
const dispatch = useAppDispatch();
const prefix = getPrefix(partition.mountpoint);
const suffix = getSuffix(partition.mountpoint);
return (
{
const mountpoint = prefix + suffix;
dispatch(
changePartitionMountpoint({
id: partition.id,
mountpoint: mountpoint,
})
);
}}
aria-label="text input example"
/>
);
};
type MinimumSizePropTypes = {
partition: Partition;
units: Units;
};
type Units = 'KiB' | 'MiB' | 'GiB';
const getConversionFactor = (units: Units) => {
switch (units) {
case 'KiB':
return UNIT_KIB;
case 'MiB':
return UNIT_MIB;
case 'GiB':
return UNIT_GIB;
}
};
const MinimumSize = ({ partition, units }: MinimumSizePropTypes) => {
const conversionFactor = getConversionFactor(units);
const convertToDisplayUnits = (minSize: string) => {
return (parseInt(minSize) * conversionFactor).toString();
};
const convertToBytes = (minSize: string) => {
return (parseInt(minSize) / conversionFactor).toString();
};
const dispatch = useAppDispatch();
return (
true}
value={convertToDisplayUnits(partition.min_size)}
type="text"
onChange={(event, minSize) => {
dispatch(
changePartitionMinSize({
id: partition.id,
min_size: convertToBytes(minSize),
})
);
}}
/>
);
};
type SizeUnitPropTypes = {
units: Units;
setUnits: React.Dispatch>;
};
const SizeUnit = ({ units, setUnits }: SizeUnitPropTypes) => {
const [isOpen, setIsOpen] = useState(false);
const onToggle = (isOpen: boolean) => {
setIsOpen(isOpen);
};
const onSelect = (event: React.MouseEvent, selection: Units) => {
setUnits(selection);
setIsOpen(false);
};
return (
);
};
export default FileSystemConfiguration;