Compliance: refactor handlePartitions duplicate
This commit is contained in:
parent
9da490ad52
commit
96da1817df
3 changed files with 43 additions and 59 deletions
|
|
@ -7,7 +7,6 @@ import {
|
|||
Select,
|
||||
SelectOption,
|
||||
} from '@patternfly/react-core';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useSelectorHandlers } from './useSelectorHandlers';
|
||||
|
||||
|
|
@ -17,24 +16,19 @@ import {
|
|||
} from '../../../../../store/complianceApi';
|
||||
import { useAppDispatch, useAppSelector } from '../../../../../store/hooks';
|
||||
import {
|
||||
Filesystem,
|
||||
useGetOscapCustomizationsForPolicyQuery,
|
||||
useLazyGetOscapCustomizationsForPolicyQuery,
|
||||
} from '../../../../../store/imageBuilderApi';
|
||||
import {
|
||||
addKernelArg,
|
||||
addPartition,
|
||||
changeCompliance,
|
||||
changeFileSystemConfigurationType,
|
||||
clearKernelAppend,
|
||||
clearPartitions,
|
||||
selectCompliancePolicyID,
|
||||
selectCompliancePolicyTitle,
|
||||
selectDistribution,
|
||||
} from '../../../../../store/wizardSlice';
|
||||
import { useHasSpecificTargetOnly } from '../../../utilities/hasSpecificTargetOnly';
|
||||
import { parseSizeUnit } from '../../../utilities/parseSizeUnit';
|
||||
import { Partition, Units } from '../../FileSystem/components/FileSystemTable';
|
||||
import { removeBetaFromRelease } from '../removeBetaFromRelease';
|
||||
|
||||
type ComplianceSelectOptionPropType = {
|
||||
|
|
@ -87,8 +81,12 @@ const PolicySelector = () => {
|
|||
const hasWslTargetOnly = useHasSpecificTargetOnly('wsl');
|
||||
const dispatch = useAppDispatch();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const { clearCompliancePackages, handlePackages, handleServices } =
|
||||
useSelectorHandlers();
|
||||
const {
|
||||
clearCompliancePackages,
|
||||
handlePackages,
|
||||
handlePartitions,
|
||||
handleServices,
|
||||
} = useSelectorHandlers();
|
||||
|
||||
const {
|
||||
data: policies,
|
||||
|
|
@ -147,28 +145,6 @@ const PolicySelector = () => {
|
|||
dispatch(clearKernelAppend());
|
||||
};
|
||||
|
||||
const handlePartitions = (oscapPartitions: Filesystem[]) => {
|
||||
dispatch(clearPartitions());
|
||||
|
||||
const newPartitions = oscapPartitions.map((filesystem) => {
|
||||
const [size, unit] = parseSizeUnit(filesystem.min_size);
|
||||
const partition: Partition = {
|
||||
mountpoint: filesystem.mountpoint,
|
||||
min_size: size.toString(),
|
||||
unit: unit as Units,
|
||||
id: uuidv4(),
|
||||
};
|
||||
return partition;
|
||||
});
|
||||
|
||||
if (newPartitions.length > 0) {
|
||||
dispatch(changeFileSystemConfigurationType('manual'));
|
||||
for (const partition of newPartitions) {
|
||||
dispatch(addPartition(partition));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleKernelAppend = (kernelAppend: string | undefined) => {
|
||||
dispatch(clearKernelAppend());
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import {
|
|||
TextInputGroupUtilities,
|
||||
} from '@patternfly/react-core';
|
||||
import { TimesIcon } from '@patternfly/react-icons';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useSelectorHandlers } from './useSelectorHandlers';
|
||||
|
||||
|
|
@ -28,17 +27,14 @@ import {
|
|||
import { useAppDispatch, useAppSelector } from '../../../../../store/hooks';
|
||||
import {
|
||||
DistributionProfileItem,
|
||||
Filesystem,
|
||||
OpenScap,
|
||||
OpenScapProfile,
|
||||
} from '../../../../../store/imageBuilderApi';
|
||||
import {
|
||||
addKernelArg,
|
||||
addPartition,
|
||||
changeCompliance,
|
||||
changeFileSystemConfigurationType,
|
||||
clearKernelAppend,
|
||||
clearPartitions,
|
||||
selectComplianceProfileID,
|
||||
selectComplianceType,
|
||||
selectDistribution,
|
||||
|
|
@ -77,8 +73,12 @@ const ProfileSelector = () => {
|
|||
>([]);
|
||||
const complianceType = useAppSelector(selectComplianceType);
|
||||
const prefetchProfile = useBackendPrefetch('getOscapCustomizations');
|
||||
const { clearCompliancePackages, handlePackages, handleServices } =
|
||||
useSelectorHandlers();
|
||||
const {
|
||||
clearCompliancePackages,
|
||||
handlePackages,
|
||||
handlePartitions,
|
||||
handleServices,
|
||||
} = useSelectorHandlers();
|
||||
|
||||
const {
|
||||
data: profiles,
|
||||
|
|
@ -187,28 +187,6 @@ const ProfileSelector = () => {
|
|||
setFilterValue('');
|
||||
};
|
||||
|
||||
const handlePartitions = (oscapPartitions: Filesystem[]) => {
|
||||
dispatch(clearPartitions());
|
||||
|
||||
const newPartitions = oscapPartitions.map((filesystem) => {
|
||||
const [size, unit] = parseSizeUnit(filesystem.min_size);
|
||||
const partition: Partition = {
|
||||
mountpoint: filesystem.mountpoint,
|
||||
min_size: size.toString(),
|
||||
unit: unit as Units,
|
||||
id: uuidv4(),
|
||||
};
|
||||
return partition;
|
||||
});
|
||||
|
||||
if (newPartitions.length > 0) {
|
||||
dispatch(changeFileSystemConfigurationType('manual'));
|
||||
for (const partition of newPartitions) {
|
||||
dispatch(addPartition(partition));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleKernelAppend = (kernelAppend: string | undefined) => {
|
||||
dispatch(clearKernelAppend());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useAppDispatch } from '../../../../../store/hooks';
|
||||
import { Services } from '../../../../../store/imageBuilderApi';
|
||||
import { Filesystem, Services } from '../../../../../store/imageBuilderApi';
|
||||
import {
|
||||
addPackage,
|
||||
addPartition,
|
||||
changeDisabledServices,
|
||||
changeEnabledServices,
|
||||
changeFileSystemConfigurationType,
|
||||
changeMaskedServices,
|
||||
clearPartitions,
|
||||
removePackage,
|
||||
} from '../../../../../store/wizardSlice';
|
||||
import { parseSizeUnit } from '../../../utilities/parseSizeUnit';
|
||||
import { Partition, Units } from '../../FileSystem/components/FileSystemTable';
|
||||
|
||||
export const useSelectorHandlers = () => {
|
||||
const dispatch = useAppDispatch();
|
||||
|
|
@ -35,6 +42,28 @@ export const useSelectorHandlers = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const handlePartitions = (oscapPartitions: Filesystem[]) => {
|
||||
dispatch(clearPartitions());
|
||||
|
||||
const newPartitions = oscapPartitions.map((filesystem) => {
|
||||
const [size, unit] = parseSizeUnit(filesystem.min_size);
|
||||
const partition: Partition = {
|
||||
mountpoint: filesystem.mountpoint,
|
||||
min_size: size.toString(),
|
||||
unit: unit as Units,
|
||||
id: uuidv4(),
|
||||
};
|
||||
return partition;
|
||||
});
|
||||
|
||||
if (newPartitions.length > 0) {
|
||||
dispatch(changeFileSystemConfigurationType('manual'));
|
||||
for (const partition of newPartitions) {
|
||||
dispatch(addPartition(partition));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleServices = (services: Services | undefined) => {
|
||||
dispatch(changeEnabledServices(services?.enabled || []));
|
||||
dispatch(changeMaskedServices(services?.masked || []));
|
||||
|
|
@ -45,5 +74,6 @@ export const useSelectorHandlers = () => {
|
|||
clearCompliancePackages,
|
||||
handlePackages,
|
||||
handleServices,
|
||||
handlePartitions,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue